From 4ebad71805df9defb17ab898313db0e6e2eb2d3b Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Fri, 29 Sep 2023 09:58:44 +0800 Subject: [PATCH] fix(agent): hotfix vscode extension 0.6.1. Filter out no data AgentStats event. (#489) --- clients/intellij/package.json | 2 +- clients/tabby-agent/package.json | 2 +- clients/tabby-agent/src/AnonymousUsageLogger.ts | 12 +++++++----- clients/tabby-agent/src/CompletionProviderStats.ts | 5 ++++- clients/tabby-agent/src/TabbyAgent.ts | 8 +++++--- clients/vim/package.json | 2 +- clients/vscode/CHANGELOG.md | 6 ++++++ clients/vscode/package.json | 4 ++-- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/clients/intellij/package.json b/clients/intellij/package.json index 650f970..6dcdfc1 100644 --- a/clients/intellij/package.json +++ b/clients/intellij/package.json @@ -10,6 +10,6 @@ "devDependencies": { "cpy-cli": "^4.2.0", "rimraf": "^5.0.1", - "tabby-agent": "0.3.0" + "tabby-agent": "0.3.1" } } diff --git a/clients/tabby-agent/package.json b/clients/tabby-agent/package.json index 036b4b7..aa48082 100644 --- a/clients/tabby-agent/package.json +++ b/clients/tabby-agent/package.json @@ -1,6 +1,6 @@ { "name": "tabby-agent", - "version": "0.3.0", + "version": "0.3.1", "description": "Generic client agent for Tabby AI coding assistant IDE extensions.", "repository": "https://github.com/TabbyML/tabby", "main": "./dist/index.js", diff --git a/clients/tabby-agent/src/AnonymousUsageLogger.ts b/clients/tabby-agent/src/AnonymousUsageLogger.ts index 8e77303..fae0a5c 100644 --- a/clients/tabby-agent/src/AnonymousUsageLogger.ts +++ b/clients/tabby-agent/src/AnonymousUsageLogger.ts @@ -18,7 +18,8 @@ export class AnonymousUsageLogger { : `${process.version} ${process.platform} ${require("os").arch()} ${require("os").release()}`, }; private sessionProperties: Record = {}; - private pendingUserProperties: Record = {}; + private userProperties: Record = {}; + private userPropertiesUpdated = false; private emittedUniqueEvent: string[] = []; private dataStore: DataStore | null = null; private anonymousId: string; @@ -68,7 +69,8 @@ export class AnonymousUsageLogger { * Set properties which will be bind to the user. */ 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 } = {}) { @@ -90,9 +92,9 @@ export class AnonymousUsageLogger { ...this.sessionProperties, ...data, }; - if (Object.keys(this.pendingUserProperties).length > 0) { - properties["$set"] = this.pendingUserProperties; - this.pendingUserProperties = {}; + if (this.userPropertiesUpdated) { + properties["$set"] = this.userProperties; + this.userPropertiesUpdated = false; } try { await this.anonymousUsageTrackingApi.POST("/usage", { diff --git a/clients/tabby-agent/src/CompletionProviderStats.ts b/clients/tabby-agent/src/CompletionProviderStats.ts index 515075f..06ace31 100644 --- a/clients/tabby-agent/src/CompletionProviderStats.ts +++ b/clients/tabby-agent/src/CompletionProviderStats.ts @@ -20,7 +20,10 @@ class Average { this.quantity += 1; } - mean(): number { + mean(): number | undefined { + if (this.quantity === 0) { + return undefined; + } return this.sum / this.quantity; } diff --git a/clients/tabby-agent/src/TabbyAgent.ts b/clients/tabby-agent/src/TabbyAgent.ts index 8cb7f99..3ee2d7c 100644 --- a/clients/tabby-agent/src/TabbyAgent.ts +++ b/clients/tabby-agent/src/TabbyAgent.ts @@ -70,7 +70,6 @@ export class TabbyAgent extends EventEmitter implements Agent { this.submitStatsTimer = setInterval(async () => { await this.submitStats(); - this.logger.debug("Stats submitted"); }, TabbyAgent.submitStatsInterval); } @@ -185,8 +184,11 @@ export class TabbyAgent extends EventEmitter implements Agent { private async submitStats() { const stats = this.completionProviderStats.stats(); - await this.anonymousUsageLogger.event("AgentStats", { stats, config: this.config.completion }); - this.completionProviderStats.reset(); + if (stats.completion_request.count > 0) { + await this.anonymousUsageLogger.event("AgentStats", { stats }); + this.completionProviderStats.reset(); + this.logger.debug({ stats }, "Stats submitted"); + } } private async post[0]>( diff --git a/clients/vim/package.json b/clients/vim/package.json index 7187b64..39bb51f 100644 --- a/clients/vim/package.json +++ b/clients/vim/package.json @@ -10,6 +10,6 @@ "devDependencies": { "cpy-cli": "^4.2.0", "rimraf": "^5.0.1", - "tabby-agent": "0.3.0" + "tabby-agent": "0.3.1" } } diff --git a/clients/vscode/CHANGELOG.md b/clients/vscode/CHANGELOG.md index 7b54f22..a35b2a3 100644 --- a/clients/vscode/CHANGELOG.md +++ b/clients/vscode/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.6.1 + +### Fixes: + +- Reduced the frequency of event submissions for anonymous usage tracking. + ## 0.6.0 ### Features: diff --git a/clients/vscode/package.json b/clients/vscode/package.json index cf8a38c..f37b7dc 100644 --- a/clients/vscode/package.json +++ b/clients/vscode/package.json @@ -7,7 +7,7 @@ "repository": "https://github.com/TabbyML/tabby", "bugs": "https://github.com/TabbyML/tabby/issues", "license": "Apache-2.0", - "version": "0.6.0", + "version": "0.6.1", "keywords": [ "ai", "autocomplete", @@ -217,6 +217,6 @@ }, "dependencies": { "@xstate/fsm": "^2.0.1", - "tabby-agent": "0.3.0" + "tabby-agent": "0.3.1" } }