@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.js
CHANGED
|
@@ -1906,11 +1906,56 @@ function useApiClient() {
|
|
|
1906
1906
|
return client;
|
|
1907
1907
|
}, [client]);
|
|
1908
1908
|
}
|
|
1909
|
+
const featureName = "embeddingsIndexApi";
|
|
1910
|
+
const FeatureEnabledContext = require$$0.createContext("loading");
|
|
1911
|
+
function useIsFeatureEnabled() {
|
|
1912
|
+
const client = sanity.useClient({
|
|
1913
|
+
apiVersion: "2023-09-01"
|
|
1914
|
+
});
|
|
1915
|
+
const [status, setStatus] = require$$0.useState("loading");
|
|
1916
|
+
require$$0.useEffect(() => {
|
|
1917
|
+
client.request({
|
|
1918
|
+
method: "GET",
|
|
1919
|
+
url: "/projects/".concat(client.config().projectId, "/features/").concat(featureName)
|
|
1920
|
+
}).then(isEnabled => {
|
|
1921
|
+
setStatus(isEnabled === "true" || isEnabled === true ? "enabled" : "disabled");
|
|
1922
|
+
}).catch(err => {
|
|
1923
|
+
console.error(err);
|
|
1924
|
+
setStatus("disabled");
|
|
1925
|
+
});
|
|
1926
|
+
}, [client]);
|
|
1927
|
+
return status;
|
|
1928
|
+
}
|
|
1929
|
+
function FeatureEnabledProvider(props) {
|
|
1930
|
+
const status = useIsFeatureEnabled();
|
|
1931
|
+
return /* @__PURE__ */jsxRuntime.jsx(FeatureEnabledContext.Provider, {
|
|
1932
|
+
value: status,
|
|
1933
|
+
children: props.children
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
function useIsFeatureEnabledContext() {
|
|
1937
|
+
return require$$0.useContext(FeatureEnabledContext);
|
|
1938
|
+
}
|
|
1939
|
+
function FeatureDisabledNotice() {
|
|
1940
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
1941
|
+
tone: "primary",
|
|
1942
|
+
border: true,
|
|
1943
|
+
padding: 2,
|
|
1944
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
|
|
1945
|
+
size: 1,
|
|
1946
|
+
children: ["Embeddings index APIs are only available on the", " ", /* @__PURE__ */jsxRuntime.jsx("a", {
|
|
1947
|
+
href: "https://sanity.io/pricing",
|
|
1948
|
+
children: "Team tier and above"
|
|
1949
|
+
}), ". Please upgrade to enable access."]
|
|
1950
|
+
})
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1909
1953
|
const NO_OPTIONS = [];
|
|
1910
1954
|
const NO_FILTER = () => true;
|
|
1911
1955
|
function SemanticSearchReferenceInput(props) {
|
|
1912
1956
|
var _a, _b, _c;
|
|
1913
1957
|
const defaultEnabled = ((_c = (_b = (_a = props.schemaType) == null ? void 0 : _a.options) == null ? void 0 : _b.embeddingsIndex) == null ? void 0 : _c.searchMode) === "embeddings";
|
|
1958
|
+
const featureState = useIsFeatureEnabledContext();
|
|
1914
1959
|
const [semantic, setSemantic] = require$$0.useState(defaultEnabled);
|
|
1915
1960
|
const toggleSemantic = require$$0.useCallback(() => setSemantic(current => !current), []);
|
|
1916
1961
|
return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
@@ -1919,13 +1964,16 @@ function SemanticSearchReferenceInput(props) {
|
|
|
1919
1964
|
style: {
|
|
1920
1965
|
width: "100%"
|
|
1921
1966
|
},
|
|
1922
|
-
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1967
|
+
children: [semantic && featureState == "loading" ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1968
|
+
padding: 2,
|
|
1969
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
|
|
1970
|
+
}) : null, semantic && featureState == "disabled" ? /* @__PURE__ */jsxRuntime.jsx(FeatureDisabledNotice, {}) : null, /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1923
1971
|
flex: 1,
|
|
1924
1972
|
style: {
|
|
1925
1973
|
maxHeight: 36,
|
|
1926
1974
|
overflow: "hidden"
|
|
1927
1975
|
},
|
|
1928
|
-
children: semantic ? /* @__PURE__ */jsxRuntime.jsx(SemanticSearchInput, {
|
|
1976
|
+
children: semantic && featureState == "enabled" ? /* @__PURE__ */jsxRuntime.jsx(SemanticSearchInput, {
|
|
1929
1977
|
...props
|
|
1930
1978
|
}) : props.renderDefault(props)
|
|
1931
1979
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
@@ -2091,6 +2139,15 @@ function isType(schemaType, typeName) {
|
|
|
2091
2139
|
}
|
|
2092
2140
|
const embeddingsIndexReferenceInput = sanity.definePlugin({
|
|
2093
2141
|
name: "@sanity/embeddings-index-reference-input",
|
|
2142
|
+
studio: {
|
|
2143
|
+
components: {
|
|
2144
|
+
layout: props => {
|
|
2145
|
+
return /* @__PURE__ */jsxRuntime.jsx(FeatureEnabledProvider, {
|
|
2146
|
+
children: props.renderDefault(props)
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
},
|
|
2094
2151
|
form: {
|
|
2095
2152
|
components: {
|
|
2096
2153
|
input: props => {
|
|
@@ -2660,17 +2717,21 @@ function IndexStatus(_ref4) {
|
|
|
2660
2717
|
});
|
|
2661
2718
|
}
|
|
2662
2719
|
function EmbeddingsIndexTool() {
|
|
2720
|
+
const featureState = useIsFeatureEnabled();
|
|
2663
2721
|
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
2664
2722
|
children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
2665
2723
|
justify: "center",
|
|
2666
2724
|
flex: 1,
|
|
2667
|
-
children: /* @__PURE__ */jsxRuntime.
|
|
2725
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Card, {
|
|
2668
2726
|
flex: 1,
|
|
2669
2727
|
style: {
|
|
2670
2728
|
maxWidth: 1200
|
|
2671
2729
|
},
|
|
2672
2730
|
padding: 5,
|
|
2673
|
-
children: /* @__PURE__ */jsxRuntime.jsx(
|
|
2731
|
+
children: [featureState == "loading" ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
2732
|
+
padding: 2,
|
|
2733
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
|
|
2734
|
+
}) : null, featureState == "disabled" ? /* @__PURE__ */jsxRuntime.jsx(FeatureDisabledNotice, {}) : null, featureState == "enabled" ? /* @__PURE__ */jsxRuntime.jsx(Indexes, {}) : null]
|
|
2674
2735
|
})
|
|
2675
2736
|
})
|
|
2676
2737
|
});
|