From 03c38a1d8a4fa383eb4df2f0375a20bb356a9826 Mon Sep 17 00:00:00 2001 From: Sreeram Sreedhar Date: Mon, 20 Apr 2026 13:52:08 -0700 Subject: [PATCH] fixed bugs --- apps/docs/integrations/convex.mdx | 7 +------ packages/tools/src/convex-component/README.md | 8 ++------ .../src/convex-component/src/client/index.ts | 7 ------- .../convex-component/src/component/install.ts | 2 +- .../convex-component/src/component/mutations.ts | 12 ++++++++---- .../convex-component/src/component/queries.ts | 5 +++-- .../convex-component/src/component/schema.ts | 1 + .../src/convex-component/src/react/index.tsx | 17 ----------------- 8 files changed, 16 insertions(+), 43 deletions(-) diff --git a/apps/docs/integrations/convex.mdx b/apps/docs/integrations/convex.mdx index a616e4d9..556b2475 100644 --- a/apps/docs/integrations/convex.mdx +++ b/apps/docs/integrations/convex.mdx @@ -35,14 +35,10 @@ export default app; ### 2. Set API Key -Get your API key from [console.supermemory.ai](https://console.supermemory.ai): +Get your API key from [console.supermemory.ai](https://console.supermemory.ai) and set it as a Convex environment variable: ```bash -# Environment variable (recommended) npx convex env set SUPERMEMORY_API_KEY your-api-key - -# Or set it programmatically -npx convex run supermemory:mutations.setApiKey '{"apiKey": "your-api-key"}' ``` ### 3. Use in Your App @@ -222,7 +218,6 @@ const client = createSupermemoryClient(convex); | `client.getApiStats(args?)` | Get aggregated statistics | | `client.searchCached(args)` | Local text search in Convex cache | | `client.cleanCache()` | Remove expired cache entries | -| `client.setApiKey(key)` | Configure API key | ## AI SDK Integration diff --git a/packages/tools/src/convex-component/README.md b/packages/tools/src/convex-component/README.md index e734e4ac..b8c9e323 100644 --- a/packages/tools/src/convex-component/README.md +++ b/packages/tools/src/convex-component/README.md @@ -44,14 +44,10 @@ export default app; ### 2. Set API Key -Get your API key from [Supermemory Dashboard](https://supermemory.ai/dashboard) and set it: +Get your API key from [console.supermemory.ai](https://console.supermemory.ai) and set it as a Convex environment variable: ```bash -# Environment variable (recommended) -export SUPERMEMORY_API_KEY="your-api-key" - -# Or set it programmatically -npx convex run supermemory:mutations.setApiKey '{"apiKey": "your-api-key"}' +npx convex env set SUPERMEMORY_API_KEY your-api-key ``` ### 3. Use in Your App diff --git a/packages/tools/src/convex-component/src/client/index.ts b/packages/tools/src/convex-component/src/client/index.ts index 5e05759f..b85cd224 100644 --- a/packages/tools/src/convex-component/src/client/index.ts +++ b/packages/tools/src/convex-component/src/client/index.ts @@ -233,13 +233,6 @@ export function createSupermemoryClient( return await client.mutation(mutation("updateDocumentStatus"), args); }, - /** - * Set Supermemory API key - * Configure the API key for Supermemory calls - */ - setApiKey: async (apiKey: string) => { - return await client.mutation(mutation("setApiKey"), { apiKey }); - }, }; } diff --git a/packages/tools/src/convex-component/src/component/install.ts b/packages/tools/src/convex-component/src/component/install.ts index 301f046f..2ca00e5b 100644 --- a/packages/tools/src/convex-component/src/component/install.ts +++ b/packages/tools/src/convex-component/src/component/install.ts @@ -7,4 +7,4 @@ export { add, search, profile } from "./actions"; export { getApiStats, getApiLogs, listDocuments, getDocumentByCustomId, listMemories, getChatSessions, getChatSession, getAnalytics, getDashboardOverview } from "./queries"; -export { cleanExpiredCache, setApiKey, updateDocumentStatus, trackChatMessage } from "./mutations"; +export { cleanExpiredCache, updateDocumentStatus, trackChatMessage } from "./mutations"; diff --git a/packages/tools/src/convex-component/src/component/mutations.ts b/packages/tools/src/convex-component/src/component/mutations.ts index 3d067431..6440cd94 100644 --- a/packages/tools/src/convex-component/src/component/mutations.ts +++ b/packages/tools/src/convex-component/src/component/mutations.ts @@ -254,8 +254,11 @@ export const updateDocumentStatus = mutation({ /** * Initialize or update API key * Stores the Supermemory API key in Convex + * + * SECURITY NOTE: This is an internal mutation. Use `npx convex env set SUPERMEMORY_API_KEY` + * for production, or call this from a server-side admin endpoint with proper auth checks. */ -export const setApiKey = mutation({ +export const setApiKey = internalMutation({ args: { apiKey: v.string(), }, @@ -420,11 +423,12 @@ export const updateAnalytics = internalMutation({ if (args.incrementSearches) { updates.totalSearches = existing.totalSearches + args.incrementSearches; } - if (args.responseTime) { - // Calculate new average + if (args.incrementSearches && args.responseTime) { + // Only update average when we're also incrementing searches const totalTime = existing.avgResponseTime * existing.totalSearches; const newTotal = totalTime + args.responseTime; - updates.avgResponseTime = newTotal / (existing.totalSearches + 1); + const newSearchCount = existing.totalSearches + args.incrementSearches; + updates.avgResponseTime = newTotal / newSearchCount; } await ctx.db.patch(existing._id, updates); diff --git a/packages/tools/src/convex-component/src/component/queries.ts b/packages/tools/src/convex-component/src/component/queries.ts index e976c5cc..2099e107 100644 --- a/packages/tools/src/convex-component/src/component/queries.ts +++ b/packages/tools/src/convex-component/src/component/queries.ts @@ -221,9 +221,10 @@ export const listMemories = query({ if (args.source) { return await ctx.db .query("memories") - .withIndex("by_source", (q) => q.eq("source", args.source)) + .withIndex("by_source_container", (q) => + q.eq("source", args.source).eq("containerTag", args.containerTag) + ) .order("desc") - .filter((q) => q.eq(q.field("containerTag"), args.containerTag)) .take(limit); } diff --git a/packages/tools/src/convex-component/src/component/schema.ts b/packages/tools/src/convex-component/src/component/schema.ts index 0b0fe5d5..830e619c 100644 --- a/packages/tools/src/convex-component/src/component/schema.ts +++ b/packages/tools/src/convex-component/src/component/schema.ts @@ -111,6 +111,7 @@ export default defineSchema({ }) .index("by_container", ["containerTag"]) .index("by_source", ["source"]) + .index("by_source_container", ["source", "containerTag"]) .index("by_created", ["createdAt"]), /** diff --git a/packages/tools/src/convex-component/src/react/index.tsx b/packages/tools/src/convex-component/src/react/index.tsx index 03d83962..46865177 100644 --- a/packages/tools/src/convex-component/src/react/index.tsx +++ b/packages/tools/src/convex-component/src/react/index.tsx @@ -325,23 +325,6 @@ export function useUpdateDocumentStatus(componentPath: string = "supermemory") { ); } -/** - * Hook to set Supermemory API key - * - * @param componentPath - Path to the component (default: "supermemory") - */ -export function useSetApiKey(componentPath: string = "supermemory") { - const mutation = `${componentPath}:setApiKey` as unknown as FunctionReference<"mutation">; - const setKeyMutation = useMutation(mutation); - - return useCallback( - async (apiKey: string) => { - return await setKeyMutation({ apiKey }); - }, - [setKeyMutation] - ); -} - /** * Hook to list memories for a user *