Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@supermemory/tools",
"type": "module",
"version": "2.2.0",
"version": "2.3.0",
"description": "Memory tools for AI SDK, OpenAI, Voltagent and Mastra with supermemory",
"scripts": {
"build": "tsdown",
"dev": "tsdown --watch --ignore-watch .turbo",
"check-types": "tsc --noEmit",
"test": "vitest --testTimeout 100000",
"test:unit": "vitest run --testTimeout 100000 src/tools-shared.test.ts src/tool-operations.test.ts src/claude-memory.test.ts test/with-supermemory/unit.test.ts test/with-supermemory/conversation-conversion.test.ts test/mastra/unit.test.ts",
"test:unit": "vitest run --testTimeout 100000 src/tools-shared.test.ts src/tool-operations.test.ts src/claude-memory.test.ts test/with-supermemory/unit.test.ts test/with-supermemory/conversation-conversion.test.ts test/openai-middleware.unit.test.ts test/mastra/unit.test.ts test/voltagent.unit.test.ts",
"test:watch": "vitest --watch --testTimeout 100000"
},
"dependencies": {
Expand Down
10 changes: 8 additions & 2 deletions packages/tools/src/mastra/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MemoryCache,
buildMemoriesText,
extractQueryText,
wrapMemoryContext,
type Logger,
type MemoryMode,
type PromptTemplate,
Expand Down Expand Up @@ -138,6 +139,11 @@ export class SupermemoryInputProcessor implements Processor {
async processInput(args: ProcessInputArgs): Promise<ProcessInputResult> {
const { messages, messageList, requestContext } = args

// Mastra owns tagged system messages by tag. Clear the previous value on
// every invocation so empty, skipped, cached, fresh, and error paths cannot
// leave stale Supermemory context behind.
messageList.clearSystemMessages("supermemory")

try {
const queryText = extractQueryText(
messages as unknown as Array<{
Expand All @@ -163,7 +169,7 @@ export class SupermemoryInputProcessor implements Processor {
const cachedMemories = this.ctx.memoryCache.get(turnKey)
if (cachedMemories) {
this.ctx.logger.debug("Using cached memories", { turnKey })
messageList.addSystem(cachedMemories, "supermemory")
messageList.addSystem(wrapMemoryContext(cachedMemories), "supermemory")
return messageList
}

Expand All @@ -185,7 +191,7 @@ export class SupermemoryInputProcessor implements Processor {

if (memories) {
this.ctx.memoryCache.set(turnKey, memories)
messageList.addSystem(memories, "supermemory")
messageList.addSystem(wrapMemoryContext(memories), "supermemory")
this.ctx.logger.debug("Injected memories into system prompt", {
length: memories.length,
})
Expand Down
Loading
Loading