Skip to content

Commit

Permalink
fix(agent): fix agent notify listener when initialization. (#3265)
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes authored Oct 11, 2024
1 parent 8b14765 commit f754e0f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
11 changes: 11 additions & 0 deletions clients/tabby-agent/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class Configurations extends EventEmitter implements Feature {

private configForLsp: TabbyLspConfig = { server: defaultConfigData["server"] }; // config for lsp client

private clientCapabilities: ClientCapabilities | undefined = undefined;

constructor(private readonly dataStore?: DataStore) {
super();
}
Expand Down Expand Up @@ -134,6 +136,8 @@ export class Configurations extends EventEmitter implements Feature {
clientCapabilities: ClientCapabilities,
clientProvidedConfig: ClientProvidedConfig,
): Promise<ServerCapabilities> {
this.clientCapabilities = clientCapabilities;

this.updateClientProvidedConfig(clientProvidedConfig);

connection.onDidChangeConfiguration(async (params) => {
Expand All @@ -151,6 +155,13 @@ export class Configurations extends EventEmitter implements Feature {
return {};
}

async initialized(connection: Connection): Promise<void> {
if (this.clientCapabilities?.tabby?.configDidChangeListener) {
const config = this.getConfigForLsp();
connection.sendNotification(ConfigDidChangeNotification.type, config);
}
}

getClientProvidedConfig(): ClientProvidedConfig {
return this.clientProvided;
}
Expand Down
5 changes: 2 additions & 3 deletions clients/tabby-agent/src/http/tabbyApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,18 @@ export class TabbyApiClient extends EventEmitter {
this.createTimeOutAbortSignal(),
]),
};
this.updateIsConnecting(true);
try {
if (!this.api) {
throw new Error("http client not initialized");
}
this.logger.debug(`Health check request: ${requestDescription}. [${requestId}]`);
this.updateIsConnecting(true);
let response;
if (method === "POST") {
response = await this.api.POST(requestPath, requestOptions);
} else {
response = await this.api.GET(requestPath, requestOptions);
}
this.updateIsConnecting(false);
this.logger.debug(`Health check response status: ${response.response.status}. [${requestId}]`);
if (response.error || !response.response.ok) {
throw new HttpError(response.response);
Expand All @@ -269,7 +268,6 @@ export class TabbyApiClient extends EventEmitter {
this.serverHealth = response.data;
this.updateStatus("ready");
} catch (error) {
this.updateIsConnecting(false);
this.serverHealth = undefined;
if (error instanceof HttpError && error.status == 405 && method !== "POST") {
return await this.healthCheck(signal, "POST");
Expand All @@ -290,6 +288,7 @@ export class TabbyApiClient extends EventEmitter {
this.updateStatus("noConnection");
}
}
this.updateIsConnecting(false);
}

private async updateServerProvidedConfig(): Promise<void> {
Expand Down
8 changes: 5 additions & 3 deletions clients/tabby-agent/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ export class Server {

private async initialized(): Promise<void> {
this.logger.info("Received initialized notification.");
await [this.completionProvider, this.chatFeature].mapAsync((feature: Feature) => {
return feature.initialized?.(this.connection);
});
await [this.configurations, this.statusProvider, this.completionProvider, this.chatFeature].mapAsync(
(feature: Feature) => {
return feature.initialized?.(this.connection);
},
);

// FIXME(@icycodes): remove deprecated methods
if (this.clientCapabilities?.tabby?.agent) {
Expand Down
9 changes: 9 additions & 0 deletions clients/tabby-agent/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class StatusProvider extends EventEmitter implements Feature {
private readonly logger = getLogger("StatusProvider");

private lspConnection: Connection | undefined = undefined;
private clientCapabilities: ClientCapabilities | undefined = undefined;

constructor(
private readonly dataStore: DataStore,
Expand All @@ -35,6 +36,7 @@ export class StatusProvider extends EventEmitter implements Feature {

initialize(connection: Connection, clientCapabilities: ClientCapabilities): ServerCapabilities {
this.lspConnection = connection;
this.clientCapabilities = clientCapabilities;

connection.onRequest(StatusRequest.type, async (params) => {
if (params?.recheckConnection) {
Expand Down Expand Up @@ -79,6 +81,13 @@ export class StatusProvider extends EventEmitter implements Feature {
return {};
}

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

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

0 comments on commit f754e0f

Please sign in to comment.