supermemory/packages/tools/src/shared/logger.ts
nexxeln 9553434c9a mastra integration (#717)
adds withSupermemory wrapper and input/output processors for
mastra agents:

- input processor fetches and injects memories into system prompt
before llm calls
- output processor saves conversations to supermemory after
responses
- supports profile, query, and full memory search modes
- includes custom prompt templates and requestcontext support

const agent = new Agent(withSupermemory(
{ id: "my-assistant", model: openai("gpt-4o"), instructions:
"..." },
"user-123",
{ mode: "full", addMemory: "always", threadId: "conv-456" }
))

includes docs as well

this pr also reworks how the tools package works into shared modules
2026-02-03 00:43:08 +00:00

45 lines
1.1 KiB
TypeScript

import type { Logger } from "./types"
/**
* Creates a logger instance that outputs to console when verbose mode is enabled.
*
* @param verbose - When true, logs are written to console; when false, logs are silently ignored
* @returns Logger instance with debug, info, warn, and error methods
*/
export const createLogger = (verbose: boolean): Logger => {
if (!verbose) {
return {
debug: () => {},
info: () => {},
warn: () => {},
error: () => {},
}
}
return {
debug: (message: string, data?: unknown) => {
console.log(
`[supermemory] ${message}`,
data ? JSON.stringify(data, null, 2) : "",
)
},
info: (message: string, data?: unknown) => {
console.log(
`[supermemory] ${message}`,
data ? JSON.stringify(data, null, 2) : "",
)
},
warn: (message: string, data?: unknown) => {
console.warn(
`[supermemory] ${message}`,
data ? JSON.stringify(data, null, 2) : "",
)
},
error: (message: string, data?: unknown) => {
console.error(
`[supermemory] ${message}`,
data ? JSON.stringify(data, null, 2) : "",
)
},
}
}