fixed bugs

This commit is contained in:
Sreeram Sreedhar 2026-04-20 13:52:08 -07:00
parent cdb4c81b85
commit 03c38a1d8a
8 changed files with 16 additions and 43 deletions

View file

@ -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

View file

@ -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

View file

@ -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 });
},
};
}

View file

@ -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";

View file

@ -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);

View file

@ -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);
}

View file

@ -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"]),
/**

View file

@ -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
*