@assistant-ui/react
Version:
TypeScript/React library for AI Chat
42 lines • 1.37 kB
JavaScript
import { useMemo, useSyncExternalStore, useDebugValue } from "react";
import { useAssistantApi, } from "../AssistantApiContext.js";
class ProxiedAssistantState {
constructor(api) {
this.
}
get threads() {
return this.
}
get tools() {
return this.
}
get threadListItem() {
return this.
}
get thread() {
return this.
}
get composer() {
return this.
}
get message() {
return this.
}
get part() {
return this.
}
get attachment() {
return this.
}
}
export const useAssistantState = (selector) => {
const api = useAssistantApi();
const proxiedState = useMemo(() => new ProxiedAssistantState(api), [api]);
const slice = useSyncExternalStore(api.subscribe, () => selector(proxiedState), () => selector(proxiedState));
useDebugValue(slice);
if (slice instanceof ProxiedAssistantState)
throw new Error("You tried to return the entire AssistantState. This is not supported due to technical limitations.");
return slice;
};
//# sourceMappingURL=useAssistantState.js.map