@assistant-ui/react
Version:
TypeScript/React library for AI Chat
29 lines (25 loc) • 926 B
text/typescript
"use client";
import { ThreadListItemRuntime } from "../runtime/ThreadListItemRuntime";
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
import { useAssistantApi } from "../../context/react";
export function useThreadListItemRuntime(options?: {
optional?: false | undefined;
}): ThreadListItemRuntime;
export function useThreadListItemRuntime(options?: {
optional?: boolean | undefined;
}): ThreadListItemRuntime | null;
export function useThreadListItemRuntime(options?: {
optional?: boolean | undefined;
}) {
const api = useAssistantApi();
const runtime = api.threadListItem.source
? api.threadListItem().__internal_getRuntime()
: null;
if (!runtime && !options?.optional) {
throw new Error("ThreadListItemRuntime is not available");
}
return runtime;
}
export const useThreadListItem = createStateHookForRuntime(
useThreadListItemRuntime,
);