UNPKG

@assistant-ui/react

Version:

React components for AI chat.

42 lines (41 loc) 1.14 kB
"use client"; // src/runtimes/local/useLocalRuntime.tsx import { useEffect, useMemo, useState } from "react"; import { LocalRuntimeCore } from "./LocalRuntimeCore.mjs"; import { AssistantRuntimeImpl } from "../../api/AssistantRuntime.mjs"; import { ThreadRuntimeImpl } from "../../internal.mjs"; var LocalRuntimeImpl = class _LocalRuntimeImpl extends AssistantRuntimeImpl { constructor(core, thread) { super(core, thread); this.core = core; } reset(options) { this.core.reset(options); } static create(_core) { return new _LocalRuntimeImpl( _core, AssistantRuntimeImpl.createMainThreadRuntime(_core, ThreadRuntimeImpl) ); } }; var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => { const opt = { ...options, adapters: { ...options.adapters, chatModel: adapter } }; const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages)); useEffect(() => { runtime.setOptions(opt); }); return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]); }; export { useLocalRuntime }; //# sourceMappingURL=useLocalRuntime.mjs.map