Skip to content

Commit 142cdb5

Browse files
authored
Revert "Use @roo-code/cloud from npm" (#6742)
Revert "Use @roo-code/cloud from npm (#6611)" This reverts commit a1439c1.
1 parent 7a865e2 commit 142cdb5

34 files changed

+5874
-149
lines changed

packages/cloud/eslint.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { config } from "@roo-code/config-eslint/base"
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default [...config]

packages/cloud/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@roo-code/cloud",
3+
"description": "Roo Code Cloud VSCode integration.",
4+
"version": "0.0.0",
5+
"type": "module",
6+
"exports": "./src/index.ts",
7+
"scripts": {
8+
"lint": "eslint src --ext=ts --max-warnings=0",
9+
"check-types": "tsc --noEmit",
10+
"test": "vitest run",
11+
"clean": "rimraf dist .turbo"
12+
},
13+
"dependencies": {
14+
"@roo-code/telemetry": "workspace:^",
15+
"@roo-code/types": "workspace:^",
16+
"zod": "^3.25.61"
17+
},
18+
"devDependencies": {
19+
"@roo-code/config-eslint": "workspace:^",
20+
"@roo-code/config-typescript": "workspace:^",
21+
"@types/node": "20.x",
22+
"@types/vscode": "^1.84.0",
23+
"vitest": "^3.2.3"
24+
}
25+
}

packages/cloud/src/CloudAPI.ts

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { type ShareVisibility, type ShareResponse, shareResponseSchema } from "@roo-code/types"
2+
3+
import { getRooCodeApiUrl } from "./config"
4+
import type { AuthService } from "./auth"
5+
import { getUserAgent } from "./utils"
6+
import { AuthenticationError, CloudAPIError, NetworkError, TaskNotFoundError } from "./errors"
7+
8+
interface CloudAPIRequestOptions extends Omit<RequestInit, "headers"> {
9+
timeout?: number
10+
headers?: Record<string, string>
11+
}
12+
13+
export class CloudAPI {
14+
private authService: AuthService
15+
private log: (...args: unknown[]) => void
16+
private baseUrl: string
17+
18+
constructor(authService: AuthService, log?: (...args: unknown[]) => void) {
19+
this.authService = authService
20+
this.log = log || console.log
21+
this.baseUrl = getRooCodeApiUrl()
22+
}
23+
24+
private async request<T>(
25+
endpoint: string,
26+
options: CloudAPIRequestOptions & {
27+
parseResponse?: (data: unknown) => T
28+
} = {},
29+
): Promise<T> {
30+
const { timeout = 10000, parseResponse, headers = {}, ...fetchOptions } = options
31+
32+
const sessionToken = this.authService.getSessionToken()
33+
34+
if (!sessionToken) {
35+
throw new AuthenticationError()
36+
}
37+
38+
const url = `${this.baseUrl}${endpoint}`
39+
40+
const requestHeaders = {
41+
"Content-Type": "application/json",
42+
Authorization: `Bearer ${sessionToken}`,
43+
"User-Agent": getUserAgent(),
44+
...headers,
45+
}
46+
47+
try {
48+
const response = await fetch(url, {
49+
...fetchOptions,
50+
headers: requestHeaders,
51+
signal: AbortSignal.timeout(timeout),
52+
})
53+
54+
if (!response.ok) {
55+
await this.handleErrorResponse(response, endpoint)
56+
}
57+
58+
const data = await response.json()
59+
60+
if (parseResponse) {
61+
return parseResponse(data)
62+
}
63+
64+
return data as T
65+
} catch (error) {
66+
if (error instanceof TypeError && error.message.includes("fetch")) {
67+
throw new NetworkError(`Network error while calling ${endpoint}`)
68+
}
69+
70+
if (error instanceof CloudAPIError) {
71+
throw error
72+
}
73+
74+
if (error instanceof Error && error.name === "AbortError") {
75+
throw new CloudAPIError(`Request to ${endpoint} timed out`, undefined, undefined)
76+
}
77+
78+
throw new CloudAPIError(
79+
`Unexpected error while calling ${endpoint}: ${error instanceof Error ? error.message : String(error)}`,
80+
)
81+
}
82+
}
83+
84+
private async handleErrorResponse(response: Response, endpoint: string): Promise<never> {
85+
let responseBody: unknown
86+
87+
try {
88+
responseBody = await response.json()
89+
} catch {
90+
responseBody = await response.text()
91+
}
92+
93+
switch (response.status) {
94+
case 401:
95+
throw new AuthenticationError()
96+
case 404:
97+
if (endpoint.includes("/share")) {
98+
throw new TaskNotFoundError()
99+
}
100+
throw new CloudAPIError(`Resource not found: ${endpoint}`, 404, responseBody)
101+
default:
102+
throw new CloudAPIError(
103+
`HTTP ${response.status}: ${response.statusText}`,
104+
response.status,
105+
responseBody,
106+
)
107+
}
108+
}
109+
110+
async shareTask(taskId: string, visibility: ShareVisibility = "organization"): Promise<ShareResponse> {
111+
this.log(`[CloudAPI] Sharing task ${taskId} with visibility: ${visibility}`)
112+
113+
const response = await this.request("/api/extension/share", {
114+
method: "POST",
115+
body: JSON.stringify({ taskId, visibility }),
116+
parseResponse: (data) => shareResponseSchema.parse(data),
117+
})
118+
119+
this.log("[CloudAPI] Share response:", response)
120+
return response
121+
}
122+
}

0 commit comments

Comments
 (0)