Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Dec 31, 2024
1 parent 7066080 commit f77d2ce
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
24 changes: 12 additions & 12 deletions clients/tabby-agent/src/http/tabbyApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class TabbyApiClient extends EventEmitter {

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

private connectionErrorMessage: string | undefined = undefined;
private serverHealth: TabbyApiComponents["schemas"]["HealthState"] | undefined = undefined;
Expand Down Expand Up @@ -178,11 +178,11 @@ export class TabbyApiClient extends EventEmitter {
}
}

private updateIsRateLimited(isRateLimited: boolean) {
if (this.rateLimited != isRateLimited) {
this.logger.debug(`updateIsRateLimited: ${isRateLimited}`);
this.rateLimited = isRateLimited;
this.emit("isRateLimitedUpdated", isRateLimited);
private updateIsRateLimitExceeded(isRateLimitExceeded: boolean) {
if (this.rateLimitExceeded != isRateLimitExceeded) {
this.logger.debug(`updateIsRateLimitExceeded: ${isRateLimitExceeded}`);
this.rateLimitExceeded = isRateLimitExceeded;
this.emit("isRateLimitExceededUpdated", isRateLimitExceeded);
}
}

Expand Down Expand Up @@ -224,8 +224,8 @@ export class TabbyApiClient extends EventEmitter {
return !!this.completionResponseIssue;
}

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

getServerHealth(): TabbyApiComponents["schemas"]["HealthState"] | undefined {
Expand Down Expand Up @@ -384,7 +384,7 @@ export class TabbyApiClient extends EventEmitter {
}
this.logger.trace(`Completion response data: [${requestId}]`, response.data);
statsData.latency = performance.now() - requestStartedAt;
this.updateIsRateLimited(false);
this.updateIsRateLimitExceeded(false);
return response.data;
} catch (error) {
this.updateIsFetchingCompletion(false);
Expand All @@ -397,16 +397,16 @@ export class TabbyApiClient extends EventEmitter {
} else if (isUnauthorizedError(error)) {
this.logger.debug(`Completion request failed due to unauthorized. [${requestId}]`);
statsData.notAvailable = true;
this.updateIsRateLimited(false);
this.updateIsRateLimitExceeded(false);
this.connect(); // schedule a reconnection
} else if (isRateLimitedError(error)) {
this.logger.debug(`Completion request failed due to rate limiting. [${requestId}]`);
statsData.notAvailable = true;
this.updateIsRateLimited(true);
this.updateIsRateLimitExceeded(true);
} else {
this.logger.error(`Completion request failed. [${requestId}]`, error);
statsData.notAvailable = true;
this.updateIsRateLimited(false);
this.updateIsRateLimitExceeded(false);
this.connect(); // schedule a reconnection
}
throw error; // rethrow error
Expand Down
13 changes: 5 additions & 8 deletions clients/tabby-agent/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class StatusProvider extends EventEmitter implements Feature {
this.tabbyApiClient.on("hasCompletionResponseTimeIssueUpdated", async () => {
this.notify();
});
this.tabbyApiClient.on("isRateLimitedUpdated", async () => {
this.tabbyApiClient.on("isRateLimitExceededUpdated", async () => {
this.notify();
});

Expand Down Expand Up @@ -206,12 +206,9 @@ export class StatusProvider extends EventEmitter implements Feature {
case "ready":
{
const ignored = this.dataStore.data.statusIgnoredIssues ?? [];
if (this.tabbyApiClient.isRateLimited()) {
statusInfo = { status: "rateLimited" };
} else if (
this.tabbyApiClient.hasCompletionResponseTimeIssue() &&
!ignored.includes("completionResponseSlow")
) {
if (this.tabbyApiClient.isRateLimitExceeded()) {
statusInfo = { status: "rateLimitExceeded" };
} else if (this.tabbyApiClient.hasCompletionResponseTimeIssue() && !ignored.includes("completionResponseSlow")) {
statusInfo = { status: "completionResponseSlow" };
} else if (this.tabbyApiClient.isFetchingCompletion()) {
statusInfo = { status: "fetching" };
Expand Down Expand Up @@ -272,7 +269,7 @@ export class StatusProvider extends EventEmitter implements Feature {
case "completionResponseSlow":
statusInfo.tooltip = "Tabby: Slow Completion Response Detected";
break;
case "rateLimited":
case "rateLimitExceeded":
statusInfo.tooltip = "Tabby: Too Many Requests";
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion clients/vscode/src/StatusBarItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class StatusBarItem {
break;
}
case "completionResponseSlow":
case "rateLimited": {
case "rateLimitExceeded": {
this.setColorWarning();
this.setIcon(iconWarning);
this.setTooltip(statusInfo.tooltip);
Expand Down
2 changes: 1 addition & 1 deletion clients/vscode/src/commands/commandPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class CommandPalette {
},
};
}
case "rateLimited": {
case 'rateLimitExceeded': {
return {
label: `${STATUS_PREFIX}Too Many Requests`,
description: "Request limit exceeded",
Expand Down

0 comments on commit f77d2ce

Please sign in to comment.