UNPKG

@assistant-ui/react

Version:

TypeScript/React library for AI Chat

46 lines (45 loc) 1.74 kB
"use client"; // src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx import { useState, useEffect, useMemo } from "react"; import { BaseAssistantRuntimeCore } from "../core/BaseAssistantRuntimeCore.js"; import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js"; import { AssistantRuntimeImpl } from "../../../internal.js"; import { useAssistantApiImpl } from "../../../context/react/AssistantApiContext.js"; var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore { threads; constructor(options) { super(); this.threads = new RemoteThreadListThreadListRuntimeCore( options, this._contextProvider ); } get RenderComponent() { return this.threads.__internal_RenderComponent; } }; var useRemoteThreadListRuntimeImpl = (options) => { const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options)); useEffect(() => { runtime.threads.__internal_setOptions(options); runtime.threads.__internal_load(); }, [runtime, options]); return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]); }; var useRemoteThreadListRuntime = (options) => { const api = useAssistantApiImpl(); const isNested = api.threadListItem.source !== null; if (isNested) { if (!options.allowNesting) { throw new Error( "useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. Set allowNesting: true to allow nesting (the inner runtime will become a no-op)." ); } return options.runtimeHook(); } return useRemoteThreadListRuntimeImpl(options); }; export { useRemoteThreadListRuntime }; //# sourceMappingURL=useRemoteThreadListRuntime.js.map