76 lines
4.1 KiB
JavaScript
76 lines
4.1 KiB
JavaScript
export const NATIVE_PROVIDER_ID = 'mnemon-native';
|
|
export const DEFAULT_TIMEOUT_MS = 10_000;
|
|
export const DEFAULT_RECALL_LIMIT = 10;
|
|
export const DEFAULT_RECALL_QUALITY_POLICY = 'strict-v1';
|
|
export function isNativeProvider(provider) {
|
|
return (provider.typeId ?? provider.id) === NATIVE_PROVIDER_ID;
|
|
}
|
|
export const MEMORY_PLACEMENT_CAPABILITIES = ['graph', 'entities', 'related', 'exact-write', 'link', 'forget'];
|
|
export const CATEGORIES = ['preference', 'decision', 'fact', 'insight', 'context', 'general'];
|
|
export const SOURCES = ['user', 'agent', 'external'];
|
|
export const EDGE_TYPES = ['temporal', 'semantic', 'causal', 'entity'];
|
|
export const INTENTS = ['WHY', 'WHEN', 'ENTITY', 'GENERAL'];
|
|
export function normalizeEntityKey(entity) {
|
|
return entity.normalize('NFKC').trim().toLocaleLowerCase();
|
|
}
|
|
export const DEFAULT_EMBEDDING_ENDPOINT = 'http://localhost:11434';
|
|
export const DEFAULT_EMBEDDING_MODEL = 'nomic-embed-text';
|
|
export const EMBEDDING_PROTOCOL_AUTO = 'auto';
|
|
export const EMBEDDING_PROTOCOL_OLLAMA = 'ollama';
|
|
export const EMBEDDING_PROTOCOL_OPENAI = 'openai';
|
|
export const DEFAULT_EMBEDDING_PROTOCOL = EMBEDDING_PROTOCOL_AUTO;
|
|
export const MNEMON_EMBEDDING_PROTOCOLS = [EMBEDDING_PROTOCOL_AUTO, EMBEDDING_PROTOCOL_OLLAMA, EMBEDDING_PROTOCOL_OPENAI];
|
|
export const EMBEDDING_CREDENTIAL_PREFIX = 'dsh-mnemon/embedding-';
|
|
export const EMBEDDING_CREDENTIAL_REFERENCE = /^dsh-mnemon\/embedding-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u;
|
|
export const EMBEDDING_ENVIRONMENT_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/u;
|
|
export const MEMORY_SPACES_DIRECTORY = 'data';
|
|
export const MEMORY_SPACE_REGISTRY_FILE = '.dsh-memory-bodies.json';
|
|
export const MEMORY_SPACE_DATABASE_FILE = 'mnemon.db';
|
|
export const MEMORY_SPACE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
export const MEMORY_SPACE_NAME_MAX_LENGTH = 100;
|
|
export const MEMORY_SPACE_DESCRIPTION_MAX_LENGTH = 1000;
|
|
export const MNEMON_ACTIVE_STORE_FILE = 'active';
|
|
export const MEMORY_PROVIDER_REGISTRY_FILE = 'memory-providers.json';
|
|
function isObject(value) {
|
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
}
|
|
export function parseMemorySpaceRegistry(value) {
|
|
const registry = isObject(value) ? value : undefined;
|
|
if (registry?.version !== 1 || !Array.isArray(registry.bodies))
|
|
throw new Error('Memory Space registry is invalid');
|
|
const ids = new Set();
|
|
const bodies = registry.bodies.map((raw) => {
|
|
const body = isObject(raw) ? raw : undefined;
|
|
if (typeof body?.id !== 'string' || !MEMORY_SPACE_ID_PATTERN.test(body.id) || ids.has(body.id))
|
|
throw new Error('Memory Space registry contains an invalid or duplicate id');
|
|
if (typeof body.name !== 'string' || body.name.trim() === '' || body.name.length > MEMORY_SPACE_NAME_MAX_LENGTH
|
|
|| typeof body.description !== 'string' || body.description.length > MEMORY_SPACE_DESCRIPTION_MAX_LENGTH)
|
|
throw new Error('Memory Space registry contains invalid metadata');
|
|
if (typeof body.createdAt !== 'string' || typeof body.updatedAt !== 'string')
|
|
throw new Error('Memory Space registry contains invalid timestamps');
|
|
ids.add(body.id);
|
|
return { id: body.id, name: body.name, description: body.description, active: body.active === true, createdAt: body.createdAt, updatedAt: body.updatedAt };
|
|
});
|
|
return { version: 1, bodies };
|
|
}
|
|
export function summarizeMemorySpaceRegistry(value) {
|
|
const registry = isObject(value) ? value : undefined;
|
|
const listed = registry?.bodies;
|
|
const spaces = Array.isArray(listed) ? listed.filter(isObject) : [];
|
|
return {
|
|
valid: registry?.version === 1 && Array.isArray(listed),
|
|
spaces: spaces.length,
|
|
active: spaces.filter(space => space.active === true).length,
|
|
};
|
|
}
|
|
export function summarizeMemoryProviderRegistry(value) {
|
|
const registry = isObject(value) ? value : undefined;
|
|
const services = registry?.services;
|
|
const listed = registry?.bodies;
|
|
return {
|
|
valid: registry !== undefined,
|
|
services: isObject(services) ? Object.keys(services).length : 0,
|
|
connections: Array.isArray(listed) ? listed.length : 0,
|
|
};
|
|
}
|