fix(agent): hotfix vscode extension 0.6.1. Filter out no data AgentStats event. (#489)

release-0.2
Zhiming Ma 2023-09-29 09:58:44 +08:00 committed by GitHub
parent 5d9ca6928c
commit 4ebad71805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 14 deletions

View File

@ -10,6 +10,6 @@
"devDependencies": { "devDependencies": {
"cpy-cli": "^4.2.0", "cpy-cli": "^4.2.0",
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"tabby-agent": "0.3.0" "tabby-agent": "0.3.1"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "tabby-agent", "name": "tabby-agent",
"version": "0.3.0", "version": "0.3.1",
"description": "Generic client agent for Tabby AI coding assistant IDE extensions.", "description": "Generic client agent for Tabby AI coding assistant IDE extensions.",
"repository": "https://github.com/TabbyML/tabby", "repository": "https://github.com/TabbyML/tabby",
"main": "./dist/index.js", "main": "./dist/index.js",

View File

@ -18,7 +18,8 @@ export class AnonymousUsageLogger {
: `${process.version} ${process.platform} ${require("os").arch()} ${require("os").release()}`, : `${process.version} ${process.platform} ${require("os").arch()} ${require("os").release()}`,
}; };
private sessionProperties: Record<string, any> = {}; private sessionProperties: Record<string, any> = {};
private pendingUserProperties: Record<string, any> = {}; private userProperties: Record<string, any> = {};
private userPropertiesUpdated = false;
private emittedUniqueEvent: string[] = []; private emittedUniqueEvent: string[] = [];
private dataStore: DataStore | null = null; private dataStore: DataStore | null = null;
private anonymousId: string; private anonymousId: string;
@ -68,7 +69,8 @@ export class AnonymousUsageLogger {
* Set properties which will be bind to the user. * Set properties which will be bind to the user.
*/ */
setUserProperties(key: string, value: any) { setUserProperties(key: string, value: any) {
setProperty(this.pendingUserProperties, key, value); setProperty(this.userProperties, key, value);
this.userPropertiesUpdated = true;
} }
async uniqueEvent(event: string, data: { [key: string]: any } = {}) { async uniqueEvent(event: string, data: { [key: string]: any } = {}) {
@ -90,9 +92,9 @@ export class AnonymousUsageLogger {
...this.sessionProperties, ...this.sessionProperties,
...data, ...data,
}; };
if (Object.keys(this.pendingUserProperties).length > 0) { if (this.userPropertiesUpdated) {
properties["$set"] = this.pendingUserProperties; properties["$set"] = this.userProperties;
this.pendingUserProperties = {}; this.userPropertiesUpdated = false;
} }
try { try {
await this.anonymousUsageTrackingApi.POST("/usage", { await this.anonymousUsageTrackingApi.POST("/usage", {

View File

@ -20,7 +20,10 @@ class Average {
this.quantity += 1; this.quantity += 1;
} }
mean(): number { mean(): number | undefined {
if (this.quantity === 0) {
return undefined;
}
return this.sum / this.quantity; return this.sum / this.quantity;
} }

View File

@ -70,7 +70,6 @@ export class TabbyAgent extends EventEmitter implements Agent {
this.submitStatsTimer = setInterval(async () => { this.submitStatsTimer = setInterval(async () => {
await this.submitStats(); await this.submitStats();
this.logger.debug("Stats submitted");
}, TabbyAgent.submitStatsInterval); }, TabbyAgent.submitStatsInterval);
} }
@ -185,8 +184,11 @@ export class TabbyAgent extends EventEmitter implements Agent {
private async submitStats() { private async submitStats() {
const stats = this.completionProviderStats.stats(); const stats = this.completionProviderStats.stats();
await this.anonymousUsageLogger.event("AgentStats", { stats, config: this.config.completion }); if (stats.completion_request.count > 0) {
this.completionProviderStats.reset(); await this.anonymousUsageLogger.event("AgentStats", { stats });
this.completionProviderStats.reset();
this.logger.debug({ stats }, "Stats submitted");
}
} }
private async post<T extends Parameters<typeof this.api.POST>[0]>( private async post<T extends Parameters<typeof this.api.POST>[0]>(

View File

@ -10,6 +10,6 @@
"devDependencies": { "devDependencies": {
"cpy-cli": "^4.2.0", "cpy-cli": "^4.2.0",
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"tabby-agent": "0.3.0" "tabby-agent": "0.3.1"
} }
} }

View File

@ -1,3 +1,9 @@
## 0.6.1
### Fixes:
- Reduced the frequency of event submissions for anonymous usage tracking.
## 0.6.0 ## 0.6.0
### Features: ### Features:

View File

@ -7,7 +7,7 @@
"repository": "https://github.com/TabbyML/tabby", "repository": "https://github.com/TabbyML/tabby",
"bugs": "https://github.com/TabbyML/tabby/issues", "bugs": "https://github.com/TabbyML/tabby/issues",
"license": "Apache-2.0", "license": "Apache-2.0",
"version": "0.6.0", "version": "0.6.1",
"keywords": [ "keywords": [
"ai", "ai",
"autocomplete", "autocomplete",
@ -217,6 +217,6 @@
}, },
"dependencies": { "dependencies": {
"@xstate/fsm": "^2.0.1", "@xstate/fsm": "^2.0.1",
"tabby-agent": "0.3.0" "tabby-agent": "0.3.1"
} }
} }