UNPKG

@assistant-ui/react

Version:

TypeScript/React library for AI Chat

39 lines 1.8 kB
"use client"; 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"; class RemoteThreadListRuntimeCore extends BaseAssistantRuntimeCore { threads; constructor(options) { super(); this.threads = new RemoteThreadListThreadListRuntimeCore(options, this._contextProvider); } get RenderComponent() { return this.threads.__internal_RenderComponent; } } const 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]); }; export const 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)."); } // If allowNesting is true and already inside a thread list context, // just call the runtimeHook directly (no-op behavior) return options.runtimeHook(); } return useRemoteThreadListRuntimeImpl(options); }; //# sourceMappingURL=useRemoteThreadListRuntime.js.map