Skip to content

Commit

Permalink
fix(agent): return help message for status request.
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes committed Nov 22, 2024
1 parent 05bbf74 commit 53ecfed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
6 changes: 1 addition & 5 deletions clients/tabby-agent/src/http/tabbyApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ export class TabbyApiClient extends EventEmitter {
const requestPath = "/v1/health";
const requestDescription = `${method} ${this.endpoint + requestPath}`;
const requestOptions = {
signal: abortSignalFromAnyOf([
signal,
abortController.signal,
this.createTimeOutAbortSignal(),
]),
signal: abortSignalFromAnyOf([signal, abortController.signal, this.createTimeOutAbortSignal()]),
};
try {
if (!this.api) {
Expand Down
16 changes: 15 additions & 1 deletion clients/tabby-agent/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export type ChatEditResolveParams = {
};

/**
* [Tabby] Apply workspace edit request(️)
* [Tabby] Apply workspace edit request(️)
*
* This method is sent from the server to client to apply edit in workspace with options.
* - method: `tabby/workspace/applyEdit`
Expand Down Expand Up @@ -851,8 +851,22 @@ export type StatusInfo = {
| "fetching"
| "completionResponseSlow";
tooltip?: string;
/**
* The health information of the server if available.
*/
serverHealth?: Record<string, unknown>;
/**
* The action to take for this status.
* - `disconnected` or `completionResponseSlow` -> StatusShowHelpMessageCommand
* - others -> undefined
*/
command?: StatusShowHelpMessageCommand | LspCommand;
/**
* The help message if available.
* Only available when this status info is returned from {@link StatusRequest}, not provided in {@link StatusDidChangeNotification}.
* Only available when the status is `disconnected` or `completionResponseSlow`.
*/
helpMessage?: string;
};

/**
Expand Down
17 changes: 8 additions & 9 deletions clients/tabby-agent/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class StatusProvider extends EventEmitter implements Feature {
if (params?.recheckConnection) {
await this.tabbyApiClient.connect({ reset: true });
}
return this.getStatusInfo();
return this.buildStatusInfo({ includeHelpMessage: true });
});
connection.onRequest(StatusShowHelpMessageRequest.type, async () => {
return this.showStatusHelpMessage();
Expand Down Expand Up @@ -83,20 +83,16 @@ export class StatusProvider extends EventEmitter implements Feature {

async initialized(connection: Connection): Promise<void> {
if (this.clientCapabilities?.tabby?.statusDidChangeListener) {
const statusInfo = await this.getStatusInfo();
const statusInfo = await this.buildStatusInfo();
connection.sendNotification(StatusDidChangeNotification.type, statusInfo);
}
}

private async notify() {
const statusInfo = await this.getStatusInfo();
const statusInfo = await this.buildStatusInfo();
this.emit("updated", statusInfo);
}

getStatusInfo(): StatusInfo {
return this.buildStatusInfo();
}

async showStatusHelpMessage(): Promise<boolean | null> {
let params: ShowMessageRequestParams;
let issue: StatusIssuesName | undefined = undefined;
Expand Down Expand Up @@ -186,7 +182,7 @@ export class StatusProvider extends EventEmitter implements Feature {
return false;
}

private buildStatusInfo(): StatusInfo {
private buildStatusInfo(options: { includeHelpMessage?: boolean } = {}): StatusInfo {
let statusInfo: StatusInfo;
const apiClientStatus = this.tabbyApiClient.getStatus();
switch (apiClientStatus) {
Expand Down Expand Up @@ -221,13 +217,16 @@ export class StatusProvider extends EventEmitter implements Feature {
}
this.fillToolTip(statusInfo);
statusInfo.serverHealth = this.tabbyApiClient.getServerHealth();
statusInfo.command = this.tabbyApiClient.hasHelpMessage()
const hasHelpMessage = this.tabbyApiClient.hasHelpMessage();
statusInfo.command = hasHelpMessage
? {
title: "Detail",
command: "tabby/status/showHelpMessage",
arguments: [{}],
}
: undefined;
statusInfo.helpMessage =
hasHelpMessage && options.includeHelpMessage ? this.tabbyApiClient.getHelpMessage() : undefined;
return statusInfo;
}

Expand Down

0 comments on commit 53ecfed

Please sign in to comment.