-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Move @roo-code/cloud to the Roo-Code repo #7503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { config } from "@roo-code/config-eslint/base" | ||
| import globals from "globals" | ||
|
|
||
| /** @type {import("eslint").Linter.Config} */ | ||
| export default [ | ||
| ...config, | ||
| { | ||
| files: ["**/*.cjs"], | ||
| languageOptions: { | ||
| globals: { | ||
| ...globals.node, | ||
| ...globals.commonjs, | ||
| }, | ||
| sourceType: "commonjs", | ||
| }, | ||
| rules: { | ||
| "@typescript-eslint/no-require-imports": "off", | ||
| }, | ||
| }, | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "@roo-code/cloud", | ||
| "description": "Roo Code Cloud services.", | ||
| "version": "0.0.0", | ||
cte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "type": "module", | ||
| "exports": "./src/index.ts", | ||
| "scripts": { | ||
| "lint": "eslint src --ext=ts --max-warnings=0", | ||
| "check-types": "tsc --noEmit", | ||
| "test": "vitest run", | ||
| "clean": "rimraf .turbo" | ||
| }, | ||
| "dependencies": { | ||
| "@roo-code/types": "workspace:^", | ||
| "ioredis": "^5.6.1", | ||
| "jwt-decode": "^4.0.0", | ||
| "p-wait-for": "^5.0.2", | ||
| "socket.io-client": "^4.8.1", | ||
| "zod": "^3.25.76" | ||
| }, | ||
| "devDependencies": { | ||
| "@roo-code/config-eslint": "workspace:^", | ||
| "@roo-code/config-typescript": "workspace:^", | ||
| "@types/node": "^24.1.0", | ||
| "@types/vscode": "^1.102.0", | ||
| "globals": "^16.3.0", | ||
| "vitest": "^3.2.4" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import { z } from "zod" | ||
|
|
||
| import { type AuthService, type ShareVisibility, type ShareResponse, shareResponseSchema } from "@roo-code/types" | ||
|
|
||
| import { getRooCodeApiUrl } from "./config.js" | ||
| import { getUserAgent } from "./utils.js" | ||
| import { AuthenticationError, CloudAPIError, NetworkError, TaskNotFoundError } from "./errors.js" | ||
|
|
||
| interface CloudAPIRequestOptions extends Omit<RequestInit, "headers"> { | ||
| timeout?: number | ||
| headers?: Record<string, string> | ||
| } | ||
|
|
||
| export class CloudAPI { | ||
cte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private authService: AuthService | ||
| private log: (...args: unknown[]) => void | ||
| private baseUrl: string | ||
|
|
||
| constructor(authService: AuthService, log?: (...args: unknown[]) => void) { | ||
| this.authService = authService | ||
| this.log = log || console.log | ||
| this.baseUrl = getRooCodeApiUrl() | ||
| } | ||
|
|
||
| private async request<T>( | ||
| endpoint: string, | ||
| options: CloudAPIRequestOptions & { | ||
| parseResponse?: (data: unknown) => T | ||
| } = {}, | ||
| ): Promise<T> { | ||
| const { timeout = 30_000, parseResponse, headers = {}, ...fetchOptions } = options | ||
|
|
||
| const sessionToken = this.authService.getSessionToken() | ||
|
|
||
| if (!sessionToken) { | ||
| throw new AuthenticationError() | ||
| } | ||
|
|
||
| const url = `${this.baseUrl}${endpoint}` | ||
|
|
||
| const requestHeaders = { | ||
| "Content-Type": "application/json", | ||
| Authorization: `Bearer ${sessionToken}`, | ||
| "User-Agent": getUserAgent(), | ||
| ...headers, | ||
| } | ||
|
|
||
| try { | ||
| const response = await fetch(url, { | ||
| ...fetchOptions, | ||
| headers: requestHeaders, | ||
| signal: AbortSignal.timeout(timeout), | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| await this.handleErrorResponse(response, endpoint) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| if (parseResponse) { | ||
| return parseResponse(data) | ||
| } | ||
|
|
||
| return data as T | ||
| } catch (error) { | ||
| if (error instanceof TypeError && error.message.includes("fetch")) { | ||
| throw new NetworkError(`Network error while calling ${endpoint}`) | ||
| } | ||
|
|
||
| if (error instanceof CloudAPIError) { | ||
| throw error | ||
| } | ||
|
|
||
| if (error instanceof Error && error.name === "AbortError") { | ||
| throw new CloudAPIError(`Request to ${endpoint} timed out`, undefined, undefined) | ||
| } | ||
|
|
||
| throw new CloudAPIError( | ||
| `Unexpected error while calling ${endpoint}: ${error instanceof Error ? error.message : String(error)}`, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private async handleErrorResponse(response: Response, endpoint: string): Promise<never> { | ||
| let responseBody: unknown | ||
|
|
||
| try { | ||
| responseBody = await response.json() | ||
| } catch { | ||
| responseBody = await response.text() | ||
| } | ||
|
|
||
| switch (response.status) { | ||
| case 401: | ||
| throw new AuthenticationError() | ||
| case 404: | ||
| if (endpoint.includes("/share")) { | ||
| throw new TaskNotFoundError() | ||
| } | ||
| throw new CloudAPIError(`Resource not found: ${endpoint}`, 404, responseBody) | ||
| default: | ||
| throw new CloudAPIError( | ||
| `HTTP ${response.status}: ${response.statusText}`, | ||
| response.status, | ||
| responseBody, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| async shareTask(taskId: string, visibility: ShareVisibility = "organization"): Promise<ShareResponse> { | ||
| this.log(`[CloudAPI] Sharing task ${taskId} with visibility: ${visibility}`) | ||
|
|
||
| const response = await this.request("/api/extension/share", { | ||
| method: "POST", | ||
| body: JSON.stringify({ taskId, visibility }), | ||
| parseResponse: (data) => shareResponseSchema.parse(data), | ||
| }) | ||
|
|
||
| this.log("[CloudAPI] Share response:", response) | ||
| return response | ||
| } | ||
|
|
||
| async bridgeConfig() { | ||
| return this.request("/api/extension/bridge/config", { | ||
| method: "GET", | ||
| parseResponse: (data) => | ||
| z | ||
| .object({ | ||
| userId: z.string(), | ||
| socketBridgeUrl: z.string(), | ||
| token: z.string(), | ||
| }) | ||
| .parse(data), | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.