Files
wehub-resource-sync e30e75b5d4
Code Quality / Oxlint + Oxfmt (push) Waiting to run
Code Quality / Template Sync (push) Waiting to run
Code Quality / Build Changed Packages (push) Waiting to run
Code Quality / Test Changed Packages (push) Waiting to run
Deploy Expo Example / Deploy Production (push) Waiting to run
Deploy Ink Example / Deploy Production (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.12) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Waiting to run
Deploy Shadcn Registry / Deploy Production (push) Waiting to run
Template Metrics / LOC + Bundle Size (push) Waiting to run
Changesets / Create Version PR (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

56 lines
1.5 KiB
TypeScript

"use client";
import { memo, type FC, type PropsWithChildren } from "react";
import { BrainIcon } from "lucide-react";
import { useAuiState } from "@assistant-ui/react";
import { cn } from "@/lib/utils";
type GroupedPartsGroup = {
indices: readonly number[];
};
const ReasoningGroupImpl: FC<
PropsWithChildren<{ group: GroupedPartsGroup }>
> = ({ children, group }) => {
const startIndex = group.indices[0]!;
const endIndex = group.indices.at(-1)!;
const isMultiLine = useAuiState((s) => {
let totalLength = 0;
for (let i = startIndex; i <= endIndex; i++) {
const part = s.message.parts[i];
if (part?.type === "reasoning") {
if (part.text.includes("\n\n")) return true;
totalLength += part.text.length;
}
}
return totalLength > 120;
});
const textAfter = useAuiState((s) => {
for (let i = endIndex + 1; i < s.message.parts.length; i++) {
const type = s.message.parts[i]?.type;
if (type === "data") continue;
return type === "text";
}
return false;
});
return (
<div
data-slot="reasoning-group"
className={cn(
"text-muted-foreground mt-4 mb-2 flex items-start gap-2 text-sm leading-relaxed first:mt-0",
isMultiLine && "mt-6 mb-4",
textAfter && "mb-4",
)}
>
<BrainIcon className="mt-[3.25px] size-3.5 shrink-0" />
<div className="space-y-4.5">{children}</div>
</div>
);
};
export const ReasoningGroup = memo(ReasoningGroupImpl);
ReasoningGroup.displayName = "ReasoningGroup";