-
Couldn't load subscription status.
- Fork 2.3k
feat: Experiment: Show a bit of stats in Cloud tab to help users discover there's more in Cloud #8415
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
feat: Experiment: Show a bit of stats in Cloud tab to help users discover there's more in Cloud #8415
Changes from 9 commits
7b43022
af0a90e
2c31616
d84e031
eda8cae
c33cc29
70a2478
d1e7192
f70062d
7ab010a
b66c5ec
e46eb8a
22113cd
1e287f9
bca20e5
3ec844a
3f85776
82e093b
09b2fa2
ac7d139
a989db7
0d1cd24
6f37b02
61a133d
c13bf8b
0393a40
5b83dd1
ab77ff2
35154ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,25 @@ import { getRooCodeApiUrl } from "./config.js" | |
| import { getUserAgent } from "./utils.js" | ||
| import { AuthenticationError, CloudAPIError, NetworkError, TaskNotFoundError } from "./errors.js" | ||
|
|
||
| // Usage stats schemas | ||
| const usageStatsSchema = z.object({ | ||
|
||
| success: z.boolean(), | ||
| data: z.object({ | ||
| dates: z.array(z.string()), // Array of date strings | ||
| tasks: z.array(z.number()), // Array of task counts | ||
| tokens: z.array(z.number()), // Array of token counts | ||
| costs: z.array(z.number()), // Array of costs in USD | ||
| totals: z.object({ | ||
| tasks: z.number(), | ||
| tokens: z.number(), | ||
| cost: z.number(), // Total cost in USD | ||
| }), | ||
| }), | ||
| period: z.number(), // Period in days (e.g., 30) | ||
| }) | ||
|
|
||
| export type UsageStats = z.infer<typeof usageStatsSchema> | ||
|
|
||
| interface CloudAPIRequestOptions extends Omit<RequestInit, "headers"> { | ||
| timeout?: number | ||
| headers?: Record<string, string> | ||
|
|
@@ -53,9 +72,11 @@ export class CloudAPI { | |
| }) | ||
|
|
||
| if (!response.ok) { | ||
| this.log(`[CloudAPI] Request to ${endpoint} failed with status ${response.status}`) | ||
| await this.handleErrorResponse(response, endpoint) | ||
| } | ||
|
|
||
| // Log before attempting to read the body | ||
| const data = await response.json() | ||
brunobergher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (parseResponse) { | ||
|
|
@@ -86,9 +107,15 @@ export class CloudAPI { | |
| let responseBody: unknown | ||
|
|
||
| try { | ||
| responseBody = await response.json() | ||
| } catch { | ||
| responseBody = await response.text() | ||
| const bodyText = await response.text() | ||
|
|
||
| try { | ||
| responseBody = JSON.parse(bodyText) | ||
| } catch { | ||
| responseBody = bodyText | ||
| } | ||
| } catch (_error) { | ||
| responseBody = "Failed to read error response" | ||
| } | ||
|
|
||
| switch (response.status) { | ||
|
|
@@ -109,15 +136,12 @@ export class CloudAPI { | |
| } | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
|
|
@@ -134,4 +158,14 @@ export class CloudAPI { | |
| .parse(data), | ||
| }) | ||
| } | ||
|
|
||
| async getUsagePreview(): Promise<UsageStats> { | ||
| const response = await this.request("/api/analytics/usage/daily?period=7", { | ||
| method: "GET", | ||
| parseResponse: (data) => { | ||
| return usageStatsSchema.parse(data) | ||
| }, | ||
| }) | ||
| return response | ||
| } | ||
| } | ||
brunobergher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
brunobergher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.