@sema-agent/core
Version:
Stateless, task-oriented AI agent core
19 lines (18 loc) • 1 kB
JavaScript
export function ownSessionCallGrantOffer(o) {
if (o === undefined)
return undefined;
const grant = o.grant;
return typeof grant === "string" ? { ...o, grant } : undefined;
}
export const SESSION_CALL_GRANT_REJECTIONS = Object.freeze(["not_a_string", "no_offer", "mismatch", "edited", "not_written"]);
export function sessionCallGrantSeat(raw, offered, edited, byPerson) {
if (raw === undefined)
return {};
const shape = typeof raw !== "string" ? "not_a_string" : offered === undefined ? "no_offer" : raw !== offered.grant ? "mismatch" : undefined;
if (shape === undefined && !byPerson)
return {};
const reason = shape ?? (edited ? "edited" : undefined);
if (reason === undefined && typeof raw === "string")
return { sessionCallGrant: { verdict: "granted", grant: raw } };
return { sessionCallGrant: { verdict: "rejected", reason: reason ?? "not_a_string", ...(typeof raw === "string" ? { requested: raw.slice(0, 200) } : {}) } };
}