Spaces:
Running on Zero

File size: 712 Bytes
fafd7a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import axios from 'axios';

export const API_URL = import.meta.env.VITE_API_URL || '';

// Generate or retrieve a Session ID so each browser gets its own graph + vector store
const getSessionId = () => {
    const fresh = () => (crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).substring(2) + Date.now().toString(36));
    try {
        let sid = localStorage.getItem('cognigraph-session-id');
        if (!sid) {
            sid = fresh();
            localStorage.setItem('cognigraph-session-id', sid);
        }
        return sid;
    } catch {
        return fresh();
    }
};

export const api = axios.create({
    baseURL: API_URL,
    headers: { 'X-Session-ID': getSessionId() },
});