diff --git a/packages/react/src/context/providers/AssistantProvider.tsx b/packages/react/src/context/providers/AssistantProvider.tsx index 3dc0aa6f46..2a31f90fa0 100644 --- a/packages/react/src/context/providers/AssistantProvider.tsx +++ b/packages/react/src/context/providers/AssistantProvider.tsx @@ -8,6 +8,11 @@ import { makeAssistantModelConfigStore } from "../stores/AssistantModelConfig"; import { makeAssistantToolUIsStore } from "../stores/AssistantToolUIs"; import { ThreadProvider } from "./ThreadProvider"; import { makeAssistantActionsStore } from "../stores/AssistantActions"; +import { + AssistantRuntimeStore, + makeAssistantRuntimeStore, +} from "../stores/AssistantRuntime"; +import { StoreApi } from "zustand"; type AssistantProviderProps = { runtime: AssistantRuntime; @@ -22,11 +27,17 @@ export const AssistantProvider: FC< }); const [context] = useState(() => { + const useAssistantRuntime = makeAssistantRuntimeStore(runtime); const useModelConfig = makeAssistantModelConfigStore(); const useToolUIs = makeAssistantToolUIsStore(); const useAssistantActions = makeAssistantActionsStore(runtimeRef); - return { useModelConfig, useToolUIs, useAssistantActions }; + return { + useModelConfig, + useToolUIs, + useAssistantRuntime, + useAssistantActions, + }; }); const getModelConfig = context.useModelConfig(); @@ -34,6 +45,14 @@ export const AssistantProvider: FC< return runtime.registerModelConfigProvider(getModelConfig); }, [runtime, getModelConfig]); + useEffect( + () => + ( + context.useAssistantRuntime as unknown as StoreApi + ).setState(runtime, true), + [runtime, context], + ); + return ( {children} diff --git a/packages/react/src/context/react/AssistantContext.ts b/packages/react/src/context/react/AssistantContext.ts index c1a4bdbad5..72d8162266 100644 --- a/packages/react/src/context/react/AssistantContext.ts +++ b/packages/react/src/context/react/AssistantContext.ts @@ -5,10 +5,12 @@ import type { AssistantModelConfigState } from "../stores/AssistantModelConfig"; import type { AssistantToolUIsState } from "../stores/AssistantToolUIs"; import { ReadonlyStore } from "../ReadonlyStore"; import { AssistantActionsState } from "../stores/AssistantActions"; +import { AssistantRuntime } from "../../runtimes"; export type AssistantContextValue = { useModelConfig: ReadonlyStore; useToolUIs: ReadonlyStore; + useAssistantRuntime: ReadonlyStore; useAssistantActions: ReadonlyStore; }; diff --git a/packages/react/src/context/stores/AssistantRuntime.tsx b/packages/react/src/context/stores/AssistantRuntime.tsx new file mode 100644 index 0000000000..b290745a4a --- /dev/null +++ b/packages/react/src/context/stores/AssistantRuntime.tsx @@ -0,0 +1,8 @@ +import { create } from "zustand"; +import { AssistantRuntime } from "../../runtimes"; + +export type AssistantRuntimeStore = AssistantRuntime; + +export const makeAssistantRuntimeStore = (runtime: AssistantRuntime) => { + return create(() => runtime); +};