public getChatAuthStateSync()

in packages/core/src/codewhisperer/util/authUtil.ts [469:508]


    public getChatAuthStateSync(conn = this.conn): FeatureAuthState {
        if (conn === undefined) {
            return buildFeatureAuthState(AuthStates.disconnected)
        }

        if (!isSsoConnection(conn) && !isSageMaker()) {
            throw new ToolkitError(`Connection "${conn.id}" is not a valid type: ${conn.type}`)
        }

        // default to expired to indicate reauth is needed if unmodified
        const state: FeatureAuthState = buildFeatureAuthState(AuthStates.expired)

        if (this.isConnectionExpired()) {
            return state
        }

        if (isBuilderIdConnection(conn) || isIdcSsoConnection(conn) || isSageMaker()) {
            // TODO: refactor
            if (isValidCodeWhispererCoreConnection(conn)) {
                if (this.requireProfileSelection()) {
                    state[Features.codewhispererCore] = AuthStates.pendingProfileSelection
                } else {
                    state[Features.codewhispererCore] = AuthStates.connected
                }
            }
            if (isValidAmazonQConnection(conn)) {
                if (this.requireProfileSelection()) {
                    for (const v of Object.values(Features)) {
                        state[v as Feature] = AuthStates.pendingProfileSelection
                    }
                } else {
                    for (const v of Object.values(Features)) {
                        state[v as Feature] = AuthStates.connected
                    }
                }
            }
        }

        return state
    }