m4Mindset docs

Mindset v3 / Deploy in your app / Integrate Agent Chat SDK 3

View as Markdown

Migrate from SDK 2.0 to SDK 3.0

Step-by-step guide for upgrading your Mindset AI agents from SDK 2.0 to SDK 3.0

Important: SDK 3.0 Configuration Behavior

Before migrating, understand how SDK 3.0 configuration affects your existing agents:

Migration Step

  1. Replace the SDK Script

    Update the script source to use SDK 3.0:

    html
    <script src="MINDSET-SERVER-URL/mindset-sdk3.umd.js"></script>

Complete Migration Example

Here's what your complete SDK 3.0 implementation should look like:

html
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="https://MINDSET-SERVER-URL/mindset-sdk3.umd.js"></script>

        <script>
            async function getAuthToken() {
                const currentUserId = 'session123'
                const userAuthTokenServerUrl = `YOUR-BACKEND-API-RETURNING-AUTHTOKEN`
                
                try {
                    const headers = {
                        "accept": "application/json",
                        "Content-Type": "application/json"
                    };
                    const response = await fetch(userAuthTokenServerUrl, {
                        method: 'POST',
                        headers: headers,
                        body: JSON.stringify({"currentUserId": `${currentUserId}`})
                    });
                    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;
                }
            }

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

    <body>
        <div class="main-container">
            <h1>Mindset Embedded Agent</h1>
        
            <mindset-agent 
                agentUid='YOUR-AGENT-UID'
                style='width: 100%; height: 600px; display: block; background-color: rgb(255, 255, 255); overflow: hidden; border-radius: 12px;'>
            </mindset-agent>
        </div> 
    </body>
</html>