Files
memind/user-model-service/session-snapshot.mjs
T
john 212ff3ff80 Add User Model Service and Temporal Recall for MeMind V0.1.
Introduce UMS ingest/snapshot pipeline, Context Planner with multi-source recall, runtime context injection, canonical user mapping, and session snapshot loading on auth/me.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-03 23:25:18 +08:00

31 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { resolveCanonicalUserId } from './canonical-user.mjs';
import { getActiveSnapshot } from './snapshot.mjs';
/**
* Session bootstrap payload for /auth/me (RFC: 510KB snapshot at session start).
*
* @param {import('mysql2/promise').Pool | null | undefined} pool
* @param {string} userId
* @param {string} [projection]
*/
export async function loadSessionUserModelSnapshot(pool, userId, projection = 'default') {
if (!pool?.query || !userId) return null;
const canonicalUserId = resolveCanonicalUserId(userId);
const snap = await getActiveSnapshot(pool, canonicalUserId, projection);
if (!snap) return null;
return {
snapshot_id: snap.snapshot_id,
user_id: snap.user_id,
projection: snap.projection,
profile_version: snap.profile_version,
fast_revision: snap.fast_revision,
content_hash: snap.content_hash,
byte_size: snap.byte_size,
stale_after_sec: snap.stale_after_sec,
loaded_at_hint: 'session_start',
core: snap.core,
meta: snap.meta,
...(canonicalUserId !== userId ? { canonical_user_id: canonicalUserId } : {}),
};
}