/** * rFlows applet definition — Flow Summary card. */ import type { AppletDefinition, AppletLiveData } from "../../shared/applet-types"; const flowSummary: AppletDefinition = { id: "flow-summary", label: "Flow Summary", icon: "💧", accentColor: "#0891b2", ports: [ { name: "transfer-in", type: "json", direction: "input" }, { name: "balance-out", type: "number", direction: "output" }, ], renderCompact(data: AppletLiveData): string { const { snapshot } = data; const inflowRate = (snapshot.inflowRate as number) || 0; const balance = (snapshot.balance as number) || 0; const capacity = (snapshot.capacity as number) || 1; const fillPct = Math.min(100, Math.round((balance / capacity) * 100)); const sufficiency = fillPct >= 80 ? "Sufficient" : fillPct >= 40 ? "Moderate" : "Low"; const suffColor = fillPct >= 80 ? "#22c55e" : fillPct >= 40 ? "#f59e0b" : "#ef4444"; return `
Inflow Rate ${inflowRate.toLocaleString()}/mo
Fill: ${fillPct}%
${sufficiency}
`; }, onInputReceived(portName, value, ctx) { if (portName === "transfer-in" && value && typeof value === "object") { const transfer = value as Record; const amount = Number(transfer.amount) || 0; ctx.emitOutput("balance-out", amount); } }, }; export const flowsApplets: AppletDefinition[] = [flowSummary];