@sema-agent/core
Version:
Stateless, task-oriented AI agent core
41 lines (40 loc) • 1.42 kB
JavaScript
export function shadowKeyOf(h) {
return h.name ?? h.slug.split("/").pop() ?? h.slug;
}
export function shadowNamesOf(headers, writeScope, opts = {}) {
const out = new Map();
if (writeScope === null)
return out;
for (const h of headers) {
if (h.scope !== writeScope)
continue;
if (opts.excluded?.(h.id) === true)
continue;
const key = shadowKeyOf(h);
if (key === "")
continue;
const prior = out.get(key);
if (prior === undefined || h.id < prior)
out.set(key, h.id);
}
return out;
}
export function deriveShadowedSet(headers, writeScope, opts = {}) {
const names = opts.shadowNames ?? shadowNamesOf(headers, writeScope, opts);
const out = new Map();
if (names.size === 0)
return out;
for (const h of headers) {
if (h.scope === writeScope)
continue;
const carrier = names.get(shadowKeyOf(h));
if (carrier === undefined || carrier === h.id)
continue;
out.set(h.id, carrier);
}
return out;
}
export function memoryShadowedNote(shadowingId) {
return `note: a same-named entry in this session's write home shadows this one — memory entry ${shadowingId} carries the form this session reads by default; this entry remains readable as evidence.`;
}
export const MEMORY_SEARCH_SHADOWED_TAG = "[shadowed]";