UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

44 lines (43 loc) • 2.29 kB
import { EVENT_PROMPT_REGISTRY } from "./event-registry.js"; import { SEMA_DEFAULT_PACK } from "./packs/sema-default.js"; import { DEFAULT_SYSTEM_PROMPT } from "../prompts/default.js"; function safeId(raw) { const cleaned = raw.replace(/[\u0000-\u001f\u007f]/g, "\u2400"); return cleaned.length > 120 ? `${cleaned.slice(0, 117)}...` : cleaned; } export function explainPromptAssembly(input) { const lines = []; lines.push(`constitution: ${safeId(input.constitution)}${input.constitution === "core" ? "" : " (non-default — see PromptProvider tier docs)"}`); if (input.epoch) { lines.push(`epoch: #${input.epoch.epoch} on ${safeId(input.epoch.packId)} (${safeId(input.epoch.artifactDigest).slice(0, 23)}…) via ${safeId(input.epoch.activatedBy)}`); } lines.push(`system blocks (v1 view): ${input.blocks.map((b) => `${safeId(b.id)}[${b.chars}ch]`).join(" → ")}`); if (input.sections?.length) { lines.push("sections (compiled IR):"); for (const s of input.sections) { lines.push(` ${safeId(s.id)} slot=${safeId(s.slot)} carrier=${safeId(s.carrier)} cadence=${safeId(s.cadence)} cache=${safeId(s.cacheClass)} ${s.chars}ch #${safeId(s.hash)}${s.contentHash !== undefined ? ` content=${safeId(s.contentHash)}` : ""}`); } } if (input.tools?.length) { const legacy = input.tools.filter((t) => t.contractId.startsWith("legacy:")); lines.push(`tools: ${input.tools.length} mounted (${input.tools.length - legacy.length} contract-declared, ${legacy.length} legacy/external)`); } const kinds = [...EVENT_PROMPT_REGISTRY.values()]; lines.push(`event kinds registered: ${kinds.length} (default-on: ${kinds.filter((k) => k.defaultPolicy === "on").map((k) => k.kind).join(", ")})`); return lines.join("\n"); } export function describeDefaultPack() { return { packId: SEMA_DEFAULT_PACK.packId, roleBaseText: DEFAULT_SYSTEM_PROMPT, sections: [...SEMA_DEFAULT_PACK.sections].sort((a, b) => a.rank - b.rank).map((s) => ({ id: s.id, slot: s.slot, rank: s.rank, owner: s.owner, trust: s.trust, mutability: s.mutability, locked: s.mutability === "locked", })), }; }