UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

18 lines (17 loc) • 920 B
export function readRootGrantSeat(grant, candidate, allowed) { if (grant === undefined) return {}; const offered = candidate !== undefined ? { offered: candidate.dir } : {}; const requested = typeof grant === "string" ? { requested: grant } : {}; const reason = !allowed ? "on_refusal" : typeof grant !== "string" ? "not_a_string" : candidate === undefined ? "no_candidate" : grant !== candidate.dir ? "mismatch" : undefined; if (reason !== undefined) return { readRootGrant: { verdict: "rejected", reason, ...offered, ...requested } }; return { readRootGrant: { verdict: "granted", candidate: candidate } }; } export function ownReadRootCandidate(c) { if (c === undefined) return undefined; const dir = c.dir; const covers = c.covers; return typeof dir === "string" ? { dir, clearsThisAsk: true, ...(covers === "exact" ? { covers } : {}) } : undefined; }