@sanity/embeddings-index-ui 1.0.2 → 1.0.3
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.
- package/dist/index.esm.js +67 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +65 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/isEnabled.tsx +53 -0
- package/src/embeddingsIndexDashboard/EmbeddingsIndexTool.tsx +11 -1
- package/src/referenceInput/SemanticSearchReferenceInput.tsx +25 -2
- package/src/referenceInput/referencePlugin.tsx +8 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useSchema, DefaultPreview, useDocumentPreviewStore, SanityDefaultPreview, getPreviewValueWithFallback, getPreviewStateObservable, useClient, typed, unset, setIfMissing, set, definePlugin, isObjectInputProps } from 'sanity';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import { Card, Button, Box, Flex,
|
|
3
|
+
import { Card, Button, Box, Text, Flex, Spinner, Autocomplete, Stack, Label, TextInput, TextArea, Dialog, Heading, MenuButton, Menu, MenuItem } from '@sanity/ui';
|
|
4
4
|
import { ErrorOutlineIcon, EarthGlobeIcon, LinkIcon, AddIcon, SearchIcon, EllipsisVerticalIcon, TrashIcon, UndoIcon } from '@sanity/icons';
|
|
5
|
-
import require$$0, { useMemo, useRef, useEffect, useState, useCallback, useId } from 'react';
|
|
5
|
+
import require$$0, { useMemo, useRef, useEffect, createContext, useState, useContext, useCallback, useId } from 'react';
|
|
6
6
|
import { useIntentLink } from 'sanity/router';
|
|
7
7
|
import { useDocumentPane } from 'sanity/desk';
|
|
8
8
|
|
|
@@ -1895,11 +1895,56 @@ function useApiClient() {
|
|
|
1895
1895
|
return client;
|
|
1896
1896
|
}, [client]);
|
|
1897
1897
|
}
|
|
1898
|
+
const featureName = "embeddingsIndexApi";
|
|
1899
|
+
const FeatureEnabledContext = createContext("loading");
|
|
1900
|
+
function useIsFeatureEnabled() {
|
|
1901
|
+
const client = useClient({
|
|
1902
|
+
apiVersion: "2023-09-01"
|
|
1903
|
+
});
|
|
1904
|
+
const [status, setStatus] = useState("loading");
|
|
1905
|
+
useEffect(() => {
|
|
1906
|
+
client.request({
|
|
1907
|
+
method: "GET",
|
|
1908
|
+
url: "/projects/".concat(client.config().projectId, "/features/").concat(featureName)
|
|
1909
|
+
}).then(isEnabled => {
|
|
1910
|
+
setStatus(isEnabled === "true" || isEnabled === true ? "enabled" : "disabled");
|
|
1911
|
+
}).catch(err => {
|
|
1912
|
+
console.error(err);
|
|
1913
|
+
setStatus("disabled");
|
|
1914
|
+
});
|
|
1915
|
+
}, [client]);
|
|
1916
|
+
return status;
|
|
1917
|
+
}
|
|
1918
|
+
function FeatureEnabledProvider(props) {
|
|
1919
|
+
const status = useIsFeatureEnabled();
|
|
1920
|
+
return /* @__PURE__ */jsx(FeatureEnabledContext.Provider, {
|
|
1921
|
+
value: status,
|
|
1922
|
+
children: props.children
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
function useIsFeatureEnabledContext() {
|
|
1926
|
+
return useContext(FeatureEnabledContext);
|
|
1927
|
+
}
|
|
1928
|
+
function FeatureDisabledNotice() {
|
|
1929
|
+
return /* @__PURE__ */jsx(Card, {
|
|
1930
|
+
tone: "primary",
|
|
1931
|
+
border: true,
|
|
1932
|
+
padding: 2,
|
|
1933
|
+
children: /* @__PURE__ */jsxs(Text, {
|
|
1934
|
+
size: 1,
|
|
1935
|
+
children: ["Embeddings index APIs are only available on the", " ", /* @__PURE__ */jsx("a", {
|
|
1936
|
+
href: "https://sanity.io/pricing",
|
|
1937
|
+
children: "Team tier and above"
|
|
1938
|
+
}), ". Please upgrade to enable access."]
|
|
1939
|
+
})
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1898
1942
|
const NO_OPTIONS = [];
|
|
1899
1943
|
const NO_FILTER = () => true;
|
|
1900
1944
|
function SemanticSearchReferenceInput(props) {
|
|
1901
1945
|
var _a, _b, _c;
|
|
1902
1946
|
const defaultEnabled = ((_c = (_b = (_a = props.schemaType) == null ? void 0 : _a.options) == null ? void 0 : _b.embeddingsIndex) == null ? void 0 : _c.searchMode) === "embeddings";
|
|
1947
|
+
const featureState = useIsFeatureEnabledContext();
|
|
1903
1948
|
const [semantic, setSemantic] = useState(defaultEnabled);
|
|
1904
1949
|
const toggleSemantic = useCallback(() => setSemantic(current => !current), []);
|
|
1905
1950
|
return /* @__PURE__ */jsxs(Flex, {
|
|
@@ -1908,13 +1953,16 @@ function SemanticSearchReferenceInput(props) {
|
|
|
1908
1953
|
style: {
|
|
1909
1954
|
width: "100%"
|
|
1910
1955
|
},
|
|
1911
|
-
children: [/* @__PURE__ */jsx(Box, {
|
|
1956
|
+
children: [semantic && featureState == "loading" ? /* @__PURE__ */jsx(Box, {
|
|
1957
|
+
padding: 2,
|
|
1958
|
+
children: /* @__PURE__ */jsx(Spinner, {})
|
|
1959
|
+
}) : null, semantic && featureState == "disabled" ? /* @__PURE__ */jsx(FeatureDisabledNotice, {}) : null, /* @__PURE__ */jsx(Box, {
|
|
1912
1960
|
flex: 1,
|
|
1913
1961
|
style: {
|
|
1914
1962
|
maxHeight: 36,
|
|
1915
1963
|
overflow: "hidden"
|
|
1916
1964
|
},
|
|
1917
|
-
children: semantic ? /* @__PURE__ */jsx(SemanticSearchInput, {
|
|
1965
|
+
children: semantic && featureState == "enabled" ? /* @__PURE__ */jsx(SemanticSearchInput, {
|
|
1918
1966
|
...props
|
|
1919
1967
|
}) : props.renderDefault(props)
|
|
1920
1968
|
}), /* @__PURE__ */jsx(Button, {
|
|
@@ -2080,6 +2128,15 @@ function isType(schemaType, typeName) {
|
|
|
2080
2128
|
}
|
|
2081
2129
|
const embeddingsIndexReferenceInput = definePlugin({
|
|
2082
2130
|
name: "@sanity/embeddings-index-reference-input",
|
|
2131
|
+
studio: {
|
|
2132
|
+
components: {
|
|
2133
|
+
layout: props => {
|
|
2134
|
+
return /* @__PURE__ */jsx(FeatureEnabledProvider, {
|
|
2135
|
+
children: props.renderDefault(props)
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
},
|
|
2083
2140
|
form: {
|
|
2084
2141
|
components: {
|
|
2085
2142
|
input: props => {
|
|
@@ -2649,17 +2706,21 @@ function IndexStatus(_ref4) {
|
|
|
2649
2706
|
});
|
|
2650
2707
|
}
|
|
2651
2708
|
function EmbeddingsIndexTool() {
|
|
2709
|
+
const featureState = useIsFeatureEnabled();
|
|
2652
2710
|
return /* @__PURE__ */jsx(Card, {
|
|
2653
2711
|
children: /* @__PURE__ */jsx(Flex, {
|
|
2654
2712
|
justify: "center",
|
|
2655
2713
|
flex: 1,
|
|
2656
|
-
children: /* @__PURE__ */
|
|
2714
|
+
children: /* @__PURE__ */jsxs(Card, {
|
|
2657
2715
|
flex: 1,
|
|
2658
2716
|
style: {
|
|
2659
2717
|
maxWidth: 1200
|
|
2660
2718
|
},
|
|
2661
2719
|
padding: 5,
|
|
2662
|
-
children: /* @__PURE__ */jsx(
|
|
2720
|
+
children: [featureState == "loading" ? /* @__PURE__ */jsx(Box, {
|
|
2721
|
+
padding: 2,
|
|
2722
|
+
children: /* @__PURE__ */jsx(Spinner, {})
|
|
2723
|
+
}) : null, featureState == "disabled" ? /* @__PURE__ */jsx(FeatureDisabledNotice, {}) : null, featureState == "enabled" ? /* @__PURE__ */jsx(Indexes, {}) : null]
|
|
2663
2724
|
})
|
|
2664
2725
|
})
|
|
2665
2726
|
});
|