@sema-agent/core
Version:
Stateless, task-oriented AI agent core
17 lines (16 loc) • 707 B
JavaScript
const ROOT_READ_THROUGH = new WeakMap();
export function rootReadThrough(root, sessions) {
ROOT_READ_THROUGH.set(root, sessions);
return root;
}
export function rootHeadReadOf(root, anchor) {
if (root === undefined || anchor.rootSessionId === undefined || anchor.rootSessionIncarnation === undefined)
return undefined;
if (root.sessionId !== anchor.rootSessionId || root.incarnation !== anchor.rootSessionIncarnation)
return undefined;
const sessions = ROOT_READ_THROUGH.get(root);
const headOf = sessions?.headOf;
if (sessions === undefined || typeof headOf !== "function")
return undefined;
return (sessionId) => headOf.call(sessions, sessionId);
}