export type LoggerBackend = { info(msg: string, ...args: unknown[]): void warn(msg: string, ...args: unknown[]): void error(msg: string, ...args: unknown[]): void debug?(msg: string, ...args: unknown[]): void } const NOOP_LOGGER: LoggerBackend = { info() {}, warn() {}, error() {}, debug() {}, } let _backend: LoggerBackend = NOOP_LOGGER let _debug = false export function initLogger(backend: LoggerBackend, debug: boolean): void { _backend = backend _debug = debug } export const log = { info(msg: string, ...args: unknown[]): void { _backend.info(`supermemory: ${msg}`, ...args) }, warn(msg: string, ...args: unknown[]): void { _backend.warn(`supermemory: ${msg}`, ...args) }, error(msg: string, err?: unknown): void { const detail = err instanceof Error ? err.message : err ? String(err) : "" _backend.error(`supermemory: ${msg}${detail ? ` — ${detail}` : ""}`) }, debug(msg: string, ...args: unknown[]): void { if (!_debug) return const fn = _backend.debug ?? _backend.info fn(`supermemory [debug]: ${msg}`, ...args) }, debugRequest(method: string, params: Record): void { if (!_debug) return const fn = _backend.debug ?? _backend.info fn(`supermemory [debug] → ${method}`, JSON.stringify(params, null, 2)) }, debugResponse(method: string, data: unknown): void { if (!_debug) return const fn = _backend.debug ?? _backend.info fn(`supermemory [debug] ← ${method}`, JSON.stringify(data, null, 2)) }, }