@assistant-ui/react
Version:
TypeScript/React library for AI Chat
19 lines • 847 B
JavaScript
"use client";
import { useEffect, useMemo, useState } from "react";
import { ExternalStoreRuntimeCore } from "./ExternalStoreRuntimeCore.js";
import { AssistantRuntimeImpl, } from "../../runtime/AssistantRuntime.js";
import { useRuntimeAdapters } from "../adapters/RuntimeAdapterProvider.js";
export const useExternalStoreRuntime = (store) => {
const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));
useEffect(() => {
runtime.setAdapter(store);
});
const { modelContext } = useRuntimeAdapters() ?? {};
useEffect(() => {
if (!modelContext)
return undefined;
return runtime.registerModelContextProvider(modelContext);
}, [modelContext, runtime]);
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
};
//# sourceMappingURL=useExternalStoreRuntime.js.map