@liveblocks/react 2.25.0-aiprivatebeta9 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,60 +0,0 @@
1
- import {
2
- useClient
3
- } from "./chunk-TMKZ6U2Y.js";
4
-
5
- // src/version.ts
6
- var PKG_NAME = "@liveblocks/react";
7
- var PKG_VERSION = "2.25.0-aiprivatebeta9";
8
- var PKG_FORMAT = "esm";
9
-
10
- // src/ClientSideSuspense.tsx
11
- import { Suspense, useEffect, useState } from "react";
12
- import { jsx } from "react/jsx-runtime";
13
- function ClientSideSuspense(props) {
14
- const [mounted, setMounted] = useState(false);
15
- useEffect(() => {
16
- setMounted(true);
17
- }, []);
18
- return /* @__PURE__ */ jsx(Suspense, { fallback: props.fallback, children: mounted ? typeof props.children === "function" ? props.children() : props.children : props.fallback });
19
- }
20
-
21
- // src/ai.tsx
22
- import { kInternal, nanoid } from "@liveblocks/core";
23
- import { memo, useEffect as useEffect2, useId, useState as useState2 } from "react";
24
- function useAi() {
25
- return useClient()[kInternal].ai;
26
- }
27
- function useRandom() {
28
- return useState2(nanoid)[0];
29
- }
30
- var RegisterAiKnowledge = memo(function RegisterAiKnowledge2(props) {
31
- const layerId = useId();
32
- const ai = useAi();
33
- const { description, value } = props;
34
- const [layerKey, setLayerKey] = useState2();
35
- useEffect2(() => {
36
- const layerKey2 = ai.registerKnowledgeLayer(layerId);
37
- setLayerKey(layerKey2);
38
- return () => {
39
- ai.deregisterKnowledgeLayer(layerKey2);
40
- setLayerKey(void 0);
41
- };
42
- }, [ai, layerId]);
43
- const randomKey = useRandom();
44
- const knowledgeKey = props.id ?? randomKey;
45
- useEffect2(() => {
46
- if (layerKey !== void 0) {
47
- ai.updateKnowledge(layerKey, { description, value }, knowledgeKey);
48
- }
49
- }, [ai, layerKey, knowledgeKey, description, value]);
50
- return null;
51
- });
52
-
53
- export {
54
- PKG_NAME,
55
- PKG_VERSION,
56
- PKG_FORMAT,
57
- ClientSideSuspense,
58
- RegisterAiKnowledge
59
- };
60
- //# sourceMappingURL=chunk-Z2N4O6IQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/version.ts","../src/ClientSideSuspense.tsx","../src/ai.tsx"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import type { ReactNode } from \"react\";\nimport { Suspense, useEffect, useState } from \"react\";\n\ntype Props = {\n fallback: ReactNode;\n children: (() => ReactNode | undefined) | ReactNode | undefined;\n};\n\n/**\n * Almost like a normal <Suspense> component, except that for server-side\n * renders, the fallback will be used.\n *\n * The child props will have to be provided in a function, i.e. change:\n *\n * <Suspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </Suspense>\n *\n * To:\n *\n * <ClientSideSuspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </ClientSideSuspense>\n *\n */\nexport function ClientSideSuspense(props: Props) {\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n // Effects are never executed on the server side. The point of this is to\n // delay the flipping of this boolean until after hydration has happened.\n setMounted(true);\n }, []);\n\n return (\n <Suspense fallback={props.fallback}>\n {mounted\n ? typeof props.children === \"function\"\n ? props.children()\n : props.children\n : props.fallback}\n </Suspense>\n );\n}\n","import type { AiKnowledgeSource } from \"@liveblocks/core\";\nimport { kInternal, nanoid } from \"@liveblocks/core\";\nimport { memo, useEffect, useId, useState } from \"react\";\n\nimport { useClient } from \"./liveblocks\";\n\nfunction useAi() {\n return useClient()[kInternal].ai;\n}\n\nfunction useRandom() {\n return useState(nanoid)[0];\n}\n\n/**\n * Make knowledge about your application state available to any AI used in\n * a chat or a one-off request.\n *\n * For example:\n *\n * <RegisterAiKnowledge\n * description=\"The current mode of my application\"\n * value=\"dark\" />\n *\n * <RegisterAiKnowledge\n * description=\"The current list of todos\"\n * value={todos} />\n *\n * By mounting this component, the AI will get access to this knwoledge.\n * By unmounting this component, the AI will no longer have access to it.\n * It can choose to use or ignore this knowledge in its responses.\n */\nexport const RegisterAiKnowledge = memo(function RegisterAiKnowledge(\n props: AiKnowledgeSource & {\n /**\n * An optional unique key for this knowledge source. If multiple components\n * register knowledge under the same key, the last one to mount takes\n * precedence.\n */\n id?: string;\n }\n) {\n const layerId = useId();\n const ai = useAi();\n const { description, value } = props;\n\n const [layerKey, setLayerKey] = useState<\n ReturnType<typeof ai.registerKnowledgeLayer> | undefined\n >();\n\n // Executes at mount / unmount\n useEffect(() => {\n const layerKey = ai.registerKnowledgeLayer(layerId);\n setLayerKey(layerKey);\n return () => {\n ai.deregisterKnowledgeLayer(layerKey);\n setLayerKey(undefined);\n };\n }, [ai, layerId]);\n\n // Executes every render (if the props have changed)\n const randomKey = useRandom();\n const knowledgeKey = props.id ?? randomKey;\n useEffect(() => {\n if (layerKey !== undefined) {\n ai.updateKnowledge(layerKey, { description, value }, knowledgeKey);\n }\n }, [ai, layerKey, knowledgeKey, description, value]);\n\n return null;\n});\n"],"mappings":";;;;;AAGO,IAAM,WAAW;AACjB,IAAM,cAAiD;AACvD,IAAM,aAAgD;;;ACJ7D,SAAS,UAAU,WAAW,gBAAgB;AAkC1C;AAVG,SAAS,mBAAmB,OAAc;AAC/C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,YAAU,MAAM;AAGd,eAAW,IAAI;AAAA,EACjB,GAAG,CAAC,CAAC;AAEL,SACE,oBAAC,YAAS,UAAU,MAAM,UACvB,oBACG,OAAO,MAAM,aAAa,aACxB,MAAM,SAAS,IACf,MAAM,WACR,MAAM,UACZ;AAEJ;;;AC1CA,SAAS,WAAW,cAAc;AAClC,SAAS,MAAM,aAAAA,YAAW,OAAO,YAAAC,iBAAgB;AAIjD,SAAS,QAAQ;AACf,SAAO,UAAU,EAAE,SAAS,E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