diff options
| author | Arnab Mondal <[email protected]> | 2025-12-30 23:45:10 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-30 10:15:10 -0800 |
| commit | aa5654f084afc9d449b549167082a1fda23d209a (patch) | |
| tree | 13b60291ee346e53a98bcd4ebfd43a632bed94b3 | |
| parent | fix deduplication in python sdk (#626) (diff) | |
| download | supermemory-aa5654f084afc9d449b549167082a1fda23d209a.tar.xz supermemory-aa5654f084afc9d449b549167082a1fda23d209a.zip | |
fix(tools): pass apiKey to profile search instead of using process.env (#634)
| -rw-r--r-- | packages/tools/src/vercel/memory-prompt.ts | 53 | ||||
| -rw-r--r-- | packages/tools/src/vercel/middleware.ts | 1 |
2 files changed, 29 insertions, 25 deletions
diff --git a/packages/tools/src/vercel/memory-prompt.ts b/packages/tools/src/vercel/memory-prompt.ts index da1d74f4..ee7f85a7 100644 --- a/packages/tools/src/vercel/memory-prompt.ts +++ b/packages/tools/src/vercel/memory-prompt.ts @@ -16,22 +16,23 @@ const supermemoryProfileSearch = async ( containerTag: string, queryText: string, baseUrl: string, + apiKey: string, ): Promise<ProfileStructure> => { const payload = queryText ? JSON.stringify({ - q: queryText, - containerTag: containerTag, - }) + q: queryText, + containerTag: containerTag, + }) : JSON.stringify({ - containerTag: containerTag, - }) + containerTag: containerTag, + }) try { const response = await fetch(`${baseUrl}/v4/profile`, { method: "POST", headers: { "Content-Type": "application/json", - Authorization: `Bearer ${process.env.SUPERMEMORY_API_KEY}`, + Authorization: `Bearer ${apiKey}`, }, body: payload, }) @@ -57,7 +58,8 @@ export const addSystemPrompt = async ( containerTag: string, logger: Logger, mode: "profile" | "query" | "full", - baseUrl = "https://api.supermemory.ai", + baseUrl: string, + apiKey: string, ): Promise<LanguageModelCallOptions> => { const systemPromptExists = params.prompt.some( (prompt) => prompt.role === "system", @@ -66,22 +68,23 @@ export const addSystemPrompt = async ( const queryText = mode !== "profile" ? params.prompt - .slice() - .reverse() - .find((prompt: { role: string }) => prompt.role === "user") - ?.content?.filter( - (content: { type: string }) => content.type === "text", - ) - ?.map((content: { type: string; text: string }) => - content.type === "text" ? content.text : "", - ) - ?.join(" ") || "" + .slice() + .reverse() + .find((prompt: { role: string }) => prompt.role === "user") + ?.content?.filter( + (content: { type: string }) => content.type === "text", + ) + ?.map((content: { type: string; text: string }) => + content.type === "text" ? content.text : "", + ) + ?.join(" ") || "" : "" const memoriesResponse = await supermemoryProfileSearch( containerTag, queryText, baseUrl, + apiKey, ) const memoryCountStatic = memoriesResponse.profile.static?.length || 0 @@ -120,18 +123,18 @@ export const addSystemPrompt = async ( const profileData = mode !== "query" ? convertProfileToMarkdown({ - profile: { - static: deduplicated.static, - dynamic: deduplicated.dynamic, - }, - searchResults: { results: [] }, - }) + profile: { + static: deduplicated.static, + dynamic: deduplicated.dynamic, + }, + searchResults: { results: [] }, + }) : "" const searchResultsMemories = mode !== "profile" ? `Search results for user's recent message: \n${deduplicated.searchResults - .map((memory) => `- ${memory}`) - .join("\n")}` + .map((memory) => `- ${memory}`) + .join("\n")}` : "" const memories = diff --git a/packages/tools/src/vercel/middleware.ts b/packages/tools/src/vercel/middleware.ts index a2dd77ee..73adf200 100644 --- a/packages/tools/src/vercel/middleware.ts +++ b/packages/tools/src/vercel/middleware.ts @@ -234,6 +234,7 @@ export const transformParamsWithMemory = async ( ctx.logger, ctx.mode, ctx.normalizedBaseUrl, + ctx.apiKey, ) return transformedParams } |