<commit_before>package circlet.components

import circlet.*
import circlet.reactive.*
import circlet.utils.*
import com.intellij.ide.passwordSafe.*
import com.intellij.openapi.components.*
import com.intellij.openapi.project.*
import klogging.*
import runtime.*
import runtime.reactive.*

private val log = KLoggers.logger("app-idea/CircletLoginComponent.kt")

data class IdePLuginClientData (
    var myEnabled : Boolean? = null
)

@State(
    name = "CircletLoginComponent",
    storages = arrayOf(Storage(
        value = "CircletClient.xml",
        roamingType = RoamingType.DISABLED)))
class CircletLoginComponent() :
    ILifetimedApplicationComponent by LifetimedApplicationComponent(),
    PersistentStateComponent<IdePLuginClientData>{
    val authUrl = "http://localhost:8084/api/v1/authenticate"

    val LOGIN_ID = "CircletLoginComponent.login"
    val PASS_ID = "<PASSWORD>"
    val TOKEN_ID = "CircletLoginComponent.token"

    private val passwords = PasswordSafe.getInstance()

    val login : String get() = passwords.getPassword(ProjectManager.getInstance().defaultProject, this.javaClass, LOGIN_ID).orEmpty()
    val pass : String get() = passwords.getPassword(ProjectManager.getInstance().defaultProject, this.javaClass, PASS_ID).orEmpty()
    val token : String get() = passwords.getPassword(ProjectManager.getInstance().defaultProject, this.javaClass, TOKEN_ID).orEmpty()

    val credentialsUpdated = Signal<Boolean>()
    val enabled = Property(false)

    fun getAccessToken(login : String, pass : String) : Promise<AuthenticationResponse> {
        log.info( "Checking credentials for ${login}" )
        return CircletAuthentication(authUrl).authenticate(login, pass)
    }

    fun setCredentials(login: String, pass: String, token: String) {
        passwords.storePassword(ProjectManager.getInstance().defaultProject, this.javaClass, LOGIN_ID, login)
        passwords.storePassword(ProjectManager.getInstance().defaultProject, this.javaClass, PASS_ID, pass)
        passwords.storePassword(ProjectManager.getInstance().defaultProject, this.javaClass, TOKEN_ID, token)
        credentialsUpdated.fire(true)
    }


    override fun loadState(state: IdePLuginClientData) {
        enabled.value = state.myEnabled ?: false
    }

    override fun getState(): IdePLuginClientData =
        IdePLuginClientData(enabled.value)

}<commit_msg>more accurate handling of throwable - failure conversion<commit_after>package circlet.components

import circlet.*
import circlet.reactive.*
import circlet.utils.*
import com.intellij.ide.passwordSafe.*
import com.intellij.openapi.components.*
import com.intellij.openapi.project.*
import klogging.*
import runtime.*
import runtime.reactive.*

private val log = KLoggers.logger("app-idea/CircletLoginComponent.kt")

data class IdePLuginClientData (
    var myEnabled : Boolean? = null
)

val stagingEndpoint = "172.20.165.72:30896"
val localEndpoint = "127.0.0.1:8084"
val endpoint = localEndpoint

@State(
    name = "CircletLoginComponent",
    storages = arrayOf(Storage(
        value = "CircletClient.xml",
        roamingType = RoamingType.DISABLED)))
class CircletLoginComponent() :
    ILifetimedApplicationComponent by LifetimedApplicationComponent(),
    PersistentStateComponent<IdePLuginClientData>{
    val authEndpoint = "http://$endpoint/api/v1/authenticate"

    val LOGIN_ID = "CircletLoginComponent.login"
    val PASS_ID = "<PASSWORD>"
    val TOKEN_ID = "CircletLoginComponent.token"

    private val passwords = PasswordSafe.getInstance()

    val login : String get() = passwords.getPassword(ProjectManager.getInstance().defaultProject, this.javaClass, LOGIN_ID).orEmpty()
    val pass : String get() = passwords.getPassword(ProjectManager.getInstance().defaultProject, this.javaClass, PASS_ID).orEmpty()
    val token : String get() = passwords.getPassword(ProjectManager.getInstance().defaultProject, this.javaClass, TOKEN_ID).orEmpty()
    val credentialsUpdated = Signal<Boolean>()
    val enabled = Property(false)

    fun getAccessToken(login : String, pass : String) : Promise<AuthenticationResponse> {
        log.info( "Checking credentials for ${login}" )
        return CircletAuthentication(authEndpoint).authenticate(login, pass)
    }

    fun setCredentials(login: String, pass: String, token: String) {
        passwords.storePassword(ProjectManager.getInstance().defaultProject, this.javaClass, LOGIN_ID, login)
        passwords.storePassword(ProjectManager.getInstance().defaultProject, this.javaClass, PASS_ID, pass)
        passwords.storePassword(ProjectManager.getInstance().defaultProject, this.javaClass, TOKEN_ID, token)
        credentialsUpdated.fire(true)
    }


    override fun loadState(state: IdePLuginClientData) {
        enabled.value = state.myEnabled ?: false
    }

    override fun getState(): IdePLuginClientData =
        IdePLuginClientData(enabled.value)

}
{'fraction_non_alphanumeric': 0.10506950122649224, 'fraction_numerical': 0.006336876533115291, 'mean_word_length': 4.61768082663605, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3524919', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1358, 'n_words': 285}