/** * Server-rendered Signal pages: Sources (CRUD) and Inbox (list + explain). * Pure (no kody:runtime). Every action is a plain form POST that redirects * back with a result. Pages work without JavaScript. */ import { esc, icon, renderShell } from './ui.ts' import type { SourceRecord } from '../signals/sources/types.ts' import type { SignalRecord } from '../signals/records/types.ts' import type { RoutingConfig } from '../signals/routing/types.ts' const TZ = 'America/Denver' const BAD_FLASH = /^(error|invalid|unknown|could not|failed)/i function fmtTime(iso: string | null | undefined): string { const t = iso ? Date.parse(iso) : Number.NaN if (!Number.isFinite(t)) return 'never' return new Intl.DateTimeFormat('en-US', { timeZone: TZ, month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }).format(new Date(t)) } function ago(now: number, iso: string | null | undefined): string { const t = iso ? Date.parse(iso) : Number.NaN if (!Number.isFinite(t)) return 'never' const ms = now - t if (ms < 60_000) return 'just now' if (ms < 3_600_000) return `${Math.floor(ms / 60_000)}m ago` if (ms < 86_400_000) return `${Math.floor(ms / 3_600_000)}h ago` return `${Math.floor(ms / 86_400_000)}d ago` } function when(now: number, iso: string | null | undefined): string { return iso ? `` : 'never' } function flashHtml(flash?: string): string { return flash ? `
${esc(inboundUrl)}
No signal sources yet. Create one to start receiving signals.
Manage inbound signal feeds. Each source gets an endpoint, a signing key, and routing rules.
${esc(s.note || 'No description')}
${esc(s.id)}${esc(inboundUrl)}${esc(s.signingHeader)}Confidence threshold: ${rc.confidenceThreshold.toFixed(2)}
No signals yet. Configure a source and send a test payload.
Every inbound signal with its routing decision and destination result.
${opts.records.length} of ${opts.total} signals shown
${list}No routing decision recorded
' const destRows = destResults.length ? `No destination results
' const main = `${esc(r.id)}${esc(r.payloadDigest.slice(0, 16))}...${esc(r.redactedPayload)}