import type { Flow } from "@yaakapp-internal/proxy-lib"; import { useSetAtom } from "jotai"; import { useLayoutEffect, useMemo, useState } from "react"; import { FlowDetail } from "../components/FlowDetail"; import { FlowList } from "../components/FlowList"; import { ProxyEditorHost } from "../components/ProxyEditorHost"; import { MessageSourceContext } from "../hooks/useFlowMessages"; import { selectedFlowAtom } from "../lib/atoms"; import { flowWindowAtom } from "../lib/store"; import { fixtureSource, type StreamFixture, streamFixtures } from "./streamFixtures"; /** * Dev only: a streaming flow's detail, opened on its Messages tab, over fixtures served the way * the engine serves them. Open `/harness.html?stream=0&theme=dark`; add `&list` for the flow list * beside it, holding every fixture's flow. */ export function MessagesHarness() { const params = new URLSearchParams(location.search); const [index, setIndex] = useState(Number(params.get("stream") ?? 0)); const fixture = streamFixtures[index] ?? streamFixtures[0]; if (fixture == null) return null; return (
{streamFixtures.map((f, i) => ( ))}
); } /** Each fixture's flow as the list holds it, one after another, the shown one as it is now */ function listedFlows(shown: Flow): Flow[] { return streamFixtures.map((f, i) => { const flow = f.flow.id === shown.id ? shown : f.flow; return { ...flow, number: 1410 + i, startedAt: `2026-11-05T21:41:1${i}.000` }; }); } function StreamDetail({ fixture }: { fixture: StreamFixture }) { const source = useMemo(() => fixtureSource(fixture), [fixture]); const setSelected = useSetAtom(selectedFlowAtom); const setWindow = useSetAtom(flowWindowAtom); const [flow, setFlow] = useState(fixture.flow); const withList = new URLSearchParams(location.search).has("list"); useLayoutEffect(() => { const flows = listedFlows(flow); setWindow({ flows, hasOlder: false, total: flows.length }); setSelected(flows.find((f) => f.id === flow.id) ?? flow); }, [flow, setSelected, setWindow]); // The count on the flow follows its messages, as the engine writes it useLayoutEffect( () => source.subscribe(() => setFlow((f) => ({ ...f, messageCount: f.messageCount + 1 }))), [source], ); return ( {withList ? (
) : ( )}
); }