mirror of
https://github.com/TencentCloud/TencentDB-Agent-Memory
synced 2026-07-10 12:34:27 +00:00
refactor: unify duplicate Logger interfaces into single canonical type (#14)
* refactor: unify duplicate Logger interfaces into single canonical type
23 files had local Logger/StoreLogger/PluginLogger/PipelineLogger/RunnerLogger/ExtractorLogger/TriggerLogger
interface definitions with identical shapes ({debug?, info, warn, error}).
Replace all with imports from the canonical `Logger` in `src/core/types.ts`:
- 17 files: local `interface Logger` → `import type { Logger }`
- 6 files: named variants (StoreLogger, PluginLogger, etc.) → `type X = Logger` alias
Two intentionally different interfaces are preserved:
- `CheckpointLogger` (only info + optional warn) — different contract
- `ensure-hook-policy.ts` Logger (no error) — different contract
Net: -120 lines, zero behavioral change.
Signed-off-by: yuanrengu <heyonggang0811@126.com>
* docs: update Logger JSDoc to reflect canonical relationship
StoreLogger, PluginLogger, etc. are now type aliases of Logger, not the
other way around. Update the comment to clarify this inverted relationship.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Signed-off-by: yuanrengu <heyonggang0811@126.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import crypto from "node:crypto";
|
||||
import { sanitizeText, stripCodeBlocks, shouldCaptureL0 } from "../../utils/sanitize.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
@@ -63,13 +64,6 @@ export interface L0ConversationRecord {
|
||||
messages: ConversationMessage[];
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
const TAG = "[memory-tdai][l0]";
|
||||
|
||||
// ============================
|
||||
|
||||
@@ -19,14 +19,9 @@ import type { ConversationMessage } from "../conversation/l0-recorder.js";
|
||||
import type { IMemoryStore, L0Record } from "../store/types.js";
|
||||
import type { EmbeddingService } from "../store/embedding.js";
|
||||
|
||||
const TAG = "[memory-tdai] [capture]";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
const TAG = "[memory-tdai] [capture]";
|
||||
|
||||
export interface AutoCaptureResult {
|
||||
/** Whether the scheduler was notified (conversation count incremented) */
|
||||
|
||||
@@ -20,6 +20,7 @@ import type { IMemoryStore, L1SearchResult, L1FtsResult } from "../store/types.j
|
||||
import { buildFtsQuery } from "../store/sqlite.js";
|
||||
import type { EmbeddingService, EmbeddingCallOptions } from "../store/embedding.js";
|
||||
import { sanitizeText } from "../../utils/sanitize.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
const TAG = "[memory-tdai] [recall]";
|
||||
const RECALL_TRUNCATION_SUFFIX = "…(已截断;可用 tdai_memory_search 或 tdai_conversation_search 查看详情)";
|
||||
@@ -45,13 +46,6 @@ const MEMORY_TOOLS_GUIDE = `<memory-tools-guide>
|
||||
- 若 3 次搜索后仍无结果,说明该信息不在记忆中,请直接根据已有信息回复用户,不要继续搜索。
|
||||
</memory-tools-guide>`
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
/** A single recalled L1 memory with its search score and type. */
|
||||
export interface RecalledMemory {
|
||||
content: string;
|
||||
|
||||
@@ -13,17 +13,10 @@ import { buildPersonaPrompt } from "../prompts/persona-generation.js";
|
||||
import { BackupManager } from "../../utils/backup.js";
|
||||
import { escapeXmlTags } from "../../utils/sanitize.js";
|
||||
import { report } from "../report/reporter.js";
|
||||
import type { LLMRunner } from "../types.js";
|
||||
import type { LLMRunner, Logger } from "../types.js";
|
||||
|
||||
const TAG = "[memory-tdai] [persona]";
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
export class PersonaGenerator {
|
||||
private dataDir: string;
|
||||
private runner: LLMRunner;
|
||||
|
||||
@@ -8,14 +8,11 @@ import path from "node:path";
|
||||
import { CheckpointManager } from "../../utils/checkpoint.js";
|
||||
import { stripSceneNavigation } from "../scene/scene-navigation.js";
|
||||
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
const TAG = "[memory-tdai] [trigger]";
|
||||
|
||||
interface TriggerLogger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
type TriggerLogger = Logger;
|
||||
|
||||
export interface TriggerResult {
|
||||
should: boolean;
|
||||
|
||||
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import type { IMemoryStore, ProfileRecord, ProfileSyncRecord } from "../store/types.js";
|
||||
import { readSceneIndex, syncSceneIndex } from "../scene/scene-index.js";
|
||||
import { generateSceneNavigation, stripSceneNavigation } from "../scene/scene-navigation.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
const PROFILE_SCOPE = "global";
|
||||
|
||||
@@ -13,13 +14,6 @@ function isRenameRaceError(err: unknown): boolean {
|
||||
return code === "ENOTEMPTY" || code === "EEXIST";
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
export interface ProfileBaseline {
|
||||
version: number;
|
||||
contentMd5: string;
|
||||
|
||||
@@ -19,14 +19,7 @@ import { sanitizeJsonForParse } from "../../utils/sanitize.js";
|
||||
import type { IMemoryStore } from "../store/types.js";
|
||||
import { buildFtsQuery } from "../store/sqlite.js";
|
||||
import type { EmbeddingService } from "../store/embedding.js";
|
||||
import type { LLMRunner } from "../types.js";
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
import type { LLMRunner, Logger } from "../types.js";
|
||||
|
||||
const TAG = "[memory-tdai][l1-dedup]";
|
||||
|
||||
|
||||
@@ -22,14 +22,7 @@ import { sanitizeJsonForParse, shouldExtractL1 } from "../../utils/sanitize.js";
|
||||
import type { IMemoryStore } from "../store/types.js";
|
||||
import type { EmbeddingService } from "../store/embedding.js";
|
||||
import { report } from "../report/reporter.js";
|
||||
import type { LLMRunner } from "../types.js";
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
import type { LLMRunner, Logger } from "../types.js";
|
||||
|
||||
const TAG = "[memory-tdai][l1-extractor]";
|
||||
|
||||
|
||||
@@ -19,13 +19,7 @@ import type { IMemoryStore, L1RecordRow, L1QueryFilter } from "../store/types.js
|
||||
// Re-export types that readers need
|
||||
export type { MemoryRecord, MemoryType, EpisodicMetadata } from "./l1-writer.js";
|
||||
export type { L1QueryFilter } from "../store/types.js";
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
const TAG = "[memory-tdai] [l1-reader]";
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import path from "node:path";
|
||||
import crypto from "node:crypto";
|
||||
import type { IMemoryStore } from "../store/types.js";
|
||||
import type { EmbeddingService } from "../store/embedding.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
@@ -110,13 +111,6 @@ export interface DedupDecision {
|
||||
merged_timestamps?: string[];
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
const TAG = "[memory-tdai][l1-writer]";
|
||||
|
||||
// ============================
|
||||
|
||||
@@ -28,16 +28,11 @@ import { generateSceneNavigation, stripSceneNavigation } from "../scene/scene-na
|
||||
import { normalizeSceneFilenames } from "./filename-normalizer.js";
|
||||
import { buildSceneExtractionPrompt } from "../prompts/scene-extraction.js";
|
||||
import { report } from "../report/reporter.js";
|
||||
import type { LLMRunner } from "../types.js";
|
||||
import type { LLMRunner, Logger } from "../types.js";
|
||||
|
||||
const TAG = "[memory-tdai] [extractor]";
|
||||
|
||||
interface ExtractorLogger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
type ExtractorLogger = Logger;
|
||||
|
||||
export interface ExtractionResult {
|
||||
memoriesProcessed: number;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
* check health to dynamically downgrade to pure semantic search.
|
||||
*/
|
||||
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
// ============================
|
||||
@@ -20,13 +22,6 @@
|
||||
/** Sparse vector: array of [token_hash, weight] pairs. */
|
||||
export type SparseVector = Array<[number, number]>;
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
export interface BM25ClientConfig {
|
||||
/** Sidecar service URL (default: "http://127.0.0.1:8084") */
|
||||
serviceUrl: string;
|
||||
|
||||
@@ -11,16 +11,10 @@
|
||||
|
||||
import { BM25Encoder } from "@tencentdb-agent-memory/tcvdb-text";
|
||||
import type { SparseVector } from "@tencentdb-agent-memory/tcvdb-text";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
export type { SparseVector };
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
export interface BM25LocalConfig {
|
||||
/** Whether BM25 sparse encoding is enabled (default: true) */
|
||||
enabled: boolean;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
* - Throws on failure; callers decide fallback strategy.
|
||||
*/
|
||||
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
// ============================
|
||||
@@ -104,17 +106,6 @@ export class EmbeddingNotReadyError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Logger interface
|
||||
// ============================
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
const TAG = "[memory-tdai][embedding]";
|
||||
|
||||
// ============================
|
||||
|
||||
@@ -33,6 +33,7 @@ import type {
|
||||
L0SearchResult,
|
||||
L0FtsResult,
|
||||
} from "./types.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
@@ -106,13 +107,6 @@ export interface L1QueryFilter {
|
||||
updatedAfter?: string;
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
const TAG = "[memory-tdai][sqlite]";
|
||||
|
||||
/** Persisted metadata about the embedding provider used to generate stored vectors. */
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
import type { MemoryRecord } from "../record/l1-writer.js";
|
||||
import type { EmbeddingProviderInfo } from "./embedding.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// Re-export so consumers can import everything from types.ts
|
||||
export type { MemoryRecord, EmbeddingProviderInfo };
|
||||
@@ -26,12 +27,7 @@ export type { MemoryRecord, EmbeddingProviderInfo };
|
||||
// ============================
|
||||
|
||||
/** Minimal logger interface accepted by store implementations. */
|
||||
export interface StoreLogger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
export type StoreLogger = Logger;
|
||||
|
||||
// ============================
|
||||
// L1 Types (Structured Memories)
|
||||
|
||||
@@ -13,18 +13,12 @@
|
||||
import type { IMemoryStore, L0SearchResult } from "../store/types.js";
|
||||
import { buildFtsQuery } from "../store/sqlite.js";
|
||||
import type { EmbeddingService } from "../store/embedding.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
// ============================
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
export interface ConversationSearchResultItem {
|
||||
id: string;
|
||||
session_key: string;
|
||||
|
||||
@@ -13,18 +13,12 @@
|
||||
import type { IMemoryStore, L1SearchResult } from "../store/types.js";
|
||||
import { buildFtsQuery } from "../store/sqlite.js";
|
||||
import type { EmbeddingService } from "../store/embedding.js";
|
||||
import type { Logger } from "../types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
// ============================
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
export interface MemorySearchResultItem {
|
||||
id: string;
|
||||
content: string;
|
||||
|
||||
+3
-3
@@ -15,10 +15,10 @@
|
||||
// ============================
|
||||
|
||||
/**
|
||||
* Minimal logger interface used throughout TDAI Core.
|
||||
* Canonical logger interface used across all TDAI modules.
|
||||
*
|
||||
* Matches the existing `StoreLogger` and `RunnerLogger` interfaces
|
||||
* already used in the codebase — no migration needed for existing callers.
|
||||
* Named variants (StoreLogger, PluginLogger, etc.) are type aliases
|
||||
* of this interface, kept for backward compatibility.
|
||||
*/
|
||||
export interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Ported from context-offload-plugin with updated runtime defaults.
|
||||
*/
|
||||
|
||||
import type { Logger } from "../core/types.js";
|
||||
|
||||
// ============================
|
||||
// Data types
|
||||
// ============================
|
||||
@@ -212,12 +214,7 @@ export interface PluginConfig {
|
||||
// ============================
|
||||
|
||||
/** Logger interface used by offload plugin components */
|
||||
export interface PluginLogger {
|
||||
info: (msg: string) => void;
|
||||
warn: (msg: string) => void;
|
||||
error: (msg: string) => void;
|
||||
debug?: (msg: string) => void;
|
||||
}
|
||||
export type PluginLogger = Logger;
|
||||
|
||||
// ============================
|
||||
// Plugin defaults
|
||||
|
||||
@@ -17,6 +17,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
|
||||
import { getEnv } from "./env.js";
|
||||
import { report } from "../core/report/reporter.js";
|
||||
import type { Logger } from "../core/types.js";
|
||||
|
||||
/**
|
||||
* Resolve a preferred temporary directory for memory-tdai operations.
|
||||
@@ -49,12 +50,7 @@ function resolveOpenClawTmpDir(): string {
|
||||
|
||||
const TAG = "[memory-tdai] [runner]";
|
||||
|
||||
interface RunnerLogger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
type RunnerLogger = Logger;
|
||||
|
||||
// Dynamic import type — runEmbeddedPiAgent is an internal API
|
||||
// Prefer the public plugin runtime signature so host-injected runtimes stay assignable.
|
||||
|
||||
@@ -3,13 +3,7 @@ import path from "node:path";
|
||||
|
||||
import type { IMemoryStore } from "../core/store/types.js";
|
||||
import { ManagedTimer } from "./managed-timer.js";
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
import type { Logger } from "../core/types.js";
|
||||
|
||||
export interface MemoryCleanerOptions {
|
||||
baseDir: string;
|
||||
|
||||
@@ -36,6 +36,7 @@ import { SceneExtractor } from "../core/scene/scene-extractor.js";
|
||||
import { PersonaTrigger } from "../core/persona/persona-trigger.js";
|
||||
import { PersonaGenerator } from "../core/persona/persona-generator.js";
|
||||
import { pullProfilesToLocal, syncLocalProfilesToStore } from "../core/profile/profile-sync.js";
|
||||
import type { Logger } from "../core/types.js";
|
||||
|
||||
const TAG = "[memory-tdai] [pipeline-factory]";
|
||||
|
||||
@@ -47,12 +48,8 @@ function supportsProfileSyncWrite(store?: IMemoryStore): boolean {
|
||||
// Logger interface
|
||||
// ============================
|
||||
|
||||
export interface PipelineLogger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
/** @deprecated Use `Logger` from `../core/types.js` directly. */
|
||||
export type PipelineLogger = Logger;
|
||||
|
||||
// ============================
|
||||
// Factory options
|
||||
|
||||
@@ -81,18 +81,12 @@ import { SessionFilter } from "./session-filter.js";
|
||||
import { ManagedTimer } from "./managed-timer.js";
|
||||
import { SerialQueue } from "./serial-queue.js";
|
||||
import { report } from "../core/report/reporter.js";
|
||||
import type { Logger } from "../core/types.js";
|
||||
|
||||
// ============================
|
||||
// Types
|
||||
// ============================
|
||||
|
||||
interface Logger {
|
||||
debug?: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
}
|
||||
|
||||
/** A single captured message ready for L1 processing. */
|
||||
export interface CapturedMessage {
|
||||
role: "user" | "assistant" | "tool";
|
||||
|
||||
Reference in New Issue
Block a user