repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
The Living OS cockpit
stars
latest
clone command
git clone gitlawb://did:key:z6Mku78K...XywC/living-os-cockp...git clone gitlawb://did:key:z6Mku78K.../living-os-cockp...59751530feat: surface worker supervisor health in live work8h ago| #1 | import { NextRequest, NextResponse } from 'next/server'; |
| #2 | import { authErrorResponse, CANONICAL_KING_ID, getUserContext } from '@/lib/user-context'; |
| #3 | import { COUNCIL_ROSTER, appendCouncilMessages, draftCouncilResponse, ensureCouncilBootMessages, readCouncilMessages } from '@/lib/council-bus'; |
| #4 | |
| #5 | export const runtime = 'nodejs'; |
| #6 | export const dynamic = 'force-dynamic'; |
| #7 | |
| #8 | function cleanPrompt(value: unknown) { |
| #9 | return String(value ?? '').replace(/\s+/g, ' ').trim(); |
| #10 | } |
| #11 | |
| #12 | export async function GET() { |
| #13 | try { |
| #14 | const ctx = await getUserContext(); |
| #15 | if (ctx.canonicalMemberId !== CANONICAL_KING_ID) { |
| #16 | return NextResponse.json({ ok: false, error: 'admin_required' }, { status: 403 }); |
| #17 | } |
| #18 | await ensureCouncilBootMessages(); |
| #19 | const messages = await readCouncilMessages(160); |
| #20 | return NextResponse.json({ |
| #21 | ok: true, |
| #22 | roster: COUNCIL_ROSTER, |
| #23 | rooms: ['convene-all', ...COUNCIL_ROSTER.map(agent => agent.id)], |
| #24 | messages, |
| #25 | }); |
| #26 | } catch (error) { |
| #27 | try { |
| #28 | return authErrorResponse(error); |
| #29 | } catch { |
| #30 | return NextResponse.json({ ok: false, error: error instanceof Error ? error.message : String(error) }, { status: 500 }); |
| #31 | } |
| #32 | } |
| #33 | } |
| #34 | |
| #35 | export async function POST(req: NextRequest) { |
| #36 | try { |
| #37 | const ctx = await getUserContext(); |
| #38 | if (ctx.canonicalMemberId !== CANONICAL_KING_ID) { |
| #39 | return NextResponse.json({ ok: false, error: 'admin_required' }, { status: 403 }); |
| #40 | } |
| #41 | const body = await req.json().catch(() => ({})); |
| #42 | const prompt = cleanPrompt(body.prompt); |
| #43 | if (!prompt) { |
| #44 | return NextResponse.json({ ok: false, error: 'prompt_required' }, { status: 400 }); |
| #45 | } |
| #46 | await ensureCouncilBootMessages(); |
| #47 | const messages = draftCouncilResponse(prompt); |
| #48 | await appendCouncilMessages(messages); |
| #49 | return NextResponse.json({ |
| #50 | ok: true, |
| #51 | appended: messages.length, |
| #52 | messages: await readCouncilMessages(160), |
| #53 | roster: COUNCIL_ROSTER, |
| #54 | }); |
| #55 | } catch (error) { |
| #56 | try { |
| #57 | return authErrorResponse(error); |
| #58 | } catch { |
| #59 | return NextResponse.json({ ok: false, error: error instanceof Error ? error.message : String(error) }, { status: 500 }); |
| #60 | } |
| #61 | } |
| #62 | } |
| #63 |