Files
archie/ui/astryx-reference/main.tsx
T
sam a0d14090ef feat: add astryx design reference prototype
- scaffold a React/Vite reference app under ui/astryx-reference with shell, composer, runs, and area pages
- wire @astryxdesign packages, a neutral-derived theme, and reference dev/build scripts
- document the astryx workflow in ui/AGENTS.md
2026-11-19 17:36:22 +11:00

153 lines
5.1 KiB
TypeScript

import { useState } from "react";
import { createRoot } from "react-dom/client";
import { Theme } from "@astryxdesign/core/theme";
import "@astryxdesign/core/reset.css";
import "@astryxdesign/core/astryx.css";
import { AreaPage } from "./AreaPage";
import { DockedComposer } from "./DockedComposer";
import { ShellFrame, type Area } from "./ShellFrame";
import LandingPage from "./pages/LandingPage";
import ConversationPage, {
type ConversationMessage,
} from "./pages/ConversationPage";
import RunsPage, { type RunDecision } from "./pages/RunsPage";
import { theme } from "./theme";
const answers = [
{
test: /decision|approval|blocked|waiting/i,
text: "One run needs a decision. The checkout investigation recommends a rollback after timeouts rose from 0.4% to 8.1%. Production policy requires your approval before anything changes.",
},
{
test: /risk|impact|go wrong/i,
text: "The rollback carries moderate risk because checkout may briefly lose capacity while the release changes. It is reversible: the current release can be reapplied, and no database change is proposed.",
},
{
test: /declin(e|es|ed|ing)|deny|reject/i,
text: "Declining stops the run before any production change. Archie records the exact decision and evidence; checkout remains unchanged and the timeout investigation remains unresolved.",
},
{
test: /checkout|tim(e|ing)? out/i,
text: "Only checkout is affected. Timeouts rose four minutes after the 09:34 release. That release is the leading suspect, not a confirmed cause. The proposed rollback is reversible and does not change the database.",
},
{
test: /today|did archie|what happened/i,
text: "Archie authenticated the checkout alert, investigated the timeout spike, assessed the proposed rollback, and delivered the evidence for review. Nothing changed in production.",
},
] as const;
function answerFor(prompt: string) {
return (
answers.find(({ test }) => test.test(prompt))?.text ??
"I can explain this page, open a run, or help you review the evidence and policy behind it. This reference does not start live work."
);
}
function App() {
const [activeArea, setActiveArea] = useState<Area>("Composer");
const [draft, setDraft] = useState("");
const [messages, setMessages] = useState<ConversationMessage[]>([]);
const [decision, setDecision] = useState<RunDecision>("pending");
function submit(prompt: string) {
const value = prompt.trim();
if (!value) return;
const id = crypto.randomUUID();
setMessages((current) => [
...current,
{ id: `${id}-user`, sender: "user", text: value },
{ id: `${id}-archie`, sender: "assistant", text: answerFor(value) },
]);
setDraft("");
}
function recordDecision(next: RunDecision) {
setDecision(next);
const outcome =
next === "approved"
? "The operator approved the checkout rollback. This reference would now execute the exact approved action and verify the timeout rate."
: "The operator declined the checkout rollback. No production change was made, and the run stopped at the decision.";
setMessages((current) => [
...current,
{
id: crypto.randomUUID(),
sender: "assistant",
text: outcome,
},
]);
}
const dockedComposer = (
<DockedComposer
context={
activeArea === "Runs"
? "Runs · checkout rollback"
: `${activeArea} · same conversation`
}
messages={messages}
draft={draft}
onDraftChange={setDraft}
onSubmit={submit}
onOpenConversation={() => setActiveArea("Composer")}
/>
);
return (
<ShellFrame
activeArea={activeArea}
pendingCount={decision === "pending" ? 1 : 0}
onNavigate={setActiveArea}
dock={
activeArea !== "Composer" && activeArea !== "Runs"
? dockedComposer
: undefined
}
>
{activeArea === "Composer" &&
(messages.length === 0 ? (
<LandingPage
draft={draft}
onDraftChange={setDraft}
onSubmit={submit}
onNavigate={(area) => {
const destination = {
composer: "Composer",
runs: "Runs",
events: "Events",
governance: "Governance",
reports: "Reports",
} as const;
setActiveArea(destination[area]);
}}
/>
) : (
<ConversationPage
messages={messages}
draft={draft}
onDraftChange={setDraft}
onSubmit={submit}
onOpenRun={() => setActiveArea("Runs")}
decision={decision}
/>
))}
{activeArea === "Runs" && (
<RunsPage
composer={dockedComposer}
decision={decision}
onDecision={recordDecision}
/>
)}
{activeArea !== "Composer" && activeArea !== "Runs" && (
<AreaPage area={activeArea} onOpenRun={() => setActiveArea("Runs")} />
)}
</ShellFrame>
);
}
createRoot(document.getElementById("root")!).render(
<Theme theme={theme}>
<App />
</Theme>,
);