supermemory-ai-provider
Version:
Vercel AI Provider for providing memory to LLMs using Supermemory
1 lines • 39.5 kB
Source Map (JSON)
{"version":3,"sources":["../src/supermemory-facade.ts","../src/provider-response-provider.ts","../src/supermemory-provider-selector.ts","../src/supermemory-utils.ts","../src/supermemory-generic-language-model.ts","../src/supermemory-provider.ts"],"sourcesContent":["import { withoutTrailingSlash } from \"@ai-sdk/provider-utils\";\n\nimport { SupermemoryGenericLanguageModel } from \"./supermemory-generic-language-model\";\nimport type {\n\tSupermemoryChatModelId,\n\tSupermemoryChatSettings,\n} from \"./supermemory-types\";\nimport type { SupermemoryProviderSettings } from \"./supermemory-provider\";\n\nexport class Supermemory {\n\treadonly baseURL: string;\n\treadonly headers?: Record<string, string>;\n\n\tconstructor(\n\t\toptions: SupermemoryProviderSettings = {\n\t\t\tprovider: \"openai\",\n\t\t},\n\t) {\n\t\tthis.baseURL =\n\t\t\twithoutTrailingSlash(options.baseURL) ?? \"https://api.supermemory.ai\";\n\n\t\tthis.headers = options.headers;\n\t}\n\n\tprivate get baseConfig() {\n\t\treturn {\n\t\t\tbaseURL: this.baseURL,\n\t\t\theaders: this.headers,\n\t\t};\n\t}\n\n\tchat(\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings: SupermemoryChatSettings = {},\n\t) {\n\t\treturn new SupermemoryGenericLanguageModel(modelId, settings, {\n\t\t\tprovider: \"openai\",\n\t\t\tmodelType: \"chat\",\n\t\t\t...this.baseConfig,\n\t\t});\n\t}\n\n\tcompletion(\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings: SupermemoryChatSettings = {},\n\t) {\n\t\treturn new SupermemoryGenericLanguageModel(modelId, settings, {\n\t\t\tprovider: \"openai\",\n\t\t\tmodelType: \"completion\",\n\t\t\t...this.baseConfig,\n\t\t});\n\t}\n}\n","import type {\n\tLanguageModelV1,\n\tLanguageModelV1CallOptions,\n\tLanguageModelV1Prompt,\n} from \"ai\";\nimport type { SupermemoryProviderSettings } from \"./supermemory-provider\";\nimport { createOpenAI, type OpenAIProviderSettings } from \"@ai-sdk/openai\";\nimport { type CohereProviderSettings, createCohere } from \"@ai-sdk/cohere\";\nimport {\n\ttype AnthropicProviderSettings,\n\tcreateAnthropic,\n} from \"@ai-sdk/anthropic\";\nimport { createGroq, type GroqProviderSettings } from \"@ai-sdk/groq\";\n\n// Define a more accurate type for what llmClient will hold\ntype LanguageModelFactoryFn = (\n\tmodelId: string,\n\tconfig?: ProviderSettings,\n) => LanguageModelV1;\n\nexport type Provider = LanguageModelFactoryFn; // Provider is this factory function type\n\nexport type ProviderSettings =\n\t| OpenAIProviderSettings\n\t| CohereProviderSettings\n\t| AnthropicProviderSettings\n\t| GroqProviderSettings;\n\nconst convertMessagesToSupermemoryFormat = (\n\tmessages: LanguageModelV1Prompt,\n) => {\n\treturn messages.map((message) => {\n\t\t// If the content is a string, return it as is\n\t\tif (typeof message.content === \"string\") {\n\t\t\treturn message;\n\t\t}\n\n\t\t// Flatten the content array into a single string\n\t\tif (Array.isArray(message.content)) {\n\t\t\tmessage.content = message.content\n\t\t\t\t.map((contentItem) => {\n\t\t\t\t\tif (\"text\" in contentItem) {\n\t\t\t\t\t\treturn contentItem.text;\n\t\t\t\t\t}\n\t\t\t\t\treturn \"\";\n\t\t\t\t})\n\t\t\t\t.join(\" \");\n\t\t}\n\n\t\tconst contentText = message.content;\n\n\t\treturn {\n\t\t\trole: message.role,\n\t\t\tcontent: contentText,\n\t\t};\n\t});\n};\n\nclass SupermemoryAITextGenerator implements LanguageModelV1 {\n\treadonly specificationVersion = \"v1\";\n\treadonly defaultObjectGenerationMode = \"json\";\n\treadonly supportsImageUrls = false;\n\treadonly modelId: string;\n\treadonly provider: string;\n\n\tllmClient: LanguageModelFactoryFn;\n\tllmClientConfig?: ProviderSettings;\n\tconfig: SupermemoryProviderSettings;\n\n\tconstructor(\n\t\tmodelId: string,\n\t\tconfig: SupermemoryProviderSettings,\n\t\tllmClientConfigParam: ProviderSettings,\n\t) {\n\t\tthis.provider = config.provider || \"openai\";\n\t\tswitch (config.provider) {\n\t\t\tcase \"openai\": {\n\t\t\t\tconst openaiProvider = createOpenAI({\n\t\t\t\t\tapiKey: config?.apiKey,\n\t\t\t\t\t...(llmClientConfigParam as OpenAIProviderSettings),\n\t\t\t\t});\n\t\t\t\tif (config?.modelType === \"completion\") {\n\t\t\t\t\tthis.llmClient = (id, cfg) =>\n\t\t\t\t\t\topenaiProvider.completion(id as any, cfg as any);\n\t\t\t\t} else if (config?.modelType === \"chat\") {\n\t\t\t\t\tthis.llmClient = (id, cfg) =>\n\t\t\t\t\t\topenaiProvider.chat(id as any, cfg as any);\n\t\t\t\t} else {\n\t\t\t\t\tthis.llmClient = (id, cfg) =>\n\t\t\t\t\t\topenaiProvider.languageModel(id as any, cfg as any);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"cohere\": {\n\t\t\t\tconst cohereProvider = createCohere({\n\t\t\t\t\tapiKey: config?.apiKey,\n\t\t\t\t\t...(llmClientConfigParam as CohereProviderSettings),\n\t\t\t\t});\n\t\t\t\tthis.llmClient = ((id: string, cfg?: ProviderSettings) =>\n\t\t\t\t\tcohereProvider(id as any, cfg as any)) as any;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"anthropic\": {\n\t\t\t\tconst anthropicProvider = createAnthropic({\n\t\t\t\t\tapiKey: config?.apiKey,\n\t\t\t\t\t...(llmClientConfigParam as AnthropicProviderSettings),\n\t\t\t\t});\n\t\t\t\tthis.llmClient = ((id: string, cfg?: ProviderSettings) =>\n\t\t\t\t\tanthropicProvider.languageModel(id as any, cfg as any)) as any;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"groq\": {\n\t\t\t\tconst groqProvider = createGroq({\n\t\t\t\t\tapiKey: config?.apiKey,\n\t\t\t\t\t...(llmClientConfigParam as GroqProviderSettings),\n\t\t\t\t});\n\t\t\t\tthis.llmClient = ((id: string, cfg?: ProviderSettings) =>\n\t\t\t\t\tgroqProvider(id as any, cfg as any)) as any;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Invalid provider\");\n\t\t}\n\t\tthis.modelId = modelId;\n\t\tthis.llmClientConfig = llmClientConfigParam;\n\t\tthis.config = config;\n\t}\n\n\tdoGenerate(\n\t\toptions: LanguageModelV1CallOptions,\n\t): Promise<Awaited<ReturnType<LanguageModelV1[\"doGenerate\"]>>> {\n\t\tconst modelInstance = this.llmClient(this.modelId, this.llmClientConfig);\n\t\treturn Promise.resolve(modelInstance.doGenerate(options));\n\t}\n\n\tdoStream(\n\t\toptions: LanguageModelV1CallOptions,\n\t): Promise<Awaited<ReturnType<LanguageModelV1[\"doStream\"]>>> {\n\t\tconst modelInstance = this.llmClient(this.modelId, this.llmClientConfig);\n\t\treturn Promise.resolve(modelInstance.doStream(options));\n\t}\n}\n\nexport default SupermemoryAITextGenerator;\n","import type { SupermemoryProviderSettings } from \"./supermemory-provider\";\nimport SupermemoryAITextGenerator, {\n\ttype ProviderSettings,\n} from \"./provider-response-provider\";\nimport type { LanguageModelV1 } from \"ai\";\n\nclass SupermemoryClassSelector {\n\tmodelId: string;\n\tprovider_wrapper: string;\n\tconfig: SupermemoryProviderSettings;\n\tprovider_config?: ProviderSettings;\n\tstatic supportedProviders = [\"openai\", \"anthropic\", \"cohere\", \"groq\"];\n\n\tconstructor(\n\t\tmodelId: string,\n\t\tconfig: SupermemoryProviderSettings,\n\t\tprovider_config?: ProviderSettings,\n\t) {\n\t\tthis.modelId = modelId;\n\t\tthis.provider_wrapper = config.provider || \"openai\";\n\t\tthis.provider_config = provider_config;\n\t\tthis.config = config;\n\n\t\t// Check if provider_wrapper is supported\n\t\tif (\n\t\t\t!SupermemoryClassSelector.supportedProviders.includes(\n\t\t\t\tthis.provider_wrapper,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(`Model not supported: ${this.provider_wrapper}`);\n\t\t}\n\t}\n\n\tcreateProvider(): LanguageModelV1 {\n\t\treturn new SupermemoryAITextGenerator(\n\t\t\tthis.modelId,\n\t\t\tthis.config,\n\t\t\tthis.provider_config || {},\n\t\t) as LanguageModelV1;\n\t}\n}\n\nexport { SupermemoryClassSelector };\n","import type {\n\tLanguageModelV1Message,\n\tLanguageModelV1Prompt,\n} from \"@ai-sdk/provider\";\nimport type {\n\tMemoryResult,\n\tSupermemoryConfigSettings,\n} from \"./supermemory-types\";\nimport { loadApiKey } from \"@ai-sdk/provider-utils\";\nimport Supermemory from \"supermemory\";\n\ninterface Message {\n\trole: string;\n\tcontent: string;\n}\n\ninterface ContentObject {\n\ttype: string;\n\ttext: string;\n}\n\nconst flattenPrompt = (prompt: LanguageModelV1Prompt) => {\n\ttry {\n\t\treturn prompt\n\t\t\t.map((part) => {\n\t\t\t\tif (part.role === \"user\") {\n\t\t\t\t\treturn part.content\n\t\t\t\t\t\t.filter((obj) => obj.type === \"text\")\n\t\t\t\t\t\t.map((obj) => obj.text)\n\t\t\t\t\t\t.join(\" \");\n\t\t\t\t}\n\t\t\t\treturn \"\";\n\t\t\t})\n\t\t\t.join(\" \");\n\t} catch (error) {\n\t\tconsole.error(\"Error in flattenPrompt:\", error);\n\t\treturn \"\";\n\t}\n};\n\nconst convertToSupermemoryFormat = (messages: LanguageModelV1Prompt) => {\n\ttry {\n\t\treturn messages.flatMap((message: LanguageModelV1Message) => {\n\t\t\ttry {\n\t\t\t\tif (typeof message.content === \"string\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: message.role,\n\t\t\t\t\t\tcontent: message.content,\n\t\t\t\t\t} as Message;\n\t\t\t\t}\n\n\t\t\t\treturn (message.content as ContentObject[])\n\t\t\t\t\t.map((obj: ContentObject) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (obj.type === \"text\") {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\trole: message.role,\n\t\t\t\t\t\t\t\t\tcontent: obj.text,\n\t\t\t\t\t\t\t\t} as Message;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconsole.error(\"Error processing content object:\", error);\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\t.filter((item): item is Message => item !== null);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\"Error processing message:\", error);\n\t\t\t\treturn [];\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\tconsole.error(\"Error in convertToSupermemoryFormat:\", error);\n\t\treturn [];\n\t}\n};\n\n// Initialize Supermemory client\nconst getSupermemoryClient = (config?: SupermemoryConfigSettings) => {\n\ttry {\n\t\tconst apiKey = loadApiKey({\n\t\t\tapiKey: config?.supermemoryApiKey,\n\t\t\tenvironmentVariableName: \"SUPERMEMORY_API_KEY\",\n\t\t\tdescription: \"Supermemory\",\n\t\t});\n\n\t\treturn new Supermemory({\n\t\t\tapiKey,\n\t\t});\n\t} catch (error) {\n\t\tconsole.error(\"Error initializing Supermemory client:\", error);\n\t\tthrow error;\n\t}\n};\n\nconst searchMemories = async (\n\tquery: string,\n\tconfig?: SupermemoryConfigSettings,\n\ttop_k = 5,\n) => {\n\ttry {\n\t\tconst client = getSupermemoryClient(config);\n\n\t\tconst filters: Record<string, unknown> = {};\n\t\tif (config?.user_id) {\n\t\t\tfilters.user_id = config.user_id;\n\t\t}\n\n\t\tconst searchResponse = await client.search.execute({\n\t\t\tq: query,\n\t\t\t...(Object.keys(filters).length > 0 ? { filters } : {}),\n\t\t});\n\n\t\treturn searchResponse.results as unknown as MemoryResult[];\n\t} catch (error) {\n\t\tconsole.error(\"Error in searchMemories:\", error);\n\t\treturn [];\n\t}\n};\n\nconst addMemories = async (\n\tmessages: LanguageModelV1Prompt,\n\tconfig?: SupermemoryConfigSettings,\n) => {\n\ttry {\n\t\tconst client = getSupermemoryClient(config);\n\t\tlet finalMessages: Message[] = [];\n\n\t\tif (typeof messages === \"string\") {\n\t\t\tfinalMessages = [{ role: \"user\", content: messages }];\n\t\t} else {\n\t\t\tfinalMessages = convertToSupermemoryFormat(messages);\n\t\t}\n\n\t\tconst addPromises = finalMessages.map(async (message) => {\n\t\t\treturn await client.memories.add({\n\t\t\t\tcontent: message.content,\n\t\t\t\tcontainerTags: config?.user_id ? [config.user_id] : undefined,\n\t\t\t\tmetadata: config?.metadata as\n\t\t\t\t\t| Record<string, string | number | boolean>\n\t\t\t\t\t| undefined,\n\t\t\t});\n\t\t});\n\n\t\tconst results = await Promise.all(addPromises);\n\t\treturn results.filter(Boolean);\n\t} catch (error) {\n\t\tconsole.error(\"Error in addMemories:\", error);\n\t\tthrow error;\n\t}\n};\n\nconst getMemories = async (\n\tprompt: LanguageModelV1Prompt | string,\n\tconfig?: SupermemoryConfigSettings,\n) => {\n\ttry {\n\t\tconst message = typeof prompt === \"string\" ? prompt : flattenPrompt(prompt);\n\t\tconst memories = await searchMemories(message, config);\n\n\t\treturn memories;\n\t} catch (error) {\n\t\tconsole.error(\"Error in getMemories:\", error);\n\t\treturn [];\n\t}\n};\n\nconst retrieveMemories = async (\n\tprompt: LanguageModelV1Prompt | string,\n\tconfig?: SupermemoryConfigSettings,\n) => {\n\ttry {\n\t\tconst message = typeof prompt === \"string\" ? prompt : flattenPrompt(prompt);\n\t\tconst systemPrompt =\n\t\t\t\"These are the memories I have stored. Give more weightage to the question by users and try to answer that first. You have to modify your answer based on the memories I have provided. If the memories are irrelevant you can ignore them. Also don't reply to this section of the prompt, or the memories, they are only for your reference. The System prompt starts after text System Message: \\n\\n\";\n\n\t\tconst memories = await searchMemories(message, config);\n\n\t\tif (!memories || memories.length === 0) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst memoriesText = memories\n\t\t\t.map((memory: MemoryResult) => {\n\t\t\t\treturn `Memory: ${memory.content || memory.memory}\\n\\n`;\n\t\t\t})\n\t\t\t.join(\"\\n\\n\");\n\n\t\treturn `System Message: ${systemPrompt} ${memoriesText}`;\n\t} catch (error) {\n\t\tconsole.error(\"Error in retrieveMemories:\", error);\n\t\tthrow error;\n\t}\n};\n\nexport {\n\taddMemories,\n\tretrieveMemories,\n\tflattenPrompt,\n\tsearchMemories,\n\tgetMemories,\n};\n","import type {\n\tLanguageModelV1,\n\tLanguageModelV1CallOptions,\n\tLanguageModelV1Message,\n\tLanguageModelV1Source,\n\tLanguageModelV1ProviderMetadata,\n} from \"@ai-sdk/provider\";\n\nimport type {\n\tSupermemoryChatConfig,\n\tSupermemoryChatModelId,\n\tSupermemoryChatSettings,\n\tSupermemoryConfigSettings,\n\tSupermemoryStreamResponse,\n\tMemoryResult,\n\tSerializableMemoryResult,\n\tSerializableValue,\n} from \"./supermemory-types\";\nimport { SupermemoryClassSelector } from \"./supermemory-provider-selector\";\nimport type { SupermemoryProviderSettings } from \"./supermemory-provider\";\nimport {\n\taddMemories,\n\tgetMemories,\n\tretrieveMemories,\n} from \"./supermemory-utils\";\n\ntype SupermemoryProviderMetadata = {\n\tmemories: SerializableMemoryResult[];\n\tmemoriesText: string;\n} & Record<string, SerializableValue>;\n\ntype SupermemoryMemoryMetadata = {\n\tmemory: SerializableMemoryResult;\n\tmemoryText: string;\n} & Record<string, SerializableValue>;\n\ninterface SupermemorySource extends LanguageModelV1Source {\n\tproviderMetadata: {\n\t\tsupermemory: SupermemoryProviderMetadata | SupermemoryMemoryMetadata;\n\t};\n}\n\nconst generateRandomId = () => {\n\treturn `supermemory-${Math.random().toString(36).substring(2, 15)}${Math.random().toString(36).substring(2, 15)}`;\n};\n\nexport class SupermemoryGenericLanguageModel implements LanguageModelV1 {\n\treadonly specificationVersion = \"v1\";\n\treadonly defaultObjectGenerationMode = \"json\";\n\treadonly supportsImageUrls = false;\n\n\tconstructor(\n\t\tpublic readonly modelId: SupermemoryChatModelId,\n\t\tpublic readonly settings: SupermemoryChatSettings,\n\t\tpublic readonly config: SupermemoryChatConfig,\n\t\tpublic readonly provider_config?: SupermemoryProviderSettings,\n\t) {\n\t\tthis.provider = config.provider ?? \"openai\";\n\t}\n\n\tprovider: string;\n\n\tprivate async processMemories(\n\t\tmessagesPrompts: LanguageModelV1Message[],\n\t\tsupermemoryConfig: SupermemoryConfigSettings,\n\t) {\n\t\ttry {\n\t\t\t// Add New Memories\n\t\t\ttry {\n\t\t\t\tawait addMemories(messagesPrompts, supermemoryConfig);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(\"Error while adding memories:\", e);\n\t\t\t\t// Original code did not halt on this error, so we'll log and continue.\n\t\t\t\t// Consider if rethrowing or more specific error handling is needed.\n\t\t\t}\n\n\t\t\tconst memories = await getMemories(messagesPrompts, supermemoryConfig);\n\n\t\t\tconst mySystemPrompt =\n\t\t\t\t\"These are the memories I have stored. Give more weightage to the question by users and try to answer that first. You have to modify your answer based on the memories I have provided. If the memories are irrelevant you can ignore them. Also don't reply to this section of the prompt, or the memories, they are only for your reference. The System prompt starts after text System Message: \\n\\n\";\n\n\t\t\tlet memoriesText = \"\";\n\t\t\ttry {\n\t\t\t\tmemoriesText = memories\n\t\t\t\t\t?.map((memory: MemoryResult) => {\n\t\t\t\t\t\treturn `Memory: ${memory.memory}\\n\\n`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\\n\");\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(\"Error while parsing memories\");\n\t\t\t}\n\n\t\t\tconst memoriesPrompt = `System Message: ${mySystemPrompt} ${memoriesText}`;\n\n\t\t\t// System Prompt - The memories go as a system prompt\n\t\t\tconst systemPrompt: LanguageModelV1Message = {\n\t\t\t\trole: \"system\",\n\t\t\t\tcontent: memoriesPrompt,\n\t\t\t};\n\n\t\t\t// Add the system prompt to the beginning of the messages if there are memories\n\t\t\tif (memories?.length > 0) {\n\t\t\t\tmessagesPrompts.unshift(systemPrompt);\n\t\t\t}\n\n\t\t\treturn { memories, messagesPrompts };\n\t\t} catch (e) {\n\t\t\tconsole.error(\"Error while processing memories\");\n\t\t\treturn { memories: [], messagesPrompts };\n\t\t}\n\t}\n\n\tasync doGenerate(\n\t\toptions: LanguageModelV1CallOptions,\n\t): Promise<Awaited<ReturnType<LanguageModelV1[\"doGenerate\"]>>> {\n\t\ttry {\n\t\t\tconst provider = this.config.provider;\n\t\t\tconst supermemory_api_key = this.config.supermemoryApiKey;\n\n\t\t\tconst settings: SupermemoryProviderSettings = {\n\t\t\t\tprovider: provider,\n\t\t\t\tsupermemoryApiKey: supermemory_api_key,\n\t\t\t\tapiKey: this.config.apiKey,\n\t\t\t};\n\n\t\t\tconst supermemoryConfig: SupermemoryConfigSettings = {\n\t\t\t\tsupermemoryApiKey: supermemory_api_key,\n\t\t\t\t...this.config.supermemoryConfig,\n\t\t\t\t...this.settings,\n\t\t\t};\n\n\t\t\tconst selector = new SupermemoryClassSelector(\n\t\t\t\tthis.modelId,\n\t\t\t\tsettings,\n\t\t\t\tthis.provider_config,\n\t\t\t);\n\n\t\t\tconst messagesPrompts = options.prompt;\n\n\t\t\t// Process memories and update prompts\n\t\t\tconst { memories, messagesPrompts: updatedPrompts } =\n\t\t\t\tawait this.processMemories(messagesPrompts, supermemoryConfig);\n\n\t\t\tconst model = selector.createProvider();\n\n\t\t\tconst ans = await model.doGenerate({\n\t\t\t\t...options,\n\t\t\t\tprompt: updatedPrompts,\n\t\t\t});\n\n\t\t\t// If there are no memories, return the original response\n\t\t\tif (!memories || memories?.length === 0) {\n\t\t\t\treturn ans;\n\t\t\t}\n\n\t\t\t// Create sources array with existing sources\n\t\t\tconst sources = [...(ans.sources || [])];\n\n\t\t\t// Add a combined source with all memories\n\t\t\tconst combinedSource: LanguageModelV1Source = {\n\t\t\t\ttitle: \"Supermemory Memories\",\n\t\t\t\tsourceType: \"url\",\n\t\t\t\tid: generateRandomId(),\n\t\t\t\turl: \"https://app.supermemory.ai\",\n\t\t\t\tproviderMetadata: {\n\t\t\t\t\tsupermemory: {\n\t\t\t\t\t\tmemories: memories as SerializableMemoryResult[],\n\t\t\t\t\t\tmemoriesText: memories\n\t\t\t\t\t\t\t.map((memory: MemoryResult) => memory.memory)\n\t\t\t\t\t\t\t.join(\"\\n\\n\"),\n\t\t\t\t\t},\n\t\t\t\t} as LanguageModelV1ProviderMetadata,\n\t\t\t};\n\t\t\tsources.push(combinedSource);\n\n\t\t\t// Add individual memory sources\n\t\t\tfor (const memory of memories) {\n\t\t\t\tconst memorySource: LanguageModelV1Source = {\n\t\t\t\t\ttitle: memory.title || \"Memory\",\n\t\t\t\t\tsourceType: \"url\",\n\t\t\t\t\tid: generateRandomId(),\n\t\t\t\t\turl: \"https://app.supermemory.ai\",\n\t\t\t\t\tproviderMetadata: {\n\t\t\t\t\t\tsupermemory: {\n\t\t\t\t\t\t\tmemory: memory as SerializableMemoryResult,\n\t\t\t\t\t\t\tmemoryText: memory.memory,\n\t\t\t\t\t\t},\n\t\t\t\t\t} as LanguageModelV1ProviderMetadata,\n\t\t\t\t};\n\t\t\t\tsources.push(memorySource);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...ans,\n\t\t\t\tsources,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\t// Handle errors properly\n\t\t\tconsole.error(\"Error in doGenerate:\", error);\n\t\t\tthrow new Error(\"Failed to generate response.\");\n\t\t}\n\t}\n\n\tasync doStream(\n\t\toptions: LanguageModelV1CallOptions,\n\t): Promise<Awaited<ReturnType<LanguageModelV1[\"doStream\"]>>> {\n\t\ttry {\n\t\t\tconst provider = this.config.provider;\n\t\t\tconst supermemory_api_key = this.config.supermemoryApiKey;\n\n\t\t\tconst settings: SupermemoryProviderSettings = {\n\t\t\t\tprovider: provider,\n\t\t\t\tsupermemoryApiKey: supermemory_api_key,\n\t\t\t\tapiKey: this.config.apiKey,\n\t\t\t\tmodelType: this.config.modelType,\n\t\t\t};\n\n\t\t\tconst supermemoryConfig: SupermemoryConfigSettings = {\n\t\t\t\tsupermemoryApiKey: supermemory_api_key,\n\t\t\t\t...this.config.supermemoryConfig,\n\t\t\t\t...this.settings,\n\t\t\t};\n\n\t\t\tconst selector = new SupermemoryClassSelector(\n\t\t\t\tthis.modelId,\n\t\t\t\tsettings,\n\t\t\t\tthis.provider_config,\n\t\t\t);\n\n\t\t\tconst messagesPrompts = options.prompt;\n\n\t\t\t// Process memories and update prompts\n\t\t\tconst { memories, messagesPrompts: updatedPrompts } =\n\t\t\t\tawait this.processMemories(messagesPrompts, supermemoryConfig);\n\n\t\t\tconst model = selector.createProvider();\n\n\t\t\tconst streamResponse = await model.doStream({\n\t\t\t\t...options,\n\t\t\t\tprompt: updatedPrompts,\n\t\t\t});\n\n\t\t\t// If there are no memories, return the original stream\n\t\t\tif (!memories || memories?.length === 0) {\n\t\t\t\treturn streamResponse;\n\t\t\t}\n\n\t\t\t// Create a new stream that includes memory sources\n\t\t\tconst originalStream = streamResponse.stream;\n\n\t\t\t// Create a transform stream that adds memory sources at the beginning\n\t\t\tconst transformStream = new TransformStream({\n\t\t\t\tstart(controller) {\n\t\t\t\t\t// Add source chunks for each memory at the beginning\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (Array.isArray(memories) && memories?.length > 0) {\n\t\t\t\t\t\t\t// Create a single source that contains all memories\n\t\t\t\t\t\t\tcontroller.enqueue({\n\t\t\t\t\t\t\t\ttype: \"source\",\n\t\t\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\t\t\ttitle: \"Supermemory Memories\",\n\t\t\t\t\t\t\t\t\tsourceType: \"url\",\n\t\t\t\t\t\t\t\t\tid: generateRandomId(),\n\t\t\t\t\t\t\t\t\turl: \"https://app.supermemory.ai\",\n\t\t\t\t\t\t\t\t\tproviderMetadata: {\n\t\t\t\t\t\t\t\t\t\tsupermemory: {\n\t\t\t\t\t\t\t\t\t\t\tmemories,\n\t\t\t\t\t\t\t\t\t\t\tmemoriesText: memories\n\t\t\t\t\t\t\t\t\t\t\t\t.map((memory: MemoryResult) => memory.memory)\n\t\t\t\t\t\t\t\t\t\t\t\t.join(\"\\n\\n\"),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// Also add individual memory sources for more detailed information\n\t\t\t\t\t\t\tfor (const memory of memories) {\n\t\t\t\t\t\t\t\tcontroller.enqueue({\n\t\t\t\t\t\t\t\t\ttype: \"source\",\n\t\t\t\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\t\t\t\ttitle: memory.title || \"Memory\",\n\t\t\t\t\t\t\t\t\t\tsourceType: \"url\",\n\t\t\t\t\t\t\t\t\t\tid: generateRandomId(),\n\t\t\t\t\t\t\t\t\t\turl: \"https://app.supermemory.ai\",\n\t\t\t\t\t\t\t\t\t\tproviderMetadata: {\n\t\t\t\t\t\t\t\t\t\t\tsupermemory: {\n\t\t\t\t\t\t\t\t\t\t\t\tmemory,\n\t\t\t\t\t\t\t\t\t\t\t\tmemoryText: memory.memory,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(\"Error adding memory sources:\", error);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\ttransform(chunk, controller) {\n\t\t\t\t\t// Pass through all chunks from the original stream\n\t\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\t// Pipe the original stream through our transform stream\n\t\t\tconst enhancedStream = originalStream.pipeThrough(transformStream);\n\n\t\t\t// Return a new stream response with our enhanced stream\n\t\t\treturn {\n\t\t\t\tstream: enhancedStream,\n\t\t\t\trawCall: streamResponse.rawCall,\n\t\t\t\trawResponse: streamResponse.rawResponse,\n\t\t\t\trequest: streamResponse.request,\n\t\t\t\twarnings: streamResponse.warnings,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error in doStream:\", error);\n\t\t\tthrow new Error(\"Streaming failed or method not implemented.\");\n\t\t}\n\t}\n}\n","import type { LanguageModelV1, ProviderV1 } from \"@ai-sdk/provider\";\nimport { loadApiKey, withoutTrailingSlash } from \"@ai-sdk/provider-utils\";\nimport type {\n\tSupermemoryChatModelId,\n\tSupermemoryChatSettings,\n\tSupermemoryConfig,\n} from \"./supermemory-types\";\nimport type { OpenAIProviderSettings } from \"@ai-sdk/openai\";\nimport { SupermemoryGenericLanguageModel } from \"./supermemory-generic-language-model\";\nimport type { OpenAIChatSettings } from \"@ai-sdk/openai/internal\";\nimport type { AnthropicMessagesSettings } from \"@ai-sdk/anthropic/internal\";\nimport type { AnthropicProviderSettings } from \"@ai-sdk/anthropic\";\nimport type { CohereProviderSettings } from \"@ai-sdk/cohere\";\nimport type { GroqProviderSettings } from \"@ai-sdk/groq\";\n\nexport interface SupermemoryProvider extends ProviderV1 {\n\t(\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings?: SupermemoryChatSettings,\n\t): LanguageModelV1;\n\n\tchat(\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings?: SupermemoryChatSettings,\n\t): LanguageModelV1;\n\tcompletion(\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings?: SupermemoryChatSettings,\n\t): LanguageModelV1;\n\n\tlanguageModel(\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings?: SupermemoryChatSettings,\n\t): LanguageModelV1;\n}\n\nexport interface SupermemoryProviderSettings\n\textends OpenAIChatSettings,\n\t\tAnthropicMessagesSettings {\n\tbaseURL?: string;\n\t/**\n\t * Custom fetch implementation. You can use it as a middleware to intercept\n\t * requests or to provide a custom fetch implementation for e.g. testing\n\t */\n\tfetch?: typeof fetch;\n\t/**\n\t * @internal\n\t */\n\tgenerateId?: () => string;\n\t/**\n\t * Custom headers to include in the requests.\n\t */\n\theaders?: Record<string, string>;\n\tname?: string;\n\tsupermemoryApiKey?: string;\n\tapiKey?: string;\n\tprovider?: string;\n\tmodelType?: \"completion\" | \"chat\";\n\tsupermemoryConfig?: SupermemoryConfig;\n\n\t/**\n\t * The configuration for the provider.\n\t */\n\tconfig?:\n\t\t| OpenAIProviderSettings\n\t\t| AnthropicProviderSettings\n\t\t| CohereProviderSettings\n\t\t| GroqProviderSettings;\n}\n\nexport function createSupermemory(\n\toptions: SupermemoryProviderSettings = {\n\t\tprovider: \"openai\",\n\t},\n): SupermemoryProvider {\n\tconst baseURL =\n\t\twithoutTrailingSlash(options.baseURL) ?? \"http://api.openai.com\";\n\tconst getHeaders = () => ({\n\t\t...options.headers,\n\t});\n\n\tconst createGenericModel = (\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings: SupermemoryChatSettings = {},\n\t) =>\n\t\tnew SupermemoryGenericLanguageModel(\n\t\t\tmodelId,\n\t\t\tsettings,\n\t\t\t{\n\t\t\t\tbaseURL,\n\t\t\t\tfetch: options.fetch,\n\t\t\t\theaders: getHeaders(),\n\t\t\t\tprovider: options.provider || \"openai\",\n\t\t\t\tname: options.name,\n\t\t\t\tsupermemoryApiKey: options.supermemoryApiKey,\n\t\t\t\tapiKey: options.apiKey,\n\t\t\t\tsupermemoryConfig: options.supermemoryConfig,\n\t\t\t},\n\t\t\toptions.config,\n\t\t);\n\n\tconst createCompletionModel = (\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings: SupermemoryChatSettings = {},\n\t) =>\n\t\tnew SupermemoryGenericLanguageModel(\n\t\t\tmodelId,\n\t\t\tsettings,\n\t\t\t{\n\t\t\t\tbaseURL,\n\t\t\t\tfetch: options.fetch,\n\t\t\t\theaders: getHeaders(),\n\t\t\t\tprovider: options.provider || \"openai\",\n\t\t\t\tname: options.name,\n\t\t\t\tsupermemoryApiKey: options.supermemoryApiKey,\n\t\t\t\tapiKey: options.apiKey,\n\t\t\t\tsupermemoryConfig: options.supermemoryConfig,\n\t\t\t\tmodelType: \"completion\",\n\t\t\t},\n\t\t\toptions.config,\n\t\t);\n\n\tconst createChatModel = (\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings: SupermemoryChatSettings = {},\n\t) =>\n\t\tnew SupermemoryGenericLanguageModel(\n\t\t\tmodelId,\n\t\t\tsettings,\n\t\t\t{\n\t\t\t\tbaseURL,\n\t\t\t\tfetch: options.fetch,\n\t\t\t\theaders: getHeaders(),\n\t\t\t\tprovider: options.provider || \"openai\",\n\t\t\t\tname: options.name,\n\t\t\t\tsupermemoryApiKey: options.supermemoryApiKey,\n\t\t\t\tapiKey: options.apiKey,\n\t\t\t\tsupermemoryConfig: options.supermemoryConfig,\n\t\t\t\tmodelType: \"completion\",\n\t\t\t},\n\t\t\toptions.config,\n\t\t);\n\n\tconst provider = function (\n\t\tmodelId: SupermemoryChatModelId,\n\t\tsettings: SupermemoryChatSettings = {},\n\t) {\n\t\tif (new.target) {\n\t\t\tthrow new Error(\n\t\t\t\t\"The Supermemory model function cannot be called with the new keyword.\",\n\t\t\t);\n\t\t}\n\n\t\treturn createGenericModel(modelId, settings);\n\t};\n\n\tprovider.languageModel = createGenericModel;\n\tprovider.completion = createCompletionModel;\n\tprovider.chat = createChatModel;\n\n\treturn provider as unknown as SupermemoryProvider;\n}\n\nexport const supermemory = createSupermemory();\n"],"mappings":";AAAA,SAAS,4BAA4B;;;ACMrC,SAAS,oBAAiD;AAC1D,SAAsC,oBAAoB;AAC1D;AAAA,EAEC;AAAA,OACM;AACP,SAAS,kBAA6C;AA8CtD,IAAM,6BAAN,MAA4D;AAAA,EAClD,uBAAuB;AAAA,EACvB,8BAA8B;AAAA,EAC9B,oBAAoB;AAAA,EACpB;AAAA,EACA;AAAA,EAET;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YACC,SACA,QACA,sBACC;AACD,SAAK,WAAW,OAAO,YAAY;AACnC,YAAQ,OAAO,UAAU;AAAA,MACxB,KAAK,UAAU;AACd,cAAM,iBAAiB,aAAa;AAAA,UACnC,QAAQ,QAAQ;AAAA,UAChB,GAAI;AAAA,QACL,CAAC;AACD,YAAI,QAAQ,cAAc,cAAc;AACvC,eAA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