Skip to content

Commit

Permalink
feat(vscode): show status of rate limited
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Dec 30, 2024
1 parent 652afaf commit 3261760
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions clients/tabby-agent/src/http/tabbyApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isUnauthorizedError,
isCanceledError,
isTimeoutError,
isRateLimitedError,
} from "../utils/error";
import { RequestStats } from "./statistics";

Expand All @@ -48,6 +49,7 @@ export class TabbyApiClient extends EventEmitter {

private readonly completionRequestStats = new RequestStats();
private completionResponseIssue: "highTimeoutRate" | "slowResponseTime" | undefined = undefined;
private rateLimited = false;

private connectionErrorMessage: string | undefined = undefined;
private serverHealth: TabbyApiComponents["schemas"]["HealthState"] | undefined = undefined;
Expand Down Expand Up @@ -214,6 +216,10 @@ export class TabbyApiClient extends EventEmitter {
return !!this.completionResponseIssue;
}

isRateLimited(): boolean {
return this.rateLimited;
}

getServerHealth(): TabbyApiComponents["schemas"]["HealthState"] | undefined {
return this.serverHealth;
}
Expand Down Expand Up @@ -334,6 +340,7 @@ export class TabbyApiClient extends EventEmitter {
}
}

// todo
async fetchCompletion(
request: TabbyApiComponents["schemas"]["CompletionRequest"],
signal?: AbortSignal,
Expand All @@ -353,6 +360,7 @@ export class TabbyApiClient extends EventEmitter {
canceled: false,
timeout: false,
notAvailable: false,
rateLimited: false
};

try {
Expand Down Expand Up @@ -383,6 +391,9 @@ export class TabbyApiClient extends EventEmitter {
this.logger.debug(`Completion request failed due to unauthorized. [${requestId}]`);
statsData.notAvailable = true;
this.connect(); // schedule a reconnection
} else if (isRateLimitedError(error)) {
this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`);
statsData.rateLimited = true
} else {
this.logger.error(`Completion request failed. [${requestId}]`, error);
statsData.notAvailable = true;
Expand Down
3 changes: 2 additions & 1 deletion clients/tabby-agent/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ export type StatusInfo = {
| "readyForAutoTrigger"
| "readyForManualTrigger"
| "fetching"
| "completionResponseSlow";
| "completionResponseSlow"
| "rateLimited";
tooltip?: string;
/**
* The health information of the server if available.
Expand Down
5 changes: 5 additions & 0 deletions clients/tabby-agent/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export class StatusProvider extends EventEmitter implements Feature {
const ignored = this.dataStore.data.statusIgnoredIssues ?? [];
if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) {
statusInfo = { status: "completionResponseSlow" };
} else if (this.tabbyApiClient.isRateLimited()) {
statusInfo = { status: "rateLimited" }
} else if (this.tabbyApiClient.isFetchingCompletion()) {
statusInfo = { status: "fetching" };
} else {
Expand Down Expand Up @@ -264,6 +266,9 @@ export class StatusProvider extends EventEmitter implements Feature {
case "completionResponseSlow":
statusInfo.tooltip = "Tabby: Slow Completion Response Detected";
break;
case "rateLimited":
statusInfo.tooltip = "Tabby: Too many request";
break;
default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions clients/tabby-agent/src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export function isUnauthorizedError(error: any) {
return error instanceof HttpError && [401, 403].includes(error.status);
}

export function isRateLimitedError(error: any) {
return error instanceof HttpError && [429].includes(error.status);
}

export function errorToString(error: Error) {
let message = error.message || error.toString();
if (error.cause instanceof Error) {
Expand Down
3 changes: 2 additions & 1 deletion clients/vscode/src/StatusBarItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export class StatusBarItem {
this.setTooltip(statusInfo.tooltip);
break;
}
case "completionResponseSlow": {
case "completionResponseSlow":
case "rateLimited": {
this.setColorWarning();
this.setIcon(iconWarning);
this.setTooltip(statusInfo.tooltip);
Expand Down

0 comments on commit 3261760

Please sign in to comment.