diff --git a/src/main/java/com/sourcegraph/cody/agent/protocol/TelemetryEventParameters.kt b/src/main/java/com/sourcegraph/cody/agent/protocol/TelemetryEventParameters.kt deleted file mode 100644 index 383d8ab9cc..0000000000 --- a/src/main/java/com/sourcegraph/cody/agent/protocol/TelemetryEventParameters.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.sourcegraph.cody.agent.protocol - -enum class BillingProduct { - CODY -} - -enum class BillingCategory { - CORE, - BILLABLE -} - -data class BillingMetadata(val product: BillingProduct, val category: BillingCategory) - -data class TelemetryEventParameters( - val version: Long? = null, - val interactionID: String? = null, - val metadata: Map? = null, - val billingMetadata: BillingMetadata? = null, - val privateMetadata: Map? = null, -) diff --git a/src/main/java/com/sourcegraph/cody/chat/CodeEditorFactory.java b/src/main/java/com/sourcegraph/cody/chat/CodeEditorFactory.java index d1bb82b8f3..8e3e03cb92 100644 --- a/src/main/java/com/sourcegraph/cody/chat/CodeEditorFactory.java +++ b/src/main/java/com/sourcegraph/cody/chat/CodeEditorFactory.java @@ -2,7 +2,5 @@ public class CodeEditorFactory { - public static final int spaceBetweenButtons = 5; - public static volatile String lastCopiedText = null; } diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt index 4da3eac0b9..9220da56e5 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt @@ -3,7 +3,6 @@ package com.sourcegraph.cody.agent import com.sourcegraph.cody.agent.protocol.NetworkRequest -import com.sourcegraph.cody.agent.protocol.TelemetryEvent import com.sourcegraph.cody.agent.protocol_generated.AutocompleteParams import com.sourcegraph.cody.agent.protocol_generated.AutocompleteResult import com.sourcegraph.cody.agent.protocol_generated.Chat_ImportParams @@ -135,6 +134,11 @@ interface _SubsetGeneratedCodyAgentServer { @JsonRequest("testing/ignore/overridePolicy") fun testing_ignore_overridePolicy(params: ContextFilters?): CompletableFuture + @JsonRequest("telemetry/recordEvent") + fun telemetry_recordEvent( + params: com.sourcegraph.cody.agent.protocol_generated.TelemetryEvent + ): CompletableFuture + // // ============= // // Notifications // // ============= @@ -182,10 +186,6 @@ interface _SubsetGeneratedCodyAgentServer { * works similar to JavaScript Proxy. */ interface _LegacyAgentServer { - - @JsonRequest("telemetry/recordEvent") - fun recordEvent(event: TelemetryEvent): CompletableFuture - @JsonRequest("testing/requestErrors") fun testingRequestErrors(): CompletableFuture> } diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/protocol/TelemetryEvent.kt b/src/main/kotlin/com/sourcegraph/cody/agent/protocol/TelemetryEvent.kt deleted file mode 100644 index 86f819b8c4..0000000000 --- a/src/main/kotlin/com/sourcegraph/cody/agent/protocol/TelemetryEvent.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.sourcegraph.cody.agent.protocol - -data class TelemetryEvent( - val feature: String, - val action: String, - val parameters: TelemetryEventParameters? -) diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/protocol_extensions/BillingMetadata.kt b/src/main/kotlin/com/sourcegraph/cody/agent/protocol_extensions/BillingMetadata.kt new file mode 100644 index 0000000000..21fa35e735 --- /dev/null +++ b/src/main/kotlin/com/sourcegraph/cody/agent/protocol_extensions/BillingMetadata.kt @@ -0,0 +1,12 @@ +package com.sourcegraph.cody.agent.protocol_extensions + +object BillingMetadata { + object Product { + const val CODY = "cody" + } + + object Category { + const val CORE = "core" + const val BILLABLE = "billable" + } +} diff --git a/src/main/kotlin/com/sourcegraph/cody/config/CodyAccountListModel.kt b/src/main/kotlin/com/sourcegraph/cody/config/CodyAccountListModel.kt index d2026113f2..27f2717d4f 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/CodyAccountListModel.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/CodyAccountListModel.kt @@ -5,10 +5,9 @@ import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.project.Project import com.intellij.openapi.ui.JBPopupMenu import com.intellij.ui.awt.RelativePoint -import com.sourcegraph.cody.agent.protocol.BillingCategory -import com.sourcegraph.cody.agent.protocol.BillingMetadata -import com.sourcegraph.cody.agent.protocol.BillingProduct -import com.sourcegraph.cody.agent.protocol.TelemetryEventParameters +import com.sourcegraph.cody.agent.protocol_extensions.BillingMetadata +import com.sourcegraph.cody.agent.protocol_generated.BillingMetadataParams +import com.sourcegraph.cody.agent.protocol_generated.ParametersParams import com.sourcegraph.cody.auth.ui.AccountsListModel import com.sourcegraph.cody.auth.ui.AccountsListModelBase import com.sourcegraph.cody.telemetry.TelemetryV2 @@ -71,8 +70,10 @@ class CodyAccountListModel(private val project: Project) : project, "auth.signin.token", "clicked", - TelemetryEventParameters( - billingMetadata = BillingMetadata(BillingProduct.CODY, BillingCategory.BILLABLE))) + ParametersParams( + billingMetadata = + BillingMetadataParams( + BillingMetadata.Product.CODY, BillingMetadata.Category.BILLABLE))) val account = CodyAccount(login, displayName, server, id) if (accountsListModel.isEmpty) { diff --git a/src/main/kotlin/com/sourcegraph/cody/config/CodyPersistentAccountsHost.kt b/src/main/kotlin/com/sourcegraph/cody/config/CodyPersistentAccountsHost.kt index bb72972843..36043e11ee 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/CodyPersistentAccountsHost.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/CodyPersistentAccountsHost.kt @@ -1,10 +1,9 @@ package com.sourcegraph.cody.config import com.intellij.openapi.project.Project -import com.sourcegraph.cody.agent.protocol.BillingCategory -import com.sourcegraph.cody.agent.protocol.BillingMetadata -import com.sourcegraph.cody.agent.protocol.BillingProduct -import com.sourcegraph.cody.agent.protocol.TelemetryEventParameters +import com.sourcegraph.cody.agent.protocol_extensions.BillingMetadata +import com.sourcegraph.cody.agent.protocol_generated.BillingMetadataParams +import com.sourcegraph.cody.agent.protocol_generated.ParametersParams import com.sourcegraph.cody.telemetry.TelemetryV2 class CodyPersistentAccountsHost(private val project: Project) : CodyAccountsHost { @@ -19,8 +18,10 @@ class CodyPersistentAccountsHost(private val project: Project) : CodyAccountsHos project, "auth.signin.token", "clicked", - TelemetryEventParameters( - billingMetadata = BillingMetadata(BillingProduct.CODY, BillingCategory.BILLABLE))) + ParametersParams( + billingMetadata = + BillingMetadataParams( + BillingMetadata.Product.CODY, BillingMetadata.Category.BILLABLE))) val codyAccount = CodyAccount(login, displayName, server, id) val authManager = CodyAuthenticationManager.getInstance() diff --git a/src/main/kotlin/com/sourcegraph/cody/config/LogInToSourcegraphAction.kt b/src/main/kotlin/com/sourcegraph/cody/config/LogInToSourcegraphAction.kt index 2cee68fffb..3c3c53a437 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/LogInToSourcegraphAction.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/LogInToSourcegraphAction.kt @@ -5,10 +5,9 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.PlatformCoreDataKeys import com.intellij.openapi.project.Project import com.intellij.util.ui.JBUI -import com.sourcegraph.cody.agent.protocol.BillingCategory -import com.sourcegraph.cody.agent.protocol.BillingMetadata -import com.sourcegraph.cody.agent.protocol.BillingProduct -import com.sourcegraph.cody.agent.protocol.TelemetryEventParameters +import com.sourcegraph.cody.agent.protocol_extensions.BillingMetadata +import com.sourcegraph.cody.agent.protocol_generated.BillingMetadataParams +import com.sourcegraph.cody.agent.protocol_generated.ParametersParams import com.sourcegraph.cody.api.SourcegraphApiRequestExecutor import com.sourcegraph.cody.auth.SsoAuthMethod import com.sourcegraph.cody.telemetry.TelemetryV2 @@ -28,8 +27,10 @@ class LogInToSourcegraphAction : BaseAddAccountWithTokenAction() { it, "auth.login", "clicked", - TelemetryEventParameters( - billingMetadata = BillingMetadata(BillingProduct.CODY, BillingCategory.BILLABLE))) + ParametersParams( + billingMetadata = + BillingMetadataParams( + BillingMetadata.Product.CODY, BillingMetadata.Category.BILLABLE))) } val accountsHost = getCodyAccountsHost(e) ?: return @@ -61,8 +62,10 @@ class AddCodyEnterpriseAccountAction : BaseAddAccountWithTokenAction() { it, "auth.login", "clicked", - TelemetryEventParameters( - billingMetadata = BillingMetadata(BillingProduct.CODY, BillingCategory.BILLABLE))) + ParametersParams( + billingMetadata = + BillingMetadataParams( + BillingMetadata.Product.CODY, BillingMetadata.Category.BILLABLE))) } val accountsHost = getCodyAccountsHost(e) ?: return @@ -91,12 +94,6 @@ abstract class BaseAddAccountWithTokenAction : DumbAwareEDTAction() { ?: DataManager.getInstance().loadFromDataContext(e.dataContext, CodyAccountsHost.KEY)) } -fun signInWithSourcegraphDialog(project: Project?, parent: Component?): BaseLoginDialog = - SourcegraphTokenLoginDialog(project, parent, SsoAuthMethod.DEFAULT).apply { - title = "Sign in with Sourcegraph" - setLoginButtonText("Sign in") - } - internal class SourcegraphTokenLoginDialog( project: Project?, parent: Component?, diff --git a/src/main/kotlin/com/sourcegraph/cody/listeners/CodyDocumentListener.kt b/src/main/kotlin/com/sourcegraph/cody/listeners/CodyDocumentListener.kt index 54848c0169..0382426a46 100644 --- a/src/main/kotlin/com/sourcegraph/cody/listeners/CodyDocumentListener.kt +++ b/src/main/kotlin/com/sourcegraph/cody/listeners/CodyDocumentListener.kt @@ -5,10 +5,9 @@ import com.intellij.openapi.editor.event.BulkAwareDocumentListener import com.intellij.openapi.editor.event.DocumentEvent import com.intellij.openapi.project.Project import com.sourcegraph.cody.agent.CodyAgentService -import com.sourcegraph.cody.agent.protocol.BillingCategory -import com.sourcegraph.cody.agent.protocol.BillingMetadata -import com.sourcegraph.cody.agent.protocol.BillingProduct +import com.sourcegraph.cody.agent.protocol_extensions.BillingMetadata import com.sourcegraph.cody.agent.protocol_extensions.ProtocolTextDocumentExt +import com.sourcegraph.cody.agent.protocol_generated.BillingMetadataParams import com.sourcegraph.cody.agent.protocol_generated.CompletionItemParams import com.sourcegraph.cody.autocomplete.CodyAutocompleteManager import com.sourcegraph.cody.autocomplete.action.AcceptCodyAutocompleteAction @@ -19,6 +18,7 @@ import com.sourcegraph.utils.CodyEditorUtil class CodyDocumentListener(val project: Project) : BulkAwareDocumentListener { + // todo: it does not work after the migration to webview. see: linear.app/sourcegraph/issue/QA-78 private fun logCodeCopyPastedFromChat(event: DocumentEvent) { val pastedCode = event.newFragment.toString() if (pastedCode.isNotBlank() && CodeEditorFactory.lastCopiedText == pastedCode) { @@ -28,7 +28,8 @@ class CodyDocumentListener(val project: Project) : BulkAwareDocumentListener { feature = "keyDown", action = "paste", pastedCode, - billingMetadata = BillingMetadata(BillingProduct.CODY, BillingCategory.CORE)) + billingMetadata = + BillingMetadataParams(BillingMetadata.Product.CODY, BillingMetadata.Category.CORE)) } } diff --git a/src/main/kotlin/com/sourcegraph/cody/telemetry/TelemetryV2.kt b/src/main/kotlin/com/sourcegraph/cody/telemetry/TelemetryV2.kt index 191ca94b31..d2b0b81d91 100644 --- a/src/main/kotlin/com/sourcegraph/cody/telemetry/TelemetryV2.kt +++ b/src/main/kotlin/com/sourcegraph/cody/telemetry/TelemetryV2.kt @@ -3,9 +3,9 @@ package com.sourcegraph.cody.telemetry import com.intellij.openapi.application.ApplicationInfo import com.intellij.openapi.project.Project import com.sourcegraph.cody.agent.CodyAgentService -import com.sourcegraph.cody.agent.protocol.BillingMetadata -import com.sourcegraph.cody.agent.protocol.TelemetryEvent -import com.sourcegraph.cody.agent.protocol.TelemetryEventParameters +import com.sourcegraph.cody.agent.protocol_generated.BillingMetadataParams +import com.sourcegraph.cody.agent.protocol_generated.ParametersParams +import com.sourcegraph.cody.agent.protocol_generated.TelemetryEvent import com.sourcegraph.config.ConfigUtil class TelemetryV2 { @@ -14,18 +14,18 @@ class TelemetryV2 { project: Project, feature: String, action: String, - parameters: TelemetryEventParameters? = null + parameters: ParametersParams? = null ) { val versionParameters = mapOf( "ideProductCode" to ConfigUtil.getIntellijProductCode(), "ideBaselineVersion" to ApplicationInfo.getInstance().build.baselineVersion.toLong()) - val baseParameters = parameters ?: TelemetryEventParameters() + val baseParameters = parameters ?: ParametersParams() val newParameters = baseParameters.copy(metadata = baseParameters.metadata?.plus(versionParameters)) CodyAgentService.withAgent(project) { agent -> - agent.server.recordEvent( + agent.server.telemetry_recordEvent( TelemetryEvent(feature = "cody.$feature", action = action, parameters = newParameters)) } } @@ -35,7 +35,7 @@ class TelemetryV2 { feature: String, action: String, code: String, - billingMetadata: BillingMetadata? = null + billingMetadata: BillingMetadataParams ) { val op = if (action.startsWith("copy")) "copy" @@ -51,7 +51,7 @@ class TelemetryV2 { feature = feature, action = action, parameters = - TelemetryEventParameters( + ParametersParams( metadata = metadata, privateMetadata = privateMetadata, billingMetadata = billingMetadata))