UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

34 lines (33 loc) • 1.28 kB
const RANK = { sandbox_local: 0, external_authority: 1, hook: 2, mandate: 3, unknown: 4 }; const registry = new WeakMap(); export function brandPolicyAskClass(policy, cls) { const desc = Object.getOwnPropertyDescriptor(policy, "check"); if (desc === undefined || desc.get !== undefined || desc.set !== undefined) return policy; try { Object.defineProperty(policy, "check", { value: policy.check, writable: false, configurable: false, enumerable: desc.enumerable ?? true }); } catch { return policy; } registry.set(policy, { cls, check: policy.check }); return policy; } export function policyAskClassOf(policy) { if (policy === null || policy === undefined) return "unknown"; const entry = registry.get(policy); if (entry === undefined) return "unknown"; const desc = Object.getOwnPropertyDescriptor(policy, "check"); if (desc === undefined || desc.get !== undefined || desc.set !== undefined) return "unknown"; return desc.value === entry.check ? entry.cls : "unknown"; } export function dominantAskClass(classes) { let strongest = "sandbox_local"; for (const c of classes) if (RANK[c] > RANK[strongest]) strongest = c; return strongest; }