import { useEffect, useState, type ReactNode } from 'react'
import {
Cloud, Flame, Radio, Car, Mountain, Satellite, Activity, Server,
Save, RotateCcw, RefreshCw, AlertCircle, AlertTriangle, Info,
} from 'lucide-react'
import {
Toggle, TextInput, NumberInput, SelectInput, ListInput, NumberListInput,
US_STATES,
} from './Config'
import {
fetchEnvStatus, fetchEnvActive,
type EnvStatus, type EnvEvent,
} from '@/lib/api'
type FeedSource = 'native' | 'central'
interface EnvConfig {
enabled: boolean
nws_zones: string[]
nws: { enabled: boolean; user_agent: string; tick_seconds: number; severity_min: string; feed_source?: FeedSource }
swpc: { enabled: boolean; feed_source?: FeedSource }
ducting: { enabled: boolean; tick_seconds: number; latitude: number; longitude: number; feed_source?: FeedSource }
fires: { enabled: boolean; tick_seconds: number; state: string; feed_source?: FeedSource }
avalanche: { enabled: boolean; tick_seconds: number; center_ids: string[]; season_months: number[]; feed_source?: FeedSource }
usgs: { enabled: boolean; tick_seconds: number; sites: string[]; feed_source?: FeedSource }
usgs_quake: { enabled: boolean; tick_seconds: number; feed_url: string; global_mag_floor: number; regional_mag_floor: number; regional_radius_mi: number; escalate_mag_floor: number; broadcast_pager_alerts: string[]; region: string; feed_source?: FeedSource }
traffic: { enabled: boolean; tick_seconds: number; api_key: string; corridors: { name: string; lat: number; lon: number }[]; feed_source?: FeedSource }
roads511: { enabled: boolean; tick_seconds: number; api_key: string; base_url: string; endpoints: string[]; bbox: number[]; feed_source?: FeedSource }
wzdx: { enabled: boolean; tick_seconds: number; api_key: string; base_url: string; endpoints: string[]; bbox: number[]; feed_source?: FeedSource }
firms: { enabled: boolean; tick_seconds: number; map_key: string; source: string; bbox: number[]; day_range: number; confidence_min: string; proximity_km: number; feed_source?: FeedSource }
central?: { enabled: boolean; url: string; durable: string; region: string }
}
// WFIGS adapter config shape
interface WfigsConfig {
allowed_incident_types: string[]
freshness_seconds: number
cooldown_seconds: number
broadcast_on_acres: boolean
broadcast_on_contained: boolean
}
// Fires adapter config shape (digest settings)
interface FiresConfig {
digest_enabled: boolean
digest_schedule: string[]
digest_timezone: string
}
// ITD 511 adapter config shape
interface Roads511Config {
min_severity: string
enabled_categories: string[]
enabled_sub_types: string[]
}
// WZDx adapter config shape
interface WzdxConfig {
broadcast: boolean
min_severity: string
sub_types: string[]
}
// NWS adapter config shape
interface NwsConfig {
broadcast_severities: string[]
duplicate_allowed_after_seconds: number
}
interface TomtomConfig {
min_magnitude: number
drop_non_present: boolean
drop_zero_magnitude: boolean
}
type FeedHealth = EnvStatus['feeds'][number]
// ---------------------------------------------------------------- status cards
function FeedStatusCard({ feed }: { feed: FeedHealth }) {
const color = !feed.is_loaded ? 'bg-red-500' : feed.consecutive_errors > 0 ? 'bg-amber-500' : 'bg-green-500'
const text = !feed.is_loaded ? 'Not loaded' : feed.consecutive_errors > 0 ? `${feed.consecutive_errors} errors` : 'Healthy'
const lastFetch = feed.last_fetch ? new Date(feed.last_fetch * 1000).toLocaleTimeString() : 'Never'
return (
Events: {feed.event_count}
Last fetch: {lastFetch}
{feed.last_error &&
{feed.last_error}
}
)
}
function EventCard({ event }: { event: EnvEvent }) {
const sev = event.severity.toLowerCase()
const styles = (sev === 'extreme' || sev === 'severe' || sev === 'immediate')
? { bg: 'bg-red-500/10', border: 'border-red-500', Icon: AlertCircle, color: 'text-red-500' }
: (sev === 'moderate' || sev === 'warning' || sev === 'priority')
? { bg: 'bg-amber-500/10', border: 'border-amber-500', Icon: AlertTriangle, color: 'text-amber-500' }
: { bg: 'bg-blue-500/10', border: 'border-blue-500', Icon: Info, color: 'text-blue-500' }
const Icon = styles.Icon
return (
{event.event_type}
{event.severity}
{event.headline}
)
}
// ---------------------------------------------------------------- feed_source toggle
function FeedSourceToggle({ value, onChange, disabled, centralDisabled }: {
value: FeedSource; onChange: (v: FeedSource) => void; disabled: boolean; centralDisabled: boolean
}) {
const base = 'px-2 py-1 text-xs transition-colors'
return (
onChange('native')}
className={`${base} ${value === 'native' ? 'bg-accent text-white' : 'text-slate-400 hover:text-slate-200'}`}
>native
{ if (!centralDisabled) onChange('central') }}
className={`${base} ${centralDisabled ? 'text-slate-600 cursor-not-allowed' : value === 'central' ? 'bg-accent text-white' : 'text-slate-400 hover:text-slate-200'}`}
>central
)
}
// ---------------------------------------------------------------- adapter panel
function AdapterPanel({ title, subtitle, enabled, onEnabled, feedSource, onFeedSource, hasCentral, nativeOnly, hasKey, health, events, children }: {
title: string; subtitle?: string
enabled: boolean; onEnabled: (v: boolean) => void
feedSource: FeedSource; onFeedSource: (v: FeedSource) => void
hasCentral: boolean; nativeOnly: boolean; hasKey: boolean
health?: FeedHealth; events?: EnvEvent[]; children?: ReactNode
}) {
const centralDisabled = nativeOnly || !hasCentral
return (
{title}
{subtitle &&
{subtitle}
}
{!hasKey && (
API key not configured — contact admin
)}
{nativeOnly && (
Central not available for this adapter — native only
)}
{children}
{(health || (events && events.length > 0)) && (
Live status
{health ?
:
No status reported.
}
{events && events.length > 0 && (
{events.slice(0, 5).map((e, i) => )}
)}
)}
)
}
// ---------------------------------------------------------------- families
type AdapterKey = 'nws' | 'fires' | 'firms' | 'swpc' | 'ducting' | 'traffic' | 'roads511' | 'wzdx' | 'usgs_quake' | 'usgs' | 'avalanche'
interface AdapterMeta { label: string; subtitle: string; health: string; hasCentral: boolean; nativeOnly: boolean; hasKey: boolean }
const META: Record = {
nws: { label: 'NWS Weather Alerts', subtitle: 'National Weather Service alerts', health: 'nws', hasCentral: true, nativeOnly: false, hasKey: true },
fires: { label: 'NIFC Fire Perimeters', subtitle: 'Active wildfires (National Interagency Fire Center)', health: 'nifc', hasCentral: true, nativeOnly: false, hasKey: true },
firms: { label: 'NASA FIRMS Hotspots', subtitle: 'Satellite thermal-anomaly detections', health: 'firms', hasCentral: true, nativeOnly: false, hasKey: false },
swpc: { label: 'NOAA Space Weather (SWPC)', subtitle: 'Solar indices, geomagnetic storms', health: 'swpc', hasCentral: true, nativeOnly: false, hasKey: true },
ducting: { label: 'Tropospheric Ducting', subtitle: 'VHF/UHF extended-range conditions', health: 'ducting', hasCentral: false, nativeOnly: true, hasKey: true },
traffic: { label: 'TomTom Traffic', subtitle: 'Traffic flow on monitored corridors', health: 'traffic', hasCentral: true, nativeOnly: false, hasKey: true },
roads511: { label: '511 Road Conditions', subtitle: 'State DOT road events and closures', health: 'roads511', hasCentral: true, nativeOnly: false, hasKey: false },
wzdx: { label: 'WZDx Work Zones', subtitle: 'Planned road work and construction events from ITD', health: 'roads511', hasCentral: true, nativeOnly: false, hasKey: true },
usgs_quake: { label: 'USGS Earthquakes', subtitle: 'Seismic events from the USGS feed', health: 'usgs_quake', hasCentral: true, nativeOnly: false, hasKey: true },
usgs: { label: 'USGS Stream Gauges', subtitle: 'River and stream water levels', health: 'usgs', hasCentral: true, nativeOnly: false, hasKey: true },
avalanche: { label: 'Avalanche Advisories', subtitle: 'Backcountry avalanche danger ratings', health: 'avalanche', hasCentral: false, nativeOnly: true, hasKey: true },
}
const FAMILIES: { key: string; label: string; icon: typeof Cloud; adapters: AdapterKey[] }[] = [
{ key: 'central', label: 'Central', icon: Server, adapters: [] },
{ key: 'weather', label: 'Weather', icon: Cloud, adapters: ['nws'] },
{ key: 'fire', label: 'Fire', icon: Flame, adapters: ['fires', 'firms'] },
{ key: 'rf', label: 'RF Propagation', icon: Radio, adapters: ['swpc', 'ducting'] },
{ key: 'roads', label: 'Roads', icon: Car, adapters: ['traffic', 'roads511', 'wzdx'] },
{ key: 'geohazards', label: 'Geohazards', icon: Mountain, adapters: ['usgs_quake', 'usgs', 'avalanche'] },
{ key: 'tracking', label: 'Tracking', icon: Satellite, adapters: [] },
{ key: 'mesh', label: 'Mesh Health', icon: Activity, adapters: [] },
]
// ---------------------------------------------------------------- main page
export default function Environment() {
const [env, setEnv] = useState(null)
const [original, setOriginal] = useState('')
const [status, setStatus] = useState(null)
const [events, setEvents] = useState([])
const [loading, setLoading] = useState(true)
const [saving, setSaving] = useState(false)
const [error, setError] = useState(null)
const [success, setSuccess] = useState(null)
const [restartRequired, setRestartRequired] = useState(false)
const [family, setFamily] = useState('weather')
const [adapter, setAdapter] = useState('nws')
// WFIGS/fires adapter config state
const [wfigsConfig, setWfigsConfig] = useState({
allowed_incident_types: ['WF'],
freshness_seconds: 0,
cooldown_seconds: 28800,
broadcast_on_acres: true,
broadcast_on_contained: true,
})
const [wfigsOriginal, setWfigsOriginal] = useState("")
const [firesConfig, setFiresConfig] = useState({
digest_enabled: true,
digest_schedule: ["06:00", "18:00"],
digest_timezone: "America/Boise",
})
const [firesOriginal, setFiresOriginal] = useState("")
const [tomtomConfig, setTomtomConfig] = useState({
min_magnitude: 4,
drop_non_present: true,
drop_zero_magnitude: true,
})
const [tomtomOriginal, setTomtomOriginal] = useState("")
const [roads511Config, setRoads511Config] = useState({
min_severity: "None",
enabled_categories: ["incident", "closure"],
enabled_sub_types: ["accident", "road_closed", "closure", "lane_closed", "vehicle_on_fire", "flooding", "debris"],
})
const [roads511Original, setRoads511Original] = useState("")
const [wzdxConfig, setWzdxConfig] = useState({
broadcast: false,
min_severity: "Minor",
sub_types: ["road_works", "lane_closed", "road_closed"],
})
const [wzdxOriginal, setWzdxOriginal] = useState("")
const [nwsConfig, setNwsConfig] = useState({
broadcast_severities: ["Extreme", "Severe"],
duplicate_allowed_after_seconds: 3600,
})
const [nwsOriginal, setNwsOriginal] = useState("")
useEffect(() => {
document.title = 'Environment — MeshAI'
;(async () => {
try {
const res = await fetch('/api/config/environmental')
const data = await res.json()
setEnv(data)
setOriginal(JSON.stringify(data))
// Load adapter-config for wfigs
try {
const wfigsRes = await fetch("/api/adapter-config/wfigs")
if (wfigsRes.ok) {
const wfigsData = await wfigsRes.json()
const cfg: WfigsConfig = {
allowed_incident_types: wfigsData.allowed_incident_types?.value ?? ['WF'],
freshness_seconds: wfigsData.freshness_seconds?.value ?? 0,
cooldown_seconds: wfigsData.cooldown_seconds?.value ?? 28800,
broadcast_on_acres: wfigsData.broadcast_on_acres?.value ?? true,
broadcast_on_contained: wfigsData.broadcast_on_contained?.value ?? true,
}
setWfigsConfig(cfg)
setWfigsOriginal(JSON.stringify(cfg))
}
} catch { /* adapter-config optional */ }
// Load adapter-config for fires (digest settings)
try {
const firesRes = await fetch("/api/adapter-config/fires")
if (firesRes.ok) {
const firesData = await firesRes.json()
const cfg: FiresConfig = {
digest_enabled: firesData.digest_enabled?.value ?? true,
digest_schedule: firesData.digest_schedule?.value ?? ["06:00", "18:00"],
digest_timezone: firesData.digest_timezone?.value ?? "America/Boise",
}
setFiresConfig(cfg)
setFiresOriginal(JSON.stringify(cfg))
}
} catch { /* adapter-config optional */ }
// Load adapter-config for tomtom_incidents
try {
const ttRes = await fetch("/api/adapter-config/tomtom_incidents")
if (ttRes.ok) {
const ttData = await ttRes.json()
const cfg: TomtomConfig = {
min_magnitude: ttData.min_magnitude?.value ?? 4,
drop_non_present: ttData.drop_non_present?.value ?? true,
drop_zero_magnitude: ttData.drop_zero_magnitude?.value ?? true,
}
setTomtomConfig(cfg)
setTomtomOriginal(JSON.stringify(cfg))
}
} catch { /* adapter-config optional */ }
// Load adapter-config for itd_511
try {
const r511Res = await fetch("/api/adapter-config/itd_511")
if (r511Res.ok) {
const r511Data = await r511Res.json()
const cfg: Roads511Config = {
min_severity: r511Data.min_severity?.value ?? "None",
enabled_categories: r511Data.enabled_categories?.value ?? ["incident", "closure"],
enabled_sub_types: r511Data.enabled_sub_types?.value ?? ["accident", "road_closed", "closure", "lane_closed", "vehicle_on_fire", "flooding", "debris"],
}
setRoads511Config(cfg)
setRoads511Original(JSON.stringify(cfg))
}
} catch { /* adapter-config optional */ }
// Load adapter-config for wzdx
try {
const wzdxRes = await fetch("/api/adapter-config/wzdx")
if (wzdxRes.ok) {
const wzdxData = await wzdxRes.json()
const cfg: WzdxConfig = {
broadcast: wzdxData.broadcast?.value ?? false,
min_severity: wzdxData.min_severity?.value ?? "Minor",
sub_types: wzdxData.sub_types?.value ?? ["road_works", "lane_closed", "road_closed"],
}
setWzdxConfig(cfg)
setWzdxOriginal(JSON.stringify(cfg))
}
} catch { /* adapter-config optional */ }
// Load adapter-config for nws
try {
const nwsRes = await fetch("/api/adapter-config/nws")
if (nwsRes.ok) {
const nwsData = await nwsRes.json()
const cfg: NwsConfig = {
broadcast_severities: nwsData.broadcast_severities?.value ?? ["Extreme", "Severe"],
duplicate_allowed_after_seconds: nwsData.duplicate_allowed_after_seconds?.value ?? 3600,
}
setNwsConfig(cfg)
setNwsOriginal(JSON.stringify(cfg))
}
} catch { /* adapter-config optional */ }
} catch (e) {
setError(e instanceof Error ? e.message : 'Failed to load config')
} finally {
setLoading(false)
}
})()
}, [])
useEffect(() => {
const load = async () => {
try {
setStatus(await fetchEnvStatus())
setEvents(await fetchEnvActive())
} catch { /* status is best-effort */ }
}
load()
const t = setInterval(load, 30000)
return () => clearInterval(t)
}, [])
const hasEnvChanges = env !== null && JSON.stringify(env) !== original
const hasWfigsChanges = JSON.stringify(wfigsConfig) !== wfigsOriginal
const hasFiresChanges = JSON.stringify(firesConfig) !== firesOriginal
const hasTomtomChanges = JSON.stringify(tomtomConfig) !== tomtomOriginal
const hasRoads511Changes = JSON.stringify(roads511Config) !== roads511Original
const hasWzdxChanges = JSON.stringify(wzdxConfig) !== wzdxOriginal
const hasNwsChanges = JSON.stringify(nwsConfig) !== nwsOriginal
const hasChanges = hasEnvChanges || hasWfigsChanges || hasFiresChanges || hasTomtomChanges || hasRoads511Changes || hasWzdxChanges || hasNwsChanges
const saveAdapterConfig = async (adapterName: string, key: string, value: unknown) => {
const res = await fetch(`/api/adapter-config/${adapterName}/${key}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ value }),
})
if (!res.ok) {
const err = await res.json().catch(() => ({}))
throw new Error(err.detail || `Failed to save ${adapterName}.${key}`)
}
}
const save = async () => {
if (!env) return
setSaving(true); setError(null); setSuccess(null)
try {
// Save environmental config
if (hasEnvChanges) {
const res = await fetch('/api/config/environmental', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(env),
})
const result = await res.json()
if (!res.ok) throw new Error(result.detail || 'Save failed')
setOriginal(JSON.stringify(env))
if (result.restart_required) setRestartRequired(true)
}
// Save wfigs adapter config changes
if (hasWfigsChanges) {
const orig = JSON.parse(wfigsOriginal) as WfigsConfig
if (wfigsConfig.freshness_seconds !== orig.freshness_seconds) {
await saveAdapterConfig("wfigs", "freshness_seconds", wfigsConfig.freshness_seconds)
}
if (JSON.stringify(wfigsConfig.allowed_incident_types) !== JSON.stringify(orig.allowed_incident_types)) {
await saveAdapterConfig("wfigs", "allowed_incident_types", wfigsConfig.allowed_incident_types)
}
if (wfigsConfig.cooldown_seconds !== orig.cooldown_seconds) {
await saveAdapterConfig("wfigs", "cooldown_seconds", wfigsConfig.cooldown_seconds)
}
if (wfigsConfig.broadcast_on_acres !== orig.broadcast_on_acres) {
await saveAdapterConfig("wfigs", "broadcast_on_acres", wfigsConfig.broadcast_on_acres)
}
if (wfigsConfig.broadcast_on_contained !== orig.broadcast_on_contained) {
await saveAdapterConfig("wfigs", "broadcast_on_contained", wfigsConfig.broadcast_on_contained)
}
setWfigsOriginal(JSON.stringify(wfigsConfig))
}
// Save fires adapter config changes (digest)
if (hasFiresChanges) {
const orig = JSON.parse(firesOriginal) as FiresConfig
if (firesConfig.digest_enabled !== orig.digest_enabled) {
await saveAdapterConfig("fires", "digest_enabled", firesConfig.digest_enabled)
}
if (JSON.stringify(firesConfig.digest_schedule) !== JSON.stringify(orig.digest_schedule)) {
await saveAdapterConfig("fires", "digest_schedule", firesConfig.digest_schedule)
}
if (firesConfig.digest_timezone !== orig.digest_timezone) {
await saveAdapterConfig("fires", "digest_timezone", firesConfig.digest_timezone)
}
setFiresOriginal(JSON.stringify(firesConfig))
}
// Save tomtom adapter config changes
if (hasTomtomChanges) {
const orig = JSON.parse(tomtomOriginal) as TomtomConfig
if (tomtomConfig.min_magnitude !== orig.min_magnitude) {
await saveAdapterConfig("tomtom_incidents", "min_magnitude", tomtomConfig.min_magnitude)
}
if (tomtomConfig.drop_non_present !== orig.drop_non_present) {
await saveAdapterConfig("tomtom_incidents", "drop_non_present", tomtomConfig.drop_non_present)
}
if (tomtomConfig.drop_zero_magnitude !== orig.drop_zero_magnitude) {
await saveAdapterConfig("tomtom_incidents", "drop_zero_magnitude", tomtomConfig.drop_zero_magnitude)
}
setTomtomOriginal(JSON.stringify(tomtomConfig))
}
// Save itd_511 adapter config changes
if (hasRoads511Changes) {
const orig = JSON.parse(roads511Original) as Roads511Config
if (roads511Config.min_severity !== orig.min_severity) {
await saveAdapterConfig("itd_511", "min_severity", roads511Config.min_severity)
}
if (JSON.stringify(roads511Config.enabled_categories) !== JSON.stringify(orig.enabled_categories)) {
await saveAdapterConfig("itd_511", "enabled_categories", roads511Config.enabled_categories)
}
if (JSON.stringify(roads511Config.enabled_sub_types) !== JSON.stringify(orig.enabled_sub_types)) {
await saveAdapterConfig("itd_511", "enabled_sub_types", roads511Config.enabled_sub_types)
}
setRoads511Original(JSON.stringify(roads511Config))
}
// Save wzdx adapter config changes
if (hasWzdxChanges) {
const orig = JSON.parse(wzdxOriginal) as WzdxConfig
if (wzdxConfig.broadcast !== orig.broadcast) {
await saveAdapterConfig("wzdx", "broadcast", wzdxConfig.broadcast)
}
if (wzdxConfig.min_severity !== orig.min_severity) {
await saveAdapterConfig("wzdx", "min_severity", wzdxConfig.min_severity)
}
if (JSON.stringify(wzdxConfig.sub_types) !== JSON.stringify(orig.sub_types)) {
await saveAdapterConfig("wzdx", "sub_types", wzdxConfig.sub_types)
}
setWzdxOriginal(JSON.stringify(wzdxConfig))
}
// Save nws adapter config changes
if (hasNwsChanges) {
const orig = JSON.parse(nwsOriginal) as NwsConfig
if (JSON.stringify(nwsConfig.broadcast_severities) !== JSON.stringify(orig.broadcast_severities)) {
await saveAdapterConfig("nws", "broadcast_severities", nwsConfig.broadcast_severities)
}
if (nwsConfig.duplicate_allowed_after_seconds !== orig.duplicate_allowed_after_seconds) {
await saveAdapterConfig("nws", "duplicate_allowed_after_seconds", nwsConfig.duplicate_allowed_after_seconds)
}
setNwsOriginal(JSON.stringify(nwsConfig))
}
setSuccess('Config saved')
setTimeout(() => setSuccess(null), 3000)
} catch (e) {
setError(e instanceof Error ? e.message : 'Save failed')
} finally {
setSaving(false)
}
}
const discard = () => {
if (env) setEnv(JSON.parse(original))
setWfigsConfig(JSON.parse(wfigsOriginal || JSON.stringify(wfigsConfig)))
setFiresConfig(JSON.parse(firesOriginal || JSON.stringify(firesConfig)))
setTomtomConfig(JSON.parse(tomtomOriginal || JSON.stringify(tomtomConfig)))
setRoads511Config(JSON.parse(roads511Original || JSON.stringify(roads511Config)))
setWzdxConfig(JSON.parse(wzdxOriginal || JSON.stringify(wzdxConfig)))
setNwsConfig(JSON.parse(nwsOriginal || JSON.stringify(nwsConfig)))
}
const restart = async () => {
try { await fetch('/api/restart', { method: 'POST' }); setRestartRequired(false); setSuccess('Restart initiated') }
catch { setError('Restart failed') }
}
const up = (patch: Partial) => env && setEnv({ ...env, ...patch })
if (loading) return Loading environmental config…
if (!env) return {error || 'No config'}
const healthFor = (key: AdapterKey): FeedHealth | undefined =>
status?.feeds.find((f) => f.source === META[key].health)
const eventsFor = (key: AdapterKey): EnvEvent[] =>
events.filter((e) => e.source === META[key].health)
const fam = FAMILIES.find((f) => f.key === family)!
const activeAdapter: AdapterKey | null =
fam.adapters.length === 0 ? null : (adapter && fam.adapters.includes(adapter) ? adapter : fam.adapters[0])
// -- per-adapter settings forms (preserve all existing settings) --
const renderSettings = (key: AdapterKey) => {
switch (key) {
case 'nws': return (<>
up({ nws_zones: v })} helper="Zone IDs like IDZ016, IDZ030" infoLink="https://www.weather.gov/pimar/PubZone" />
{env.nws.feed_source !== 'central' && (
<>
up({ nws: { ...env.nws, user_agent: v } })} placeholder="(MeshAI, you@email.com)" helper="Format: (app_name, contact_email)" />
up({ nws: { ...env.nws, tick_seconds: v } })} min={30} />
up({ nws: { ...env.nws, severity_min: v } })} options={[{ value: 'minor', label: 'Minor' }, { value: 'moderate', label: 'Moderate' }, { value: 'severe', label: 'Severe' }, { value: 'extreme', label: 'Extreme' }]} />
>
)}
{env.nws.feed_source === 'central' && (
Broadcast Filters
setNwsConfig({ ...nwsConfig, duplicate_allowed_after_seconds: v })}
min={0} helper="Minimum seconds before the same alert ID can be re-broadcast" />
)}
>)
case 'swpc': return No additional settings.
case 'ducting': return (
up({ ducting: { ...env.ducting, tick_seconds: v } })} min={60} />
up({ ducting: { ...env.ducting, latitude: v } })} step={0.01} />
up({ ducting: { ...env.ducting, longitude: v } })} step={0.01} />
)
case 'fires': return (
{env.fires.feed_source !== 'central' && (
up({ fires: { ...env.fires, tick_seconds: v } })} min={60} />
up({ fires: { ...env.fires, state: v } })} options={US_STATES} />
)}
setWfigsConfig({ ...wfigsConfig, cooldown_seconds: v * 3600 })} min={0} helper="Minimum hours between updates for the same fire" />
setWfigsConfig({ ...wfigsConfig, freshness_seconds: v * 3600 })} min={0} helper="0 = always broadcast regardless of event age" />
)
case 'avalanche': return (<>
up({ avalanche: { ...env.avalanche, tick_seconds: v } })} min={60} />
up({ avalanche: { ...env.avalanche, center_ids: v } })} helper="e.g., SNFAC" infoLink="https://avalanche.org/avalanche-centers/" />
up({ avalanche: { ...env.avalanche, season_months: v } })} helper="e.g., 12, 1, 2, 3, 4" />
>)
case 'usgs': return (<>
up({ usgs: { ...env.usgs, tick_seconds: v } })} min={900} helper="Minimum 15 min (900s). tick_seconds is the native-mode poll interval; ignored when this adapter is set to feed_source=central." />
up({ usgs: { ...env.usgs, sites: v } })} helper="USGS gauge site numbers" infoLink="https://waterdata.usgs.gov/nwis" />
>)
case 'usgs_quake': return (
{env.usgs_quake.feed_source !== 'central' && (
up({ usgs_quake: { ...env.usgs_quake, tick_seconds: v } })}
min={60} />
up({ usgs_quake: { ...env.usgs_quake, region: v } })} />
)}
Magnitude Thresholds
up({ usgs_quake: { ...env.usgs_quake, global_mag_floor: v } })}
step={0.1} min={0} helper="Broadcast anywhere at or above this magnitude" />
up({ usgs_quake: { ...env.usgs_quake, regional_mag_floor: v } })}
step={0.1} min={0} helper="Reduced floor within regional radius" />
up({ usgs_quake: { ...env.usgs_quake, regional_radius_mi: v } })}
min={50} helper="Radius around region centroid for reduced floor" />
up({ usgs_quake: { ...env.usgs_quake, escalate_mag_floor: v } })}
step={0.1} min={0} helper="Magnitude at which broadcast uses warning emoji" />
PAGER Alert Levels
Broadcast at any magnitude when USGS PAGER alert reaches these levels
{(['green','yellow','orange','red'] as const).map((level) => (
{
const cur = env.usgs_quake.broadcast_pager_alerts
up({ usgs_quake: { ...env.usgs_quake,
broadcast_pager_alerts: e.target.checked
? [...cur, level]
: cur.filter((l) => l !== level) }})
}}
className="w-4 h-4 rounded accent-blue-500" />
{level}
))}
)
case 'traffic': return (<>
up({ traffic: { ...env.traffic, api_key: v } })} type="password" helper="developer.tomtom.com" />
up({ traffic: { ...env.traffic, tick_seconds: v } })} min={60} />
Corridors:
{(env.traffic.corridors || []).map((c, i) => (
{ const n = [...env.traffic.corridors]; n[i] = { ...c, name: v }; up({ traffic: { ...env.traffic, corridors: n } }) }} />
{ const n = [...env.traffic.corridors]; n[i] = { ...c, lat: v }; up({ traffic: { ...env.traffic, corridors: n } }) }} step={0.01} />
{ const n = [...env.traffic.corridors]; n[i] = { ...c, lon: v }; up({ traffic: { ...env.traffic, corridors: n } }) }} step={0.01} />
up({ traffic: { ...env.traffic, corridors: env.traffic.corridors.filter((_, j) => j !== i) } })} className="px-2 py-2 text-xs text-red-400 hover:text-red-300 border border-red-400/30 rounded">Remove
))}
up({ traffic: { ...env.traffic, corridors: [...(env.traffic.corridors || []), { name: '', lat: 0, lon: 0 }] } })} className="text-xs text-accent hover:underline">+ Add Corridor
>)
case 'roads511': return (<>
up({ roads511: { ...env.roads511, base_url: v } })} placeholder="https://511.yourstate.gov/api/v2" />
up({ roads511: { ...env.roads511, api_key: v } })} type="password" helper="Leave empty if not required" />
up({ roads511: { ...env.roads511, tick_seconds: v } })} min={60} />
up({ roads511: { ...env.roads511, endpoints: v } })} helper="e.g., /get/event" />
{(['West', 'South', 'East', 'North'] as const).map((lbl, i) => (
{ const b = [...(env.roads511.bbox || [0, 0, 0, 0])]; b[i] = v; up({ roads511: { ...env.roads511, bbox: b } }) }} step={0.01} />
))}
Broadcast Filters
Minimum Severity
setRoads511Config({...roads511Config, min_severity: e.target.value})}
className="w-full bg-slate-900 border border-slate-700 rounded px-3 py-2 text-sm"
>
None (all)
Minor+
Major only
Drop ITD 511 events below this severity
Sub-types
{([['accident', 'Crash'], ['road_closed', 'Road Closed'], ['lane_closed', 'Lane Closure'], ['vehicle_on_fire', 'Vehicle Fire'], ['flooding', 'Flooding'], ['debris', 'Debris'], ['road_works', 'Road Works'], ['disabled_vehicle', 'Disabled Vehicle']] as const).map(([val, label]) => (
{ const cur = roads511Config.enabled_sub_types; setRoads511Config({...roads511Config, enabled_sub_types: e.target.checked ? [...cur, val] : cur.filter(s => s !== val)}) }}
className="w-4 h-4 rounded accent-blue-500" />
{label}
))}
>)
case 'wzdx': return (<>
{env.wzdx?.feed_source !== 'central' && (
<>
up({ wzdx: { ...env.wzdx!, base_url: v } })} placeholder="https://511.yourstate.gov/api/v2" />
up({ wzdx: { ...env.wzdx!, api_key: v } })} type="password" helper="Leave empty if not required" />
up({ wzdx: { ...env.wzdx!, tick_seconds: v } })} min={60} />
up({ wzdx: { ...env.wzdx!, endpoints: v } })} helper="e.g., /get/event" />
{(['West', 'South', 'East', 'North'] as const).map((lbl, i) => (
{ const b = [...(env.wzdx?.bbox || [0, 0, 0, 0])]; b[i] = v; up({ wzdx: { ...env.wzdx!, bbox: b } }) }} step={0.01} />
))}
Bounding box [W,S,E,N] geographic filter
>
)}
Broadcast Settings
Broadcast work zone events
setWzdxConfig({...wzdxConfig, broadcast: e.target.checked})}
className="w-4 h-4 rounded accent-blue-500" />
{wzdxConfig.broadcast ? (
Min Severity
setWzdxConfig({...wzdxConfig, min_severity: e.target.value})}
className="w-full bg-slate-900 border border-slate-700 rounded px-3 py-2 text-sm"
>
None (all)
Minor+
Major only
) : (
Work zone events stored for LLM context only {'\u2014'} no mesh broadcasts.
)}
>)
case 'firms': return (<>
up({ firms: { ...env.firms, map_key: v } })} type="password" helper="firms.modaps.eosdis.nasa.gov/api/area/" infoLink="https://firms.modaps.eosdis.nasa.gov/api/area/" />
up({ firms: { ...env.firms, tick_seconds: v } })} min={300} />
up({ firms: { ...env.firms, source: v } })} options={[{ value: 'VIIRS_SNPP_NRT', label: 'VIIRS SNPP (NRT)' }, { value: 'VIIRS_NOAA20_NRT', label: 'VIIRS NOAA-20 (NRT)' }, { value: 'MODIS_NRT', label: 'MODIS (NRT)' }]} />
up({ firms: { ...env.firms, day_range: v } })} min={1} max={10} />
up({ firms: { ...env.firms, confidence_min: v } })} options={[{ value: 'low', label: 'Low' }, { value: 'nominal', label: 'Nominal' }, { value: 'high', label: 'High' }]} />
up({ firms: { ...env.firms, proximity_km: v } })} step={0.5} />
{(['West', 'South', 'East', 'North'] as const).map((lbl, i) => (
{ const b = [...(env.firms.bbox || [0, 0, 0, 0])]; b[i] = v; up({ firms: { ...env.firms, bbox: b } }) }} step={0.01} />
))}
>)
}
}
const a = env as unknown as Record
const setAdapterField = (key: AdapterKey, patch: { enabled?: boolean; feed_source?: FeedSource }) => {
const cur = (env as any)[key] || {}
up({ [key]: { ...cur, ...patch } } as unknown as Partial)
}
return (
{/* Header + master enable + save bar */}
Environment
up({ enabled: v })} />
{hasChanges && (
<>
Discard
{saving ? 'Saving…' : 'Save'}
>
)}
{error &&
{error}
}
{success &&
{success}
}
{restartRequired && (
A restart is required for some changes to take effect.
Restart now
)}
{/* Family tabs */}
{FAMILIES.map(({ key, label, icon: Icon }) => (
{ setFamily(key); const f = FAMILIES.find((x) => x.key === key)!; setAdapter(f.adapters[0] ?? null) }}
className={`flex items-center gap-2 px-4 py-2 text-sm whitespace-nowrap border-b-2 -mb-px transition-colors ${family === key ? 'border-accent text-accent' : 'border-transparent text-slate-400 hover:text-slate-200'}`}>
{label}
))}
{/* Central Connection tab */}
{family === 'central' && env.central && (
Central Connection
NATS JetStream source for any adapter set to "central"
up({ central: { ...env.central!, enabled: v } })} />
up({ central: { ...env.central!, url: v } })}
placeholder="nats://central.echo6.mesh:4222" />
up({ central: { ...env.central!, durable: v } })}
placeholder="meshai-v04" />
up({ central: { ...env.central!, region: v } })}
placeholder="us.id"
helper="Central v0.9.20 region token (dotted, e.g. 'us.id'). Empty = bare wildcards (all-US firehose). Each adapter is either Central or native, never both — see Reference → OR-not-AND Architecture for why." />
)}
{/* Tracking placeholder */}
{family === 'tracking' && (
No adapters yet. ADS-B / AIS / satellite passes are planned for v0.5.
)}
{/* Mesh Health (no env adapters; central greyed for future migration) */}
{family === 'mesh' && (
Mesh Health
Node/infra telemetry — sourced from the mesh, not an environmental feed.
source
{}} disabled={false} centralDisabled={true} />
Central not available — reserved for a future migration.
)}
{/* Adapter sub-tabs + panel */}
{fam.adapters.length > 0 && activeAdapter && (
<>
{fam.adapters.length > 1 && (
{fam.adapters.map((k) => (
setAdapter(k)}
className={`px-3 py-1.5 text-sm rounded ${activeAdapter === k ? 'bg-bg-hover text-slate-100' : 'text-slate-400 hover:text-slate-200'}`}>
{META[k].label}
))}
)}
setAdapterField(activeAdapter, { enabled: v })}
feedSource={a[activeAdapter]?.feed_source ?? 'native'}
onFeedSource={(v) => setAdapterField(activeAdapter, { feed_source: v })}
hasCentral={META[activeAdapter].hasCentral}
nativeOnly={META[activeAdapter].nativeOnly}
hasKey={META[activeAdapter].hasKey}
health={healthFor(activeAdapter)}
events={eventsFor(activeAdapter)}
>
{renderSettings(activeAdapter)}
>
)}
)
}