@sanity/embeddings-index-ui 1.0.1 → 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 +87 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +84 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/embeddingsApiHooks.ts +12 -7
- package/src/api/isEnabled.tsx +53 -0
- package/src/embeddingsIndexDashboard/EmbeddingsIndexTool.tsx +13 -8
- package/src/referenceInput/SemanticSearchReferenceInput.tsx +26 -15
- package/src/referenceInput/referencePlugin.tsx +8 -0
package/dist/index.js
CHANGED
|
@@ -1890,11 +1890,72 @@ function deleteIndex(indexName, client) {
|
|
|
1890
1890
|
function publicId(id) {
|
|
1891
1891
|
return id.replace("drafts.", "");
|
|
1892
1892
|
}
|
|
1893
|
+
function useApiClient() {
|
|
1894
|
+
const client = sanity.useClient({
|
|
1895
|
+
apiVersion: "vX"
|
|
1896
|
+
});
|
|
1897
|
+
return require$$0.useMemo(() => {
|
|
1898
|
+
const customHost = localStorage.getItem("embeddings-index-host");
|
|
1899
|
+
if (customHost) {
|
|
1900
|
+
return client.withConfig({
|
|
1901
|
+
apiHost: customHost,
|
|
1902
|
+
useProjectHostname: false,
|
|
1903
|
+
withCredentials: false
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
return client;
|
|
1907
|
+
}, [client]);
|
|
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
|
+
}
|
|
1893
1953
|
const NO_OPTIONS = [];
|
|
1894
1954
|
const NO_FILTER = () => true;
|
|
1895
1955
|
function SemanticSearchReferenceInput(props) {
|
|
1896
1956
|
var _a, _b, _c;
|
|
1897
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();
|
|
1898
1959
|
const [semantic, setSemantic] = require$$0.useState(defaultEnabled);
|
|
1899
1960
|
const toggleSemantic = require$$0.useCallback(() => setSemantic(current => !current), []);
|
|
1900
1961
|
return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
@@ -1903,13 +1964,16 @@ function SemanticSearchReferenceInput(props) {
|
|
|
1903
1964
|
style: {
|
|
1904
1965
|
width: "100%"
|
|
1905
1966
|
},
|
|
1906
|
-
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, {
|
|
1907
1971
|
flex: 1,
|
|
1908
1972
|
style: {
|
|
1909
1973
|
maxHeight: 36,
|
|
1910
1974
|
overflow: "hidden"
|
|
1911
1975
|
},
|
|
1912
|
-
children: semantic ? /* @__PURE__ */jsxRuntime.jsx(SemanticSearchInput, {
|
|
1976
|
+
children: semantic && featureState == "enabled" ? /* @__PURE__ */jsxRuntime.jsx(SemanticSearchInput, {
|
|
1913
1977
|
...props
|
|
1914
1978
|
}) : props.renderDefault(props)
|
|
1915
1979
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
@@ -1930,12 +1994,6 @@ function useDebouncedValue(value, ms) {
|
|
|
1930
1994
|
}, [value, ms]);
|
|
1931
1995
|
return debouncedValue;
|
|
1932
1996
|
}
|
|
1933
|
-
function useApiClient$2() {
|
|
1934
|
-
const client = sanity.useClient({
|
|
1935
|
-
apiVersion: "vX"
|
|
1936
|
-
});
|
|
1937
|
-
return require$$0.useMemo(() => client, [client]);
|
|
1938
|
-
}
|
|
1939
1997
|
function SemanticSearchInput(props) {
|
|
1940
1998
|
const {
|
|
1941
1999
|
onPathFocus,
|
|
@@ -1956,7 +2014,7 @@ function SemanticSearchInput(props) {
|
|
|
1956
2014
|
const prevDebouncedQuery = require$$0.useRef(debouncedQuery);
|
|
1957
2015
|
const [searching, setSearching] = require$$0.useState(false);
|
|
1958
2016
|
const [options, setOptions] = require$$0.useState(NO_OPTIONS);
|
|
1959
|
-
const client = useApiClient
|
|
2017
|
+
const client = useApiClient();
|
|
1960
2018
|
require$$0.useEffect(() => {
|
|
1961
2019
|
docRef.current = currentDocument;
|
|
1962
2020
|
}, [currentDocument]);
|
|
@@ -2081,6 +2139,15 @@ function isType(schemaType, typeName) {
|
|
|
2081
2139
|
}
|
|
2082
2140
|
const embeddingsIndexReferenceInput = sanity.definePlugin({
|
|
2083
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
|
+
},
|
|
2084
2151
|
form: {
|
|
2085
2152
|
components: {
|
|
2086
2153
|
input: props => {
|
|
@@ -2095,12 +2162,6 @@ const embeddingsIndexReferenceInput = sanity.definePlugin({
|
|
|
2095
2162
|
}
|
|
2096
2163
|
}
|
|
2097
2164
|
});
|
|
2098
|
-
function useApiClient$1(customApiClient) {
|
|
2099
|
-
const client = sanity.useClient({
|
|
2100
|
-
apiVersion: "vX"
|
|
2101
|
-
});
|
|
2102
|
-
return require$$0.useMemo(() => customApiClient ? customApiClient(client) : client, [client, customApiClient]);
|
|
2103
|
-
}
|
|
2104
2165
|
const defaultProjection = "{...}";
|
|
2105
2166
|
function useDefaultIndex(schema, dataset) {
|
|
2106
2167
|
const defaultFilter = require$$0.useMemo(() => "_type in [".concat(schema.getTypeNames().map(n => schema.get(n)).filter(schemaType => Boolean(schemaType && isType(schemaType, "document"))).filter(documentType => !documentType.name.startsWith("sanity.") && !documentType.name.startsWith("assist.") && documentType.name !== "document").map(documentType => '"'.concat(documentType.name, '"')).join(",\n"), "]"), [schema]);
|
|
@@ -2217,7 +2278,7 @@ function IndexEditor(props) {
|
|
|
2217
2278
|
index: selectedIndex,
|
|
2218
2279
|
onSubmit
|
|
2219
2280
|
} = props;
|
|
2220
|
-
const client = useApiClient
|
|
2281
|
+
const client = useApiClient();
|
|
2221
2282
|
const schema = sanity.useSchema();
|
|
2222
2283
|
const defaultIndex = useDefaultIndex(schema, (_a = client.config().dataset) != null ? _a : "");
|
|
2223
2284
|
const [errors, setErrors] = require$$0.useState();
|
|
@@ -2437,7 +2498,7 @@ function QueryIndex(props) {
|
|
|
2437
2498
|
const [query, setQuery] = require$$0.useState("");
|
|
2438
2499
|
const [searching, setSearching] = require$$0.useState(false);
|
|
2439
2500
|
const [results, setResults] = require$$0.useState(NO_RESULTS);
|
|
2440
|
-
const client = useApiClient
|
|
2501
|
+
const client = useApiClient();
|
|
2441
2502
|
const search = require$$0.useCallback(queryString => {
|
|
2442
2503
|
setSearching(true);
|
|
2443
2504
|
return queryIndex({
|
|
@@ -2655,24 +2716,22 @@ function IndexStatus(_ref4) {
|
|
|
2655
2716
|
})]
|
|
2656
2717
|
});
|
|
2657
2718
|
}
|
|
2658
|
-
function useApiClient() {
|
|
2659
|
-
const client = sanity.useClient({
|
|
2660
|
-
apiVersion: "vX"
|
|
2661
|
-
});
|
|
2662
|
-
return require$$0.useMemo(() => client, [client]);
|
|
2663
|
-
}
|
|
2664
2719
|
function EmbeddingsIndexTool() {
|
|
2720
|
+
const featureState = useIsFeatureEnabled();
|
|
2665
2721
|
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
2666
2722
|
children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
2667
2723
|
justify: "center",
|
|
2668
2724
|
flex: 1,
|
|
2669
|
-
children: /* @__PURE__ */jsxRuntime.
|
|
2725
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Card, {
|
|
2670
2726
|
flex: 1,
|
|
2671
2727
|
style: {
|
|
2672
2728
|
maxWidth: 1200
|
|
2673
2729
|
},
|
|
2674
2730
|
padding: 5,
|
|
2675
|
-
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]
|
|
2676
2735
|
})
|
|
2677
2736
|
})
|
|
2678
2737
|
});
|