47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { StreamingTokenResponse } from "../components/streaming-token-response";
|
|
import { AnswerUiView, type AnswerUiMapTarget } from "./answer-ui-view";
|
|
import type { AnswerUiPart } from "./contract";
|
|
|
|
export function AnswerPartsView({
|
|
parts,
|
|
messageId,
|
|
disabled,
|
|
streaming,
|
|
streamDone,
|
|
onLocate,
|
|
onSubmit
|
|
}: {
|
|
parts: AnswerUiPart[];
|
|
messageId: string;
|
|
disabled: boolean;
|
|
streaming: boolean;
|
|
streamDone: boolean;
|
|
onLocate?: (target: AnswerUiMapTarget) => Promise<unknown> | void;
|
|
onSubmit?: (text: string) => Promise<void> | void;
|
|
}) {
|
|
return (
|
|
<div className="space-y-4">
|
|
{parts.map((part, index) =>
|
|
part.type === "answer-ui" ? (
|
|
<AnswerUiView
|
|
key={`ui-${part.block.block_id}`}
|
|
block={part.block}
|
|
disabled={disabled}
|
|
onLocate={onLocate}
|
|
onSubmit={onSubmit}
|
|
/>
|
|
) : (
|
|
<StreamingTokenResponse
|
|
key={`text-${index}`}
|
|
className="leading-6"
|
|
content={part.text}
|
|
messageId={`${messageId}-${index}`}
|
|
streamDone={streamDone}
|
|
streaming={streaming}
|
|
/>
|
|
)
|
|
)}
|
|
</div>
|
|
);
|
|
}
|