UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

37 lines • 1.6 kB
/** * Decorate every row with `actorLabel`, resolved from ONE batched {@link ActorDirectory} lookup over * the distinct refs in the page — not one lookup per row, which is what turns a 200-row governance * page into 200 queries against the host's user table. * * Fail-soft by design: no directory bound, or a directory that throws, leaves the rows exactly as * they came out of the read-model. A label is cosmetic, and a governance page that renders raw refs * is strictly better than one that 500s because the host's user service is down. */ export async function withActorLabels(rows, directory) { if (directory === null || directory === undefined || rows.length === 0) return rows; const labels = await resolveLabels(rows.map((row) => row.actorRef), directory); if (labels === null) return rows; return rows.map((row) => { const label = labels[row.actorRef]; return label === undefined ? row : { ...row, actorLabel: label }; }); } /** {@link withActorLabels} for a single row (or `null`, which passes straight through). */ export async function withActorLabel(row, directory) { if (row === null) return null; const [decorated] = await withActorLabels([row], directory); return decorated ?? row; } /** The distinct-ref lookup, returning `null` when the directory failed (callers then skip labelling). */ async function resolveLabels(refs, directory) { try { return await directory.resolveDisplay([...new Set(refs)]); } catch { return null; } } //# sourceMappingURL=actor-labels.js.map