@assistant-ui/react
Version:
Typescript/React library for AI Chat
1 lines • 1.88 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { AttachmentContext } from \"../react/AttachmentContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AttachmentRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: AttachmentRuntime;\n }>;\n}\n\nconst useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);\n const [context] = useState(() => {\n return {\n useAttachmentRuntime,\n };\n });\n\n return (\n <AttachmentContext.Provider value={context}>\n {children}\n </AttachmentContext.Provider>\n );\n};\n"],"mappings":";;;AAEA,SAA0C,WAAW,gBAAgB;AACrE,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AAgC1B;AAxBJ,IAAM,4BAA4B,CAAC,YAA+B;AAChE,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AAErB,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,4BAAiE,CAAC;AAAA,EAC7E;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAuB,0BAA0B,OAAO;AAC9D,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF,CAAC;AAED,SACE,oBAAC,kBAAkB,UAAlB,EAA2B,OAAO,SAChC,UACH;AAEJ;","names":[]}