Files
package-agent-presentation/src/thread.tsx
T

24 lines
867 B
TypeScript

import { useEffect, useMemo } from "react";
import { AgentWidget } from "./widget.js";
import type { Modules } from "./gen/client.js";
import { ThreadView } from "./shared.js";
import { HttpThreadController } from "./http.js";
import type { Thread as ThreadData } from "./protocol.js";
import "./thread.css";
export const Thread: Modules["Thread"] = ({ subject, input }) => {
const controller = useMemo(
() =>
new HttpThreadController(
subject.object,
JSON.parse(
JSON.stringify(input.body.root, (_key, value) => (typeof value === "bigint" ? value.toString() : value)),
) as ThreadData,
),
[subject.object],
);
useEffect(() => () => controller.close(), [controller]);
return (
<ThreadView thread={subject.object} controller={controller} renderWidget={(item) => <AgentWidget item={item} />} />
);
};