UNPKG

@assistant-ui/react

Version:

TypeScript/React library for AI Chat

38 lines 1.34 kB
"use client"; import { createActionButton, } from "../../utils/createActionButton.js"; import { useCallback } from "react"; import { useAssistantState, useAssistantApi } from "../../context/index.js"; const useBranchPickerNext = () => { const api = useAssistantApi(); const disabled = useAssistantState(({ thread, message }) => { // Disabled if no next branch if (message.branchNumber >= message.branchCount) return true; // Disabled if running and capability not supported if (thread.isRunning && !thread.capabilities.switchBranchDuringRun) { return true; } return false; }); const callback = useCallback(() => { api.message().switchToBranch({ position: "next" }); }, [api]); if (disabled) return null; return callback; }; /** * A button component that navigates to the next branch in the message tree. * * This component automatically handles switching to the next available branch * and is disabled when there are no more branches to navigate to. * * @example * ```tsx * <BranchPickerPrimitive.Next> * Next → * </BranchPickerPrimitive.Next> * ``` */ export const BranchPickerPrimitiveNext = createActionButton("BranchPickerPrimitive.Next", useBranchPickerNext); //# sourceMappingURL=BranchPickerNext.js.map