@sema-agent/core
Version:
Stateless, task-oriented AI agent core
30 lines (29 loc) • 1.24 kB
JavaScript
export const MAX_CHECKPOINT_ID_CHARS = 128;
export const CHECKPOINT_ID_MISSING = Object.freeze(["absent", "untrusted"]);
export function isCheckpointIdMissing(word) {
return typeof word === "string" && CHECKPOINT_ID_MISSING.includes(word);
}
export function trustedCheckpointId(raw, token) {
if (typeof raw !== "string" || raw === "" || raw.length > MAX_CHECKPOINT_ID_CHARS)
return undefined;
let secret;
try {
secret = token === undefined || token === null ? "" : String(token).toLowerCase();
}
catch {
return undefined;
}
if (secret !== "" && raw.toLowerCase().includes(secret))
return undefined;
return raw;
}
export function readGateIdentity(raw, token) {
const id = trustedCheckpointId(raw, token);
if (id !== undefined)
return { checkpointId: id };
return { checkpointIdMissing: raw === undefined ? "absent" : "untrusted" };
}
const WITHHELD_ID_LABEL = { absent: "checkpoint (id absent)", untrusted: "checkpoint (id withheld: untrusted)" };
export function checkpointRowLabel(identity) {
return identity.checkpointId !== undefined ? `checkpoint ${JSON.stringify(identity.checkpointId)}` : WITHHELD_ID_LABEL[identity.checkpointIdMissing];
}