@assistant-ui/react
Version:
TypeScript/React library for AI Chat
54 lines • 1.39 kB
JavaScript
// src/context/react/hooks/useAssistantState.tsx
import { useMemo, useSyncExternalStore, useDebugValue } from "react";
import {
useAssistantApi
} from "../AssistantApiContext.js";
var ProxiedAssistantState = class {
constructor(api) {
this.
}
get threads() {
return this.
}
get toolUIs() {
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.
}
};
var 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;
};
export {
useAssistantState
};
//# sourceMappingURL=useAssistantState.js.map