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
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { cn } from "@/lib/utils";
|
|
import { useAuiState } from "@assistant-ui/react";
|
|
import { memo, type FC, type PropsWithChildren } from "react";
|
|
|
|
type GroupedPartsGroup = {
|
|
indices: readonly number[];
|
|
};
|
|
|
|
export const ToolGroupImpl: FC<
|
|
PropsWithChildren<{ group: GroupedPartsGroup }>
|
|
> = ({ children, group }) => {
|
|
const startIndex = group.indices[0]!;
|
|
const endIndex = group.indices.at(-1)!;
|
|
|
|
const textBefore = useAuiState((s) => {
|
|
for (let i = startIndex - 1; i >= 0; i--) {
|
|
const type = s.message.parts[i]?.type;
|
|
if (type === "data") continue;
|
|
return type === "text";
|
|
}
|
|
return false;
|
|
});
|
|
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="tool-group"
|
|
className={cn(textBefore && "mt-4", textAfter && "mb-4")}
|
|
>
|
|
{children}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const ToolGroup = memo(ToolGroupImpl);
|