feat(agent): add server info in AgentConnected event. (#402)

release-0.2
Zhiming Ma 2023-09-05 15:06:35 +08:00 committed by GitHub
parent a207520571
commit f514e47c2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 29 deletions

View File

@ -3,21 +3,12 @@
"info": { "info": {
"title": "Tabby Server", "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.", "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": { "license": { "name": "Apache 2.0", "url": "https://github.com/TabbyML/tabby/blob/main/LICENSE" },
"name": "Apache 2.0",
"url": "https://github.com/TabbyML/tabby/blob/main/LICENSE"
},
"version": "0.1.0" "version": "0.1.0"
}, },
"servers": [ "servers": [
{ { "url": "https://playground.app.tabbyml.com", "description": "Playground server" },
"url": "https://playground.app.tabbyml.com", { "url": "http://localhost:8080", "description": "Local server" }
"description": "Playground server"
},
{
"url": "http://localhost:8080",
"description": "Local server"
}
], ],
"paths": { "paths": {
"/v1/completions": { "/v1/completions": {
@ -25,13 +16,7 @@
"tags": ["v1"], "tags": ["v1"],
"operationId": "completion", "operationId": "completion",
"requestBody": { "requestBody": {
"content": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CompletionRequest" } } },
"application/json": {
"schema": {
"$ref": "#/components/schemas/CompletionRequest"
}
}
},
"required": true "required": true
}, },
"responses": { "responses": {
@ -105,14 +90,16 @@
}, },
"HealthState": { "HealthState": {
"type": "object", "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": { "properties": {
"model": { "type": "string" }, "model": { "type": "string" },
"device": { "type": "string" }, "device": { "type": "string" },
"compute_type": { "type": "string" }, "compute_type": { "type": "string" },
"arch": { "type": "string" }, "arch": { "type": "string" },
"cpu_info": { "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": { "LogEventRequest": {
@ -135,6 +122,16 @@
"nullable": true "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" }
}
} }
} }
} }

View File

@ -70,6 +70,9 @@ export class AnonymousUsageLogger {
if (unique && this.emittedUniqueEvent.indexOf(event) >= 0) { if (unique && this.emittedUniqueEvent.indexOf(event) >= 0) {
return; return;
} }
if (unique) {
this.emittedUniqueEvent.push(event);
}
await this.anonymousUsageTrackingApi.api await this.anonymousUsageTrackingApi.api
.usage({ .usage({
distinctId: this.anonymousId, distinctId: this.anonymousId,
@ -80,11 +83,6 @@ export class AnonymousUsageLogger {
...data, ...data,
}, },
}) })
.then(() => {
if (unique) {
this.emittedUniqueEvent.push(event);
}
})
.catch((error) => { .catch((error) => {
this.logger.error({ error }, "Error when sending anonymous usage data"); this.logger.error({ error }, "Error when sending anonymous usage data");
}); });

View File

@ -120,9 +120,6 @@ export class TabbyAgent extends EventEmitter implements Agent {
if (this.status === "unauthorized") { if (this.status === "unauthorized") {
this.emitAuthRequired(); 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, {}) return this.callApi(this.api.v1.health, {})
.then((healthState) => { .then((healthState) => {
this.serverHealthState = healthState; this.serverHealthState = healthState;
if (this.status === "ready") {
this.anonymousUsageLogger.uniqueEvent("AgentConnected", healthState);
}
}) })
.catch(() => {}); .catch(() => {});
} }