Utility functions for detecting local browser environments and validating observable platform session ownership. Reuse to manage session visibility and debugging permissions.
// Source: https://github.com/swarmclawai/swarmclaw | License: MIT | Copyright 2026 SwarmClaw Contributors
// Provided via justclaw.it.com; keep this notice with the code.
import type { Session } from '@/types'
const LOCALHOST_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1', '0.0.0.0'])
const OBSERVABLE_PLATFORM_SESSION_OWNERS = new Set(['workbench', 'comparison-bench'])
const VISIBLE_NON_USER_SESSION_OWNERS = new Set(['system', 'swarm'])
function normalizeHostname(hostname: string): string {
return hostname.trim().toLowerCase().replace(/^\[(.*)\]$/, '$1')
}
export function isLocalhostBrowser(): boolean {
if (typeof window === 'undefined') return false
return LOCALHOST_HOSTNAMES.has(normalizeHostname(window.location.hostname))
}
export function isObservablePlatformSessionOwn
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key