Repository: mem0ai/mem0
File: vercel-ai-sdk/src/mem0-utils.ts (TypeScript)

Code before:
        agent_id: config.agent_id,
      });
    }
    if (config?.run_id) {
      filters.AND.push({
        run_id: config.run_id,
      });
    }
    const org_project_filters = {
      org_id: config&&config.org_id,
      project_id: config&&config.project_id,
      org_name: !config?.org_id ? config&&config.org_name : undefined,  // deprecated
      project_name: !config?.org_id ? config&&config.project_name : undefined, // deprecated
    }
    const options = {
        method: 'POST',
        // headers: {Authorization: `Token ${(config&&config.mem0ApiKey) || (typeof process !== 'undefined' && process.env && process.env.MEM0_API_KEY) || ""}`, 'Content-Type': 'application/json'}, 
        headers: {Authorization: `Token ${loadApiKey({
            apiKey: (config&&config.mem0ApiKey),
            environmentVariableName: "MEM0_API_KEY",
            description: "Mem0",
        })}`, 'Content-Type': 'application/json'}, 
        body: JSON.stringify({query, filters, ...config, top_k: config&&config.top_k || top_k, version: "v2", output_format: "v1.1", ...org_project_filters}),
    };
    const baseUrl = config?.host || 'https://api.mem0.ai';
    const response  = await fetch(`${baseUrl}/v2/memories/search/`, options);
    const data =  await response.json();
    return data;
}

const addMemories = async (messages: LanguageModelV1Prompt, config?: Mem0ConfigSettings)=>{
    let finalMessages: Array<Message> = [];
    if (typeof messages === "string") {
        finalMessages = [{ role: "user", content: messages }];
    }else {
      finalMessages = convertToMem0Format(messages);
    }
    const response = await updateMemories(finalMessages, config);
    return response;
}

const updateMemories = async (messages: Array<Message>, config?: Mem0ConfigSettings)=>{
    const options = {
        method: 'POST',
        headers: {Authorization: `Token ${loadApiKey({
            apiKey: (config&&config.mem0ApiKey),
            environmentVariableName: "MEM0_API_KEY",
            description: "Mem0",
        })}`, 'Content-Type': 'application/json'},
        body: JSON.stringify({messages, ...config}),
    };

Review comment (suggestion):
Does the self-hosted server come with `v1` _and_ `v2` support? That's what I was wondering about when I posted the referenced issue. 🤔 

Code after:
        return [];
    }
}

const searchInternalMemories = async (query: string, config?: Mem0ConfigSettings, top_k: number = 5) => {
    try {
        const filters: { AND: Array<{ [key: string]: string | undefined }> } = {
            AND: [],
        };
        if (config?.user_id) {
            filters.AND.push({
                user_id: config.user_id,
            });
        }
        if (config?.app_id) {
            filters.AND.push({
                app_id: config.app_id,
            });
        }
        if (config?.agent_id) {
            filters.AND.push({
                agent_id: config.agent_id,
            });
        }
        if (config?.run_id) {
            filters.AND.push({
                run_id: config.run_id,
            });
        }
        const org_project_filters = {
            org_id: config&&config.org_id,
            project_id: config&&config.project_id,
            org_name: !config?.org_id ? config&&config.org_name : undefined,
            project_name: !config?.org_id ? config&&config.project_name : undefined,
        }

        const apiKey = loadApiKey({
            apiKey: (config&&config.mem0ApiKey),
            environmentVariableName: "MEM0_API_KEY",
            description: "Mem0",
        });

        const options = {
            method: 'POST',
            headers: {
                Authorization: `Token ${apiKey}`,
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                query,
                filters,