diff --git a/dist/src/smart-extractor.js b/dist/src/smart-extractor.js index aa0fcb85..43fb9f60 100644 --- a/dist/src/smart-extractor.js +++ b/dist/src/smart-extractor.js @@ -7,7 +7,7 @@ */ import { buildExtractionPrompt, buildDedupPrompt, buildMergePrompt, } from "./extraction-prompts.js"; import { AdmissionController, } from "./admission-control.js"; -import { ALWAYS_MERGE_CATEGORIES, MERGE_SUPPORTED_CATEGORIES, TEMPORAL_VERSIONED_CATEGORIES, normalizeCategory, } from "./memory-categories.js"; +import { ALWAYS_MERGE_CATEGORIES, getStorageCategoryForMemoryCategory, MERGE_SUPPORTED_CATEGORIES, TEMPORAL_VERSIONED_CATEGORIES, normalizeCategory, } from "./memory-categories.js"; import { isMetaFrustrationNoise, isNoise } from "./noise-filter.js"; import { appendRelation, buildSmartMetadata, deriveFactKey, parseSmartMetadata, stringifySmartMetadata, parseSupportInfo, updateSupportStats, } from "./smart-metadata.js"; import { isUserMdExclusiveMemory, } from "./workspace-boundary.js"; @@ -1149,23 +1149,17 @@ export class SmartExtractor { /** * Map 6-category to existing 5-category store type for backward compatibility. */ + /** + * Map a smart register onto its legacy storage category, delegating to the + * shared SMART_TO_STORAGE_CATEGORY constant (memory-categories) so the + * mapping has a single source of truth. Note: "reflection" is a legacy + * storage category minted only by the reflection writer and is deliberately + * absent from this map; smart extraction never produces reflection rows. + * The "other" fallback covers non-union values arriving from untyped + * callers at runtime, matching the old switch's default arm. + */ mapToStoreCategory(category) { - switch (category) { - case "profile": - return "fact"; - case "preferences": - return "preference"; - case "entities": - return "entity"; - case "events": - return "decision"; - case "cases": - return "fact"; - case "patterns": - return "other"; - default: - return "other"; - } + return getStorageCategoryForMemoryCategory(category) ?? "other"; } /** * Get default importance score by category. diff --git a/src/memory-categories.ts b/src/memory-categories.ts index 6b4c9249..809c0327 100644 --- a/src/memory-categories.ts +++ b/src/memory-categories.ts @@ -31,7 +31,13 @@ export const TOOL_MEMORY_CATEGORIES = [ export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number]; export type LegacyMemoryCategory = (typeof LEGACY_MEMORY_CATEGORIES)[number]; -const SMART_TO_STORAGE_CATEGORY: Record = { +/** + * Storage categories that smart registers map onto. "reflection" is minted + * only by the reflection writer and is deliberately absent from this map. + */ +export type SmartStorageCategory = Exclude; + +const SMART_TO_STORAGE_CATEGORY: Record = { profile: "fact", preferences: "preference", entities: "entity", @@ -172,7 +178,7 @@ export function resolveCategoryFilterCandidates(requestedCategory: string): stri export function getStorageCategoryForMemoryCategory( category: MemoryCategory, -): LegacyMemoryCategory { +): SmartStorageCategory { return SMART_TO_STORAGE_CATEGORY[category]; } diff --git a/src/smart-extractor.ts b/src/smart-extractor.ts index e92c41b3..aafa3116 100644 --- a/src/smart-extractor.ts +++ b/src/smart-extractor.ts @@ -27,6 +27,7 @@ import { type ExtractionStats, type MemoryCategory, ALWAYS_MERGE_CATEGORIES, + getStorageCategoryForMemoryCategory, MERGE_SUPPORTED_CATEGORIES, MEMORY_CATEGORIES, TEMPORAL_VERSIONED_CATEGORIES, @@ -1759,25 +1760,19 @@ export class SmartExtractor { /** * Map 6-category to existing 5-category store type for backward compatibility. */ + /** + * Map a smart register onto its legacy storage category, delegating to the + * shared SMART_TO_STORAGE_CATEGORY constant (memory-categories) so the + * mapping has a single source of truth. Note: "reflection" is a legacy + * storage category minted only by the reflection writer and is deliberately + * absent from this map; smart extraction never produces reflection rows. + * The "other" fallback covers non-union values arriving from untyped + * callers at runtime, matching the old switch's default arm. + */ private mapToStoreCategory( category: MemoryCategory, ): "preference" | "fact" | "decision" | "entity" | "other" { - switch (category) { - case "profile": - return "fact"; - case "preferences": - return "preference"; - case "entities": - return "entity"; - case "events": - return "decision"; - case "cases": - return "fact"; - case "patterns": - return "other"; - default: - return "other"; - } + return getStorageCategoryForMemoryCategory(category) ?? "other"; } /**