@assistant-ui/react
Version:
Typescript/React library for AI Chat
1 lines • 2.68 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/context/providers/ThreadRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport type { ThreadContextValue } from \"../react/ThreadContext\";\nimport { ThreadContext } from \"../react/ThreadContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { create } from \"zustand\";\nimport { ThreadListItemRuntime } from \"../../api/ThreadListItemRuntime\";\nimport { ThreadListItemRuntimeProvider } from \"./ThreadListItemRuntimeProvider\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\nimport { ThreadViewportProvider } from \"./ThreadViewportProvider\";\n\ntype ThreadProviderProps = {\n listItemRuntime: ThreadListItemRuntime;\n runtime: ThreadRuntime;\n};\n\nconst useThreadRuntimeStore = (runtime: ThreadRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n ensureBinding(runtime.composer);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const ThreadRuntimeProvider: FC<\n PropsWithChildren<ThreadProviderProps>\n> = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {\n const useThreadRuntime = useThreadRuntimeStore(runtime);\n\n const [context] = useState<ThreadContextValue>(() => {\n return {\n useThreadRuntime,\n };\n });\n\n return (\n <ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>\n <ThreadContext.Provider value={context}>\n {/* TODO temporarily allow accessing viewport state from outside the viewport */}\n {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}\n <ThreadViewportProvider>{children}</ThreadViewportProvider>\n </ThreadContext.Provider>\n </ThreadListItemRuntimeProvider>\n );\n};\n"],"mappings":";;;AAGA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAE9B,SAAS,cAAc;AAEvB,SAAS,qCAAqC;AAC9C,SAAS,qBAAqB;AAC9B,SAAS,8BAA8B;AAoC/B;AA7BR,IAAM,wBAAwB,CAAC,YAA2B;AACxD,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AACrB,kBAAc,QAAQ,QAAQ;AAE9B,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,wBAET,CAAC,EAAE,UAAU,iBAAiB,uBAAuB,QAAQ,MAAM;AACrE,QAAM,mBAAmB,sBAAsB,OAAO;AAEtD,QAAM,CAAC,OAAO,IAAI,SAA6B,MAAM;AACnD,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,oBAAC,iCAA8B,SAAS,uBACtC,8BAAC,cAAc,UAAd,EAAuB,OAAO,SAG7B,8BAAC,0BAAwB,UAAS,GACpC,GACF;AAEJ;","names":[]}