@sanity/embeddings-index-ui 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # @sanity/embeddings-index-ui
2
2
  > This package contains plugins for **Sanity Studio v3**.
3
3
 
4
- `@sanity/embeddings-index-ui` Sanity Studio plugins that interacts with the `/embeddings-index` HTTP API.
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
@@ -42,7 +42,7 @@ export declare interface QueryResult {
42
42
  score: number
43
43
  value: {
44
44
  documentId: string
45
- type?: string
45
+ type: string
46
46
  }
47
47
  }
48
48
 
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useClient, useSchema, DefaultPreview, useDocumentPreviewStore, SanityDefaultPreview, getPreviewValueWithFallback, getPreviewStateObservable, typed, unset, setIfMissing, set, definePlugin, isObjectInputProps } from 'sanity';
1
+ import { useSchema, DefaultPreview, useDocumentPreviewStore, SanityDefaultPreview, getPreviewValueWithFallback, getPreviewStateObservable, typed, unset, setIfMissing, set, useClient, 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 = type ? schema.get(type) : void 0;
1751
- useEffect(() => {
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: type != null ? type : "N/A"
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
@@ -1965,7 +1958,7 @@ function SemanticSearchInput(props) {
1965
1958
  const handleFocus = useCallback(() => onPathFocus(["_ref"]), [onPathFocus]);
1966
1959
  const handleBlur = useCallback(() => onPathFocus([]), [onPathFocus]);
1967
1960
  const runIndexQuery = useCallback(queryString => {
1968
- var _a, _b, _c, _d;
1961
+ var _a, _b, _c, _d, _e;
1969
1962
  setSearching(true);
1970
1963
  const refSchema = schemaType;
1971
1964
  const indexName = (_b = (_a = refSchema.options) == null ? void 0 : _a.embeddingsIndex) == null ? void 0 : _b.indexName;
@@ -1975,7 +1968,7 @@ function SemanticSearchInput(props) {
1975
1968
  throw new Error("Reference option embeddingsIndex.indexName is required, but was missing in type ".concat(refSchema.name));
1976
1969
  }
1977
1970
  queryIndex({
1978
- query: queryString,
1971
+ query: queryString.trim().length ? queryString : (_e = JSON.stringify(docRef.current)) != null ? _e : "",
1979
1972
  indexName,
1980
1973
  maxResults,
1981
1974
  filter: {
@@ -2024,7 +2017,7 @@ function SemanticSearchInput(props) {
2024
2017
  id,
2025
2018
  ref: autocompleteRef,
2026
2019
  "data-testid": "semantic-autocomplete",
2027
- placeholder: "Type to search",
2020
+ placeholder: "Type to search...",
2028
2021
  openButton: openButtonConfig,
2029
2022
  onFocus: handleFocus,
2030
2023
  onChange: handleChange,
@@ -2038,6 +2031,7 @@ function SemanticSearchInput(props) {
2038
2031
  });
2039
2032
  }
2040
2033
  function AutocompleteOption(props) {
2034
+ const value = props.result.value;
2041
2035
  return /* @__PURE__ */jsx(Button, {
2042
2036
  mode: "bleed",
2043
2037
  padding: 1,
@@ -2050,7 +2044,8 @@ function AutocompleteOption(props) {
2050
2044
  children: [/* @__PURE__ */jsx(Box, {
2051
2045
  flex: 1,
2052
2046
  children: /* @__PURE__ */jsx(DocumentPreview, {
2053
- documentId: props.result.value.documentId
2047
+ documentId: value.documentId,
2048
+ schemaTypeName: value.type
2054
2049
  })
2055
2050
  }), /* @__PURE__ */jsx(Box, {
2056
2051
  padding: 2,
@@ -2501,13 +2496,15 @@ function ResultList(props) {
2501
2496
  });
2502
2497
  }
2503
2498
  function ResultEntry(props) {
2499
+ const value = props.result.value;
2504
2500
  return /* @__PURE__ */jsxs(Flex, {
2505
2501
  gap: 4,
2506
2502
  align: "center",
2507
2503
  children: [/* @__PURE__ */jsx(Box, {
2508
2504
  flex: 1,
2509
2505
  children: /* @__PURE__ */jsx(DocumentPreview, {
2510
- documentId: props.result.value.documentId,
2506
+ documentId: value.documentId,
2507
+ schemaTypeName: value.type,
2511
2508
  button: true
2512
2509
  })
2513
2510
  }), /* @__PURE__ */jsx(Box, {