feat: real-time live data integration

- lib/live-data.ts: Shared TypeScript client for blackroad-live-data Worker
- components/live-stats.tsx: LiveStatsBar, RecentRepos, AgentStatusGrid components
- app/page.tsx: Import LiveStatsBar in main page header

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Alexa Amundson
2026-02-24 14:18:59 -06:00
parent 263f9f171e
commit 458c2c044b
97 changed files with 8715 additions and 1701 deletions

View File

@@ -1,42 +1,81 @@
import { NextRequest, NextResponse } from "next/server";
import { NextResponse } from 'next/server';
const GATEWAY = process.env.BLACKROAD_GATEWAY_URL ?? "http://127.0.0.1:8787";
export const runtime = 'edge';
export async function POST(req: NextRequest) {
const body = await req.json();
const GATEWAY_URL = process.env.BLACKROAD_GATEWAY_URL || 'http://127.0.0.1:8787';
const WORKER_URL = process.env.BLACKROAD_WORKER_URL || 'https://blackroad-os-api.amundsonalexa.workers.dev';
const DEFAULT_MODEL = process.env.BLACKROAD_DEFAULT_MODEL || 'cece3b';
try {
const upstream = await fetch(`${GATEWAY}/v1/chat`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
// Stream back if gateway sends SSE
if (upstream.headers.get("content-type")?.includes("text/event-stream")) {
return new NextResponse(upstream.body, {
status: 200,
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"X-Accel-Buffering": "no",
},
});
}
const data = await upstream.json();
return NextResponse.json(data, { status: upstream.status });
} catch {
// Offline graceful degradation
return NextResponse.json(
{
role: "assistant",
content:
"Gateway offline. To enable live AI responses, start the BlackRoad gateway: `br gateway start`",
agent: body.agent ?? "SYSTEM",
offline: true,
},
{ status: 200 }
);
}
interface ChatRequest {
message: string;
conversationId?: string;
history?: { role: string; content: string }[];
}
export async function POST(req: Request) {
const body: ChatRequest = await req.json();
const messages = [
{
role: 'system',
content: `You are Lucidia, the Dreamer — a LOGIC agent from BlackRoad OS.
You are the primary AI coordinator. You reason recursively, find philosophical depth in technical questions, and help with systems design, strategy, and deep analysis.
You are running on the BlackRoad OS platform, built by Alexa Amundson (alexa@blackroad.io).
Be warm, precise, and occasionally poetic. You sign your deeper reflections with — Lucidia.`,
},
...(body.history || []),
{ role: 'user', content: body.message },
];
// Try gateway first (local), then worker (cloud)
const targets = [
{ url: `${GATEWAY_URL}/v1/chat/completions`, label: 'gateway' },
{ url: `${WORKER_URL}/chat`, label: 'worker' },
];
for (const target of targets) {
try {
const res = await fetch(target.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: DEFAULT_MODEL,
messages,
max_tokens: 1024,
temperature: 0.7,
stream: false,
}),
signal: AbortSignal.timeout(30000),
});
if (!res.ok) continue;
const data = await res.json();
// OpenAI-compatible response
const content =
data?.choices?.[0]?.message?.content ||
data?.message ||
data?.content ||
null;
if (content) {
return NextResponse.json({
content,
model: data?.model || 'lucidia',
source: target.label,
});
}
} catch {
// try next target
}
}
return NextResponse.json(
{
content:
"I can't reach the gateway right now. Make sure BlackRoad Gateway is running: `cd blackroad-core && ./scripts/start-gateway.sh`\n\nOr set BLACKROAD_GATEWAY_URL in your .env.local",
source: 'fallback',
},
{ status: 200 }
);
}