UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

46 lines (45 loc) • 1.71 kB
export function viewSpellings(views) { const out = []; for (const v of views.views) if (!out.includes(v.path)) out.push(v.path); return out; } export function spelledViews(spellings, kind) { return { views: spellings.map((path, i) => ({ path, kind: kind ?? (i === 0 ? "lexical" : "canonical") })) }; } export function judgePathRows(rows, views, direction) { if (direction === "allow") { if (views.unreadable !== undefined || views.views.length === 0) return undefined; for (const row of rows) if (views.views.every((v) => row.reach(v).reach === "reached")) return { row }; return undefined; } let held; for (const row of rows) { if (views.unreadable !== undefined) held ??= { row, unreadable: views.unreadable }; for (const view of views.views) { const judged = row.exemptible === true ? exemptReading(view, views) : view; if (judged === undefined) continue; const r = row.reach(judged); if (r.reach === "reached") return { row, view: view.path, viewKind: view.kind }; if (r.reach === "unreadable") held ??= { row, unreadable: r.reason }; } } return held; } function exemptReading(view, views) { if (views.identityExempt === true && view.kind !== "canonical") return undefined; if (view.exemptRemainder === undefined) return view; if (view.exemptRemainder === "") return undefined; return { path: view.exemptRemainder, kind: view.kind, ...(view.aliasResolved === true ? { aliasResolved: true } : {}) }; }