import { useState, useEffect, useRef } from 'react'; import { createSpaceRun, streamRunOutput, validateProof } from '../lib/atelier-runtime'; const T = { bg: '#0a0a0a', border: 'rgba(255,255,255,0.08)', text: '#f5f5f5', textDim: '#8a8a8a', textMuted: '#5e5e5e', accent: '#c9b787', mono: 'var(--font-mono,ui-monospace,monospace)', }; export interface AtelierEmbedProps { spaceSlug: string; tenantId?: string; height?: number; compact?: boolean; allowedOrigins?: string[]; } export const ALLOWED_EMBED_ORIGINS: string[] = [ 'https://szl-holdings.com', 'https://www.szl-holdings.com', 'https://app.szl-holdings.com', 'https://*.szl-holdings.com', 'https://a11oy.szl-holdings.com', 'http://localhost:3000', 'http://localhost:4099', 'http://localhost:4110', 'http://localhost:4199', 'http://localhost:5173', 'http://localhost:5000', 'http://localhost:8099', 'http://localhost:80', 'http://127.0.0.1:3000', 'http://127.0.0.1:5173', 'http://127.0.0.1:5000', ]; function isOriginAllowed(origin: string, allowlist: string[]): boolean { if (!origin) return false; for (const pattern of allowlist) { if (pattern === origin) return true; if (pattern.includes('*')) { try { const url = new URL(origin); const patternUrl = new URL(pattern.replace('*.', '')); if (url.protocol !== patternUrl.protocol) continue; const patternHost = patternUrl.hostname; if (url.hostname === patternHost || url.hostname.endsWith('.' + patternHost)) { return true; } } catch { continue; } } } return false; } const EMBED_SPACES: Record = { 'maritime-routing': { name: 'Maritime Routing Agent', vertical: 'Maritime', color: '#7ab8d9', description: 'AIS-fed route optimization and ETA monitoring for SZL maritime operations.', runtime: 'agent-loop', }, 're-underwriting': { name: 'Real Estate Underwriting Agent', vertical: 'Real Estate', color: '#c9b787', description: 'Governed underwriting analysis for acquisition, covenant risk, and lease-up.', runtime: 'agent-loop', }, 'legal-discovery': { name: 'Legal Discovery Intelligence', vertical: 'Legal', color: '#8a8a8a', description: 'Privilege-preserving discovery analysis and deadline tracking.', runtime: 'agent-loop', }, 'cyber-triage': { name: 'Cyber Threat Triage Agent', vertical: 'Cyber', color: '#10b981', description: 'CVE enrichment, SIEM correlation, and containment brief generation.', runtime: 'agent-loop', }, 'platform-health': { name: 'A11oy Platform Health', vertical: 'Platform', color: '#5e5e5e', description: 'Fabric layer health, proof ledger integrity, and SLO tracking.', runtime: 'chat', }, }; const AGENT_LOOP_OUTPUTS: Record = { 'maritime-routing': [ '⟳ Connecting to AIS Live Feed…', '✓ Vessel data received — VLCC Everest', '⟳ Calculating ETA deviation…', '⚠ ETA +31h delay detected at Port Rotterdam', '⟳ Running port standby cost model…', '✓ Standby cost: $2.4M/day', '⟳ Evaluating 3 alternative routes…', '✓ Route via Port Antwerp: saves $1.2M demurrage', '⟳ Generating proof packet…', '✓ Proof: sha256:c9f2e5b8a1d3e6f9…\n\nRecommendation: Reroute to Port Antwerp. Estimated saving: $1.2M. Awaiting VP Operations approval.', ], 're-underwriting': [ '⟳ Loading CoStar comparable data…', '✓ 6 comps loaded for 45 Park Ave', '⟳ Checking lender covenant thresholds…', '✓ Covenant check: COMPLIANT (occupancy 89% vs 85% threshold)', '⟳ Running cap rate compression model…', '⚠ Cap rate compressed 28bps since Q4 2025', '⟳ Updating valuation model…', '✓ Portfolio value: +$4.2M vs last assessment', '⟳ Generating proof packet…', '✓ Proof: sha256:a1b2c3d4e5f6a7b8…\n\nUnderwriting complete. Risk score: 0.22 (LOW). Recommendation: Proceed with acquisition. Human approval required.', ], }; const EMBED_VERTICAL_MAP: Record = { Maritime: 'maritime', 'Real Estate': 'real-estate', Legal: 'legal', Platform: 'platform', Cyber: 'cyber', Defense: 'defense', Executive: 'executive', }; const EMBED_CONNECTORS: Record = { 'maritime-routing': ['AIS Live Feed', 'Port Standby Cost Model'], 're-underwriting': ['CoStar', 'Lender Covenant API'], 'legal-discovery': ['Docket Search', 'Document Repository'], 'cyber-triage': ['Threat Intelligence Feed', 'CVE Database', 'SIEM Events'], 'platform-health': ['Fabric Telemetry'], }; function EmbedRunner({ slug, vertical }: { slug: string; vertical: string }) { const [lines, setLines] = useState([]); const [running, setRunning] = useState(false); const [done, setDone] = useState(false); const bottomRef = useRef(null); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [lines]); async function run() { setLines([]); setDone(false); setRunning(true); try { const connectors = EMBED_CONNECTORS[slug] ?? []; const v = EMBED_VERTICAL_MAP[vertical] ?? 'cross-vertical'; const state = await createSpaceRun({ spaceSlug: slug, vertical: v, connectors, constitutionRef: 'embed-default', modelPolicy: 'governed-default', }); const finalState = await streamRunOutput( state.workcellId, (line) => setLines((prev) => [...prev, line]), { vertical: v, connectors, spaceSlug: slug }, ); const proof = await validateProof(finalState.workcellId, finalState.pceContractId); if (proof.proofRef) setLines((prev) => [...prev, `✓ Proof ref: ${proof.proofRef}`]); } catch (e) { setLines((prev) => [...prev, `✗ Run error: ${e instanceof Error ? e.message : String(e)}`]); } finally { setRunning(false); setDone(true); } } return (
{lines.length === 0 && !running && (
Click Run to execute in governed runtime.
)} {lines.map((l, i) => (
{l}
))} {running && }
{done && ✓ Proof generated}
); } export function AtelierEmbed({ spaceSlug, tenantId = 'szl', height = 340, compact = false, allowedOrigins }: AtelierEmbedProps) { const spaceInfo = EMBED_SPACES[spaceSlug] ?? { name: spaceSlug, vertical: 'Unknown', color: '#5e5e5e', description: 'A governed Atelier Space.', runtime: 'agent-loop', }; useEffect(() => { const allowlist = [...ALLOWED_EMBED_ORIGINS, ...(allowedOrigins ?? [])]; function handleMessage(e: MessageEvent) { if (e.data?.type === 'a11oy-space-handshake') { if (!isOriginAllowed(e.origin, allowlist)) { return; } e.source?.postMessage({ type: 'a11oy-space-ack', spaceSlug, tenantId, ready: true }, { targetOrigin: e.origin }); } } window.addEventListener('message', handleMessage); return () => window.removeEventListener('message', handleMessage); }, [spaceSlug, tenantId, allowedOrigins]); const BASE = (import.meta.env.BASE_URL ?? '/a11oy/').replace(/\/$/, ''); return (
{spaceInfo.name}
{!compact && (
{spaceInfo.vertical} · Atelier Space
)}
Governed
↗ Open
{!compact && (
)} {compact && (

{spaceInfo.description}

)}
Powered by A11oy Atelier · tenant: {tenantId}
); }