Steps to follow for migrating to SDK 2.0

Step 1

Replace the Mindset SDK 1.0 file name mindset-sdk.js by mindset-sdk-2.js

The MINDSET-SERVER-URL is also a new URL (not anymore your mindset AI app URL).

<script src="MINDSET-SERVER-URL/mindset-sdk2.js"></script>

Replace MINDSET-SERVER-URL with the URL provided by Mindset AI.

Step 2

Add the <mindset-agent> HTML tag in your HTML body

<mindset-agent 
    agentUid='YOUR-AGENT-UID'
    style='width: 100%; height: 600px; display: block; background-color: rgb(255, 255, 255);">
</mindset-agent>

Step 3

Remove the javascript code that uses the SDK 1.0 methods (initApp() and render() or startAgentThread()). Your existing script should look like this:

mindset.initApp({ 
    appUid: "YOUR-APP-UID", 
    authToken: data.authToken,     
    containerId: "agent-div",      
    loadingText: "Please wait ..." 
})

mindset.startAgentThread({
    agentUid: "YOUR-AGENT-UID",  
    initialQuestion: "Some text to send to the agent"
});

Step 4

Wrap your existing code in charge of fetching the authToken from your back-end script into an async method:

async function getAuthToken() {
    const userEmail = 'useremail@domain.com'
    const userAuthokenServerUrl = `YOUR-BACKEND-API-RETURNING-AUTHTOKEN`

    try {
        const response = await fetch(userAuthokenServerUrl);
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const responseData = await response.json();
        return responseData.authToken;
    } catch (error) {
        console.log('Error fetching auth token:', error);
        throw error;
    }
}

Step 5

Pass your function to the mindset.init() method

<script>
    mindset.init({fetchAuthentication: getAuthToken, appUid: "YOUR-APP-UID"})
</script>

Please check a full example of a SDK 2.0 front-end page here : Front-end full example