@botfather/units-agent-middleware
v0.1.2
Published
Agent-agnostic middleware for rewriting UI trees with Units transform programs.
Readme
@botfather/units-agent-middleware
Framework-agnostic middleware that rewrites host UI trees using verified Units transform programs before passing data to an LLM agent.
Install
npm install @botfather/units-agent-middleware @botfather/unitsUsage
import { createUnitsAgentMiddleware } from "@botfather/units-agent-middleware";
const middleware = createUnitsAgentMiddleware({
libraryDir: ".units/library",
gates: {
action_recall: 1,
name_recall: 0.98,
text_f1: 0.95,
},
});
const result = await middleware.rewrite({
tree: rawDomLikeTree,
sourceType: "dom",
taskContext: { task: "summarize_ui" },
});Supported sourceType values include dom, a11y, ir, react, and slack. Slack Block Kit payloads are normalized through @botfather/units-ui-ir; aliases block-kit, blockkit, and mrkdwn also route to slack.
rewrite returns transformed tree output, trace metadata, chosen program metadata, and fallback pass-through output when no verified program passes gates.
Returned agent_tree payloads use compact serialization defaults optimized for token usage (including redundant name/text dedupe, implicit-action omission, empty text leaf pruning, and text-id omission). Pass serializerOptions: { includeRedundantNameText: true, includeImplicitActions: true, includeTextIds: true } to preserve both fields, role-implicit actions, and text ids when needed.
