@sanity/embeddings-index-ui 1.0.0 → 1.0.2
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/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +34 -39
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +33 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/embeddingsApi.ts +1 -1
- package/src/api/embeddingsApiHooks.ts +12 -7
- package/src/embeddingsIndexDashboard/EmbeddingsIndexTool.tsx +2 -7
- package/src/embeddingsIndexDashboard/QueryIndex.tsx +2 -1
- package/src/preview/DocumentPreview.tsx +7 -11
- package/src/referenceInput/SemanticSearchReferenceInput.tsx +6 -17
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @sanity/embeddings-index-ui
|
|
2
2
|
> This package contains plugins for **Sanity Studio v3**.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Sanity Studio plugins that interacts with the `/embeddings-index` HTTP API.
|
|
5
5
|
|
|
6
6
|
The embeddings index API allows the creation of named embeddings vector indexes.
|
|
7
7
|
An embeddings index contains embeddings for all Sanity documents matching a configured GROQ filter in a dataset.
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
3
|
import { Card, Button, Box, Flex, Autocomplete, Text, Stack, Label, TextInput, TextArea, Dialog, Spinner, Heading, MenuButton, Menu, MenuItem } from '@sanity/ui';
|
|
4
4
|
import { ErrorOutlineIcon, EarthGlobeIcon, LinkIcon, AddIcon, SearchIcon, EllipsisVerticalIcon, TrashIcon, UndoIcon } from '@sanity/icons';
|
|
@@ -1740,20 +1740,12 @@ function DocumentPreview(_ref) {
|
|
|
1740
1740
|
let {
|
|
1741
1741
|
documentId,
|
|
1742
1742
|
style,
|
|
1743
|
+
schemaTypeName,
|
|
1743
1744
|
...buttonProps
|
|
1744
1745
|
} = _ref;
|
|
1745
|
-
const client = useClient({
|
|
1746
|
-
apiVersion: "2023-06-06"
|
|
1747
|
-
});
|
|
1748
|
-
const [type, setType] = useState(void 0);
|
|
1749
1746
|
const schema = useSchema();
|
|
1750
|
-
const schemaType =
|
|
1751
|
-
|
|
1752
|
-
client.fetch("* [_id==$id]._type", {
|
|
1753
|
-
id: documentId
|
|
1754
|
-
}).then(setType);
|
|
1755
|
-
}, [documentId, client]);
|
|
1756
|
-
if (!type) {
|
|
1747
|
+
const schemaType = schemaTypeName ? schema.get(schemaTypeName) : void 0;
|
|
1748
|
+
if (!schemaTypeName) {
|
|
1757
1749
|
return /* @__PURE__ */jsx(Card, {
|
|
1758
1750
|
style: {
|
|
1759
1751
|
minHeight: "36px"
|
|
@@ -1775,7 +1767,7 @@ function DocumentPreview(_ref) {
|
|
|
1775
1767
|
media: () => /* @__PURE__ */jsx(ErrorOutlineIcon, {}),
|
|
1776
1768
|
title: /* @__PURE__ */jsxs(Fragment, {
|
|
1777
1769
|
children: ["Unknown type ", /* @__PURE__ */jsx("code", {
|
|
1778
|
-
children:
|
|
1770
|
+
children: schemaTypeName != null ? schemaTypeName : "N/A"
|
|
1779
1771
|
}), " for ", documentId]
|
|
1780
1772
|
})
|
|
1781
1773
|
})
|
|
@@ -1783,6 +1775,7 @@ function DocumentPreview(_ref) {
|
|
|
1783
1775
|
}
|
|
1784
1776
|
return /* @__PURE__ */jsx(DocumentPreviewInner, {
|
|
1785
1777
|
documentId,
|
|
1778
|
+
schemaTypeName,
|
|
1786
1779
|
schemaType,
|
|
1787
1780
|
style,
|
|
1788
1781
|
...buttonProps
|
|
@@ -1886,6 +1879,22 @@ function deleteIndex(indexName, client) {
|
|
|
1886
1879
|
function publicId(id) {
|
|
1887
1880
|
return id.replace("drafts.", "");
|
|
1888
1881
|
}
|
|
1882
|
+
function useApiClient() {
|
|
1883
|
+
const client = useClient({
|
|
1884
|
+
apiVersion: "vX"
|
|
1885
|
+
});
|
|
1886
|
+
return useMemo(() => {
|
|
1887
|
+
const customHost = localStorage.getItem("embeddings-index-host");
|
|
1888
|
+
if (customHost) {
|
|
1889
|
+
return client.withConfig({
|
|
1890
|
+
apiHost: customHost,
|
|
1891
|
+
useProjectHostname: false,
|
|
1892
|
+
withCredentials: false
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
return client;
|
|
1896
|
+
}, [client]);
|
|
1897
|
+
}
|
|
1889
1898
|
const NO_OPTIONS = [];
|
|
1890
1899
|
const NO_FILTER = () => true;
|
|
1891
1900
|
function SemanticSearchReferenceInput(props) {
|
|
@@ -1926,12 +1935,6 @@ function useDebouncedValue(value, ms) {
|
|
|
1926
1935
|
}, [value, ms]);
|
|
1927
1936
|
return debouncedValue;
|
|
1928
1937
|
}
|
|
1929
|
-
function useApiClient$2() {
|
|
1930
|
-
const client = useClient({
|
|
1931
|
-
apiVersion: "vX"
|
|
1932
|
-
});
|
|
1933
|
-
return useMemo(() => client, [client]);
|
|
1934
|
-
}
|
|
1935
1938
|
function SemanticSearchInput(props) {
|
|
1936
1939
|
const {
|
|
1937
1940
|
onPathFocus,
|
|
@@ -1952,7 +1955,7 @@ function SemanticSearchInput(props) {
|
|
|
1952
1955
|
const prevDebouncedQuery = useRef(debouncedQuery);
|
|
1953
1956
|
const [searching, setSearching] = useState(false);
|
|
1954
1957
|
const [options, setOptions] = useState(NO_OPTIONS);
|
|
1955
|
-
const client = useApiClient
|
|
1958
|
+
const client = useApiClient();
|
|
1956
1959
|
useEffect(() => {
|
|
1957
1960
|
docRef.current = currentDocument;
|
|
1958
1961
|
}, [currentDocument]);
|
|
@@ -1965,7 +1968,7 @@ function SemanticSearchInput(props) {
|
|
|
1965
1968
|
const handleFocus = useCallback(() => onPathFocus(["_ref"]), [onPathFocus]);
|
|
1966
1969
|
const handleBlur = useCallback(() => onPathFocus([]), [onPathFocus]);
|
|
1967
1970
|
const runIndexQuery = useCallback(queryString => {
|
|
1968
|
-
var _a, _b, _c, _d;
|
|
1971
|
+
var _a, _b, _c, _d, _e;
|
|
1969
1972
|
setSearching(true);
|
|
1970
1973
|
const refSchema = schemaType;
|
|
1971
1974
|
const indexName = (_b = (_a = refSchema.options) == null ? void 0 : _a.embeddingsIndex) == null ? void 0 : _b.indexName;
|
|
@@ -1975,7 +1978,7 @@ function SemanticSearchInput(props) {
|
|
|
1975
1978
|
throw new Error("Reference option embeddingsIndex.indexName is required, but was missing in type ".concat(refSchema.name));
|
|
1976
1979
|
}
|
|
1977
1980
|
queryIndex({
|
|
1978
|
-
query: queryString,
|
|
1981
|
+
query: queryString.trim().length ? queryString : (_e = JSON.stringify(docRef.current)) != null ? _e : "",
|
|
1979
1982
|
indexName,
|
|
1980
1983
|
maxResults,
|
|
1981
1984
|
filter: {
|
|
@@ -2024,7 +2027,7 @@ function SemanticSearchInput(props) {
|
|
|
2024
2027
|
id,
|
|
2025
2028
|
ref: autocompleteRef,
|
|
2026
2029
|
"data-testid": "semantic-autocomplete",
|
|
2027
|
-
placeholder: "Type to search",
|
|
2030
|
+
placeholder: "Type to search...",
|
|
2028
2031
|
openButton: openButtonConfig,
|
|
2029
2032
|
onFocus: handleFocus,
|
|
2030
2033
|
onChange: handleChange,
|
|
@@ -2038,6 +2041,7 @@ function SemanticSearchInput(props) {
|
|
|
2038
2041
|
});
|
|
2039
2042
|
}
|
|
2040
2043
|
function AutocompleteOption(props) {
|
|
2044
|
+
const value = props.result.value;
|
|
2041
2045
|
return /* @__PURE__ */jsx(Button, {
|
|
2042
2046
|
mode: "bleed",
|
|
2043
2047
|
padding: 1,
|
|
@@ -2050,7 +2054,8 @@ function AutocompleteOption(props) {
|
|
|
2050
2054
|
children: [/* @__PURE__ */jsx(Box, {
|
|
2051
2055
|
flex: 1,
|
|
2052
2056
|
children: /* @__PURE__ */jsx(DocumentPreview, {
|
|
2053
|
-
documentId:
|
|
2057
|
+
documentId: value.documentId,
|
|
2058
|
+
schemaTypeName: value.type
|
|
2054
2059
|
})
|
|
2055
2060
|
}), /* @__PURE__ */jsx(Box, {
|
|
2056
2061
|
padding: 2,
|
|
@@ -2089,12 +2094,6 @@ const embeddingsIndexReferenceInput = definePlugin({
|
|
|
2089
2094
|
}
|
|
2090
2095
|
}
|
|
2091
2096
|
});
|
|
2092
|
-
function useApiClient$1(customApiClient) {
|
|
2093
|
-
const client = useClient({
|
|
2094
|
-
apiVersion: "vX"
|
|
2095
|
-
});
|
|
2096
|
-
return useMemo(() => customApiClient ? customApiClient(client) : client, [client, customApiClient]);
|
|
2097
|
-
}
|
|
2098
2097
|
const defaultProjection = "{...}";
|
|
2099
2098
|
function useDefaultIndex(schema, dataset) {
|
|
2100
2099
|
const defaultFilter = 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]);
|
|
@@ -2211,7 +2210,7 @@ function IndexEditor(props) {
|
|
|
2211
2210
|
index: selectedIndex,
|
|
2212
2211
|
onSubmit
|
|
2213
2212
|
} = props;
|
|
2214
|
-
const client = useApiClient
|
|
2213
|
+
const client = useApiClient();
|
|
2215
2214
|
const schema = useSchema();
|
|
2216
2215
|
const defaultIndex = useDefaultIndex(schema, (_a = client.config().dataset) != null ? _a : "");
|
|
2217
2216
|
const [errors, setErrors] = useState();
|
|
@@ -2431,7 +2430,7 @@ function QueryIndex(props) {
|
|
|
2431
2430
|
const [query, setQuery] = useState("");
|
|
2432
2431
|
const [searching, setSearching] = useState(false);
|
|
2433
2432
|
const [results, setResults] = useState(NO_RESULTS);
|
|
2434
|
-
const client = useApiClient
|
|
2433
|
+
const client = useApiClient();
|
|
2435
2434
|
const search = useCallback(queryString => {
|
|
2436
2435
|
setSearching(true);
|
|
2437
2436
|
return queryIndex({
|
|
@@ -2501,13 +2500,15 @@ function ResultList(props) {
|
|
|
2501
2500
|
});
|
|
2502
2501
|
}
|
|
2503
2502
|
function ResultEntry(props) {
|
|
2503
|
+
const value = props.result.value;
|
|
2504
2504
|
return /* @__PURE__ */jsxs(Flex, {
|
|
2505
2505
|
gap: 4,
|
|
2506
2506
|
align: "center",
|
|
2507
2507
|
children: [/* @__PURE__ */jsx(Box, {
|
|
2508
2508
|
flex: 1,
|
|
2509
2509
|
children: /* @__PURE__ */jsx(DocumentPreview, {
|
|
2510
|
-
documentId:
|
|
2510
|
+
documentId: value.documentId,
|
|
2511
|
+
schemaTypeName: value.type,
|
|
2511
2512
|
button: true
|
|
2512
2513
|
})
|
|
2513
2514
|
}), /* @__PURE__ */jsx(Box, {
|
|
@@ -2647,12 +2648,6 @@ function IndexStatus(_ref4) {
|
|
|
2647
2648
|
})]
|
|
2648
2649
|
});
|
|
2649
2650
|
}
|
|
2650
|
-
function useApiClient() {
|
|
2651
|
-
const client = useClient({
|
|
2652
|
-
apiVersion: "vX"
|
|
2653
|
-
});
|
|
2654
|
-
return useMemo(() => client, [client]);
|
|
2655
|
-
}
|
|
2656
2651
|
function EmbeddingsIndexTool() {
|
|
2657
2652
|
return /* @__PURE__ */jsx(Card, {
|
|
2658
2653
|
children: /* @__PURE__ */jsx(Flex, {
|