From f514e47c2e0add176958c2f62bae1de1f9ae639c Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Tue, 5 Sep 2023 15:06:35 +0800 Subject: [PATCH] feat(agent): add server info in AgentConnected event. (#402) --- clients/tabby-agent/openapi/tabby.json | 39 +++++++++---------- .../tabby-agent/src/AnonymousUsageLogger.ts | 8 ++-- clients/tabby-agent/src/TabbyAgent.ts | 6 +-- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/clients/tabby-agent/openapi/tabby.json b/clients/tabby-agent/openapi/tabby.json index 86fbb29..bd1ba1f 100644 --- a/clients/tabby-agent/openapi/tabby.json +++ b/clients/tabby-agent/openapi/tabby.json @@ -3,21 +3,12 @@ "info": { "title": "Tabby Server", "description": "\n[![tabby stars](https://img.shields.io/github/stars/TabbyML/tabby?style=social)](https://github.com/TabbyML/tabby)\n\nOpenAPI documentation for [tabby](https://github.com/TabbyML/tabby), a self-hosted AI coding assistant.", - "license": { - "name": "Apache 2.0", - "url": "https://github.com/TabbyML/tabby/blob/main/LICENSE" - }, + "license": { "name": "Apache 2.0", "url": "https://github.com/TabbyML/tabby/blob/main/LICENSE" }, "version": "0.1.0" }, "servers": [ - { - "url": "https://playground.app.tabbyml.com", - "description": "Playground server" - }, - { - "url": "http://localhost:8080", - "description": "Local server" - } + { "url": "https://playground.app.tabbyml.com", "description": "Playground server" }, + { "url": "http://localhost:8080", "description": "Local server" } ], "paths": { "/v1/completions": { @@ -25,13 +16,7 @@ "tags": ["v1"], "operationId": "completion", "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/CompletionRequest" - } - } - }, + "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CompletionRequest" } } }, "required": true }, "responses": { @@ -105,14 +90,16 @@ }, "HealthState": { "type": "object", - "required": ["model", "device", "compute_type", "arch", "cpu_info", "cpu_count"], + "required": ["model", "device", "compute_type", "arch", "cpu_info", "cpu_count", "cuda_devices", "version"], "properties": { "model": { "type": "string" }, "device": { "type": "string" }, "compute_type": { "type": "string" }, "arch": { "type": "string" }, "cpu_info": { "type": "string" }, - "cpu_count": { "type": "integer", "minimum": 0.0 } + "cpu_count": { "type": "integer", "minimum": 0.0 }, + "cuda_devices": { "type": "array", "items": { "type": "string" } }, + "version": { "$ref": "#/components/schemas/Version" } } }, "LogEventRequest": { @@ -135,6 +122,16 @@ "nullable": true } } + }, + "Version": { + "type": "object", + "required": ["build_date", "build_timestamp", "git_sha", "git_describe"], + "properties": { + "build_date": { "type": "string" }, + "build_timestamp": { "type": "string" }, + "git_sha": { "type": "string" }, + "git_describe": { "type": "string" } + } } } } diff --git a/clients/tabby-agent/src/AnonymousUsageLogger.ts b/clients/tabby-agent/src/AnonymousUsageLogger.ts index db4161a..55857c9 100644 --- a/clients/tabby-agent/src/AnonymousUsageLogger.ts +++ b/clients/tabby-agent/src/AnonymousUsageLogger.ts @@ -70,6 +70,9 @@ export class AnonymousUsageLogger { if (unique && this.emittedUniqueEvent.indexOf(event) >= 0) { return; } + if (unique) { + this.emittedUniqueEvent.push(event); + } await this.anonymousUsageTrackingApi.api .usage({ distinctId: this.anonymousId, @@ -80,11 +83,6 @@ export class AnonymousUsageLogger { ...data, }, }) - .then(() => { - if (unique) { - this.emittedUniqueEvent.push(event); - } - }) .catch((error) => { this.logger.error({ error }, "Error when sending anonymous usage data"); }); diff --git a/clients/tabby-agent/src/TabbyAgent.ts b/clients/tabby-agent/src/TabbyAgent.ts index edea33d..7d11335 100644 --- a/clients/tabby-agent/src/TabbyAgent.ts +++ b/clients/tabby-agent/src/TabbyAgent.ts @@ -120,9 +120,6 @@ export class TabbyAgent extends EventEmitter implements Agent { if (this.status === "unauthorized") { this.emitAuthRequired(); } - if (this.status == "ready") { - this.anonymousUsageLogger.uniqueEvent("AgentConnected"); - } } } @@ -257,6 +254,9 @@ export class TabbyAgent extends EventEmitter implements Agent { return this.callApi(this.api.v1.health, {}) .then((healthState) => { this.serverHealthState = healthState; + if (this.status === "ready") { + this.anonymousUsageLogger.uniqueEvent("AgentConnected", healthState); + } }) .catch(() => {}); }