lib/local-memory-boundary.ts
Rama main · réplica de lectura del repositorio original.
const FORBIDDEN_CONTEXT_KEYS=new Set(["prompt","prompts","memory","memories","messages","history","conversation","system_prompt","chain_of_thought"]);
export function assertBoundedLocalToolRequest(value:unknown,maxBytes=64_000){const bytes=Buffer.byteLength(JSON.stringify(value));if(bytes>maxBytes)throw new Error("Bounded tool request exceeds 64 KB.");const walk=(item:unknown,depth=0)=>{if(depth>12)throw new Error("Tool arguments are too deeply nested.");if(Array.isArray(item)){if(item.length>1000)throw new Error("Tool argument array is too large.");item.forEach((x)=>walk(x,depth+1));}else if(item&&typeof item==="object")for(const[key,child]of Object.entries(item)){if(FORBIDDEN_CONTEXT_KEYS.has(key.toLowerCase()))throw new Error(`Local context field '${key}' must not be sent to Astrail.`);walk(child,depth+1);}};walk(value);return value;}
export function localMemoryDataContract(){return{sent_to_astrail:["server_id","tool_name","bounded tool arguments","one-time task authorization","Astrail API key"],stays_local:["prompts","conversation history","memory records","retrieval context","model chain-of-thought"],stored_by_default:["tool name","argument names only","authorization decision","provider result metadata","trace and audit attribution"]};}