UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

34 lines (33 loc) • 1.58 kB
import { strayMembersOf } from "./own-property-receipt.js"; const ECHO_MEMBERS = Object.freeze(["kind", "value", "canonical"]); const ECHO_WORDS = Object.freeze({ subject: "an echo", unit: "member", moment: "at the gate record" }); export const REFUSAL_ECHO_KINDS = Object.freeze(["path", "command", "pattern"]); const KIND_SET = new Set(REFUSAL_ECHO_KINDS); export function isRefusalEchoKind(v) { return KIND_SET.has(v); } export function refusalEchoDefects(v) { if (!Array.isArray(v) || v.length === 0) return ["echoed is not a non-empty list"]; const out = []; if (Reflect.ownKeys(v).length !== v.length + 1) out.push("echoed holds a hole or a member that is no element"); for (let i = 0; i < v.length; i++) { const e = v[i]; if (typeof e !== "object" || e === null || Array.isArray(e)) { out.push(`echoed[${i}] is not an object`); continue; } const r = e; if (!isRefusalEchoKind(r.kind)) out.push(`echoed[${i}].kind is outside the closed set`); if (typeof r.value !== "string" || r.value === "") out.push(`echoed[${i}].value is not a non-empty string`); if (r.canonical !== undefined && (typeof r.canonical !== "string" || r.canonical === "" || r.kind !== "path")) out.push(`echoed[${i}].canonical stands only on a path, as a non-empty string`); const stray = strayMembersOf(r, ECHO_WORDS, ECHO_MEMBERS); if (stray !== undefined) out.push(`echoed[${i}]: ${stray.sentence}`); } return out; }