@sanity/embeddings-index-ui 1.1.5 → 1.1.7

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,6 +1,6 @@
1
1
  # Sanity Embeddings Index UI
2
2
 
3
- > Using this feature requires Sanity to send data to OpenAI[.]com, and Pinecone[.]io for storing vector interpretations of documents.
3
+ > Using this feature requires Sanity to send data to OpenAI.com, and Pinecone.io for storing vector interpretations of documents.
4
4
 
5
5
  Sanity Studio v3 plugins that interact with the `/embeddings-index` HTTP API.
6
6
 
package/dist/index.esm.js CHANGED
@@ -2,28 +2,41 @@ import { useClient, useProjectId, useSchema, DefaultPreview, useDocumentPreviewS
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import { Card, Text, Button, Box, Autocomplete, Flex, Spinner, Stack, Label, TextInput, TextArea, Dialog, Heading, MenuButton, Menu, MenuItem } from '@sanity/ui';
4
4
  import { ErrorOutlineIcon, EarthGlobeIcon, LinkIcon, AddIcon, EllipsisVerticalIcon, TrashIcon, UndoIcon } from '@sanity/icons';
5
- import require$$0, { createContext, useState, useEffect, useContext, useMemo, useRef, forwardRef, useId, useCallback } from 'react';
5
+ import require$$0, { useMemo, createContext, useState, useEffect, useContext, useRef, forwardRef, useId, useCallback } from 'react';
6
6
  import { useDocumentPane } from 'sanity/desk';
7
7
  import { useIntentLink, useRouter } from 'sanity/router';
8
8
  function publicId(id) {
9
9
  return id.replace("drafts.", "");
10
10
  }
11
- const featureName = "embeddingsIndexApi";
12
- const FeatureEnabledContext = createContext("loading");
13
- function useIsFeatureEnabled() {
11
+ function useApiClient() {
14
12
  const client = useClient({
15
- apiVersion: "2023-09-01"
13
+ apiVersion: "vX"
16
14
  });
15
+ return useMemo(() => {
16
+ const customHost = localStorage.getItem("embeddings-index-host");
17
+ if (customHost) {
18
+ return client.withConfig({
19
+ apiHost: customHost,
20
+ useProjectHostname: false,
21
+ withCredentials: false
22
+ });
23
+ }
24
+ return client;
25
+ }, [client]);
26
+ }
27
+ const FeatureEnabledContext = createContext("loading");
28
+ function useIsFeatureEnabled() {
29
+ const client = useApiClient();
17
30
  const [status, setStatus] = useState("loading");
18
31
  useEffect(() => {
19
32
  client.request({
20
33
  method: "GET",
21
- url: "/projects/".concat(client.config().projectId, "/features/").concat(featureName)
22
- }).then(isEnabled => {
23
- setStatus(isEnabled === "true" || isEnabled === true ? "enabled" : "disabled");
34
+ url: "/embeddings-index/status"
35
+ }).then(response => {
36
+ setStatus(response.enabled ? "enabled" : "disabled");
24
37
  }).catch(err => {
25
38
  console.error(err);
26
- setStatus("disabled");
39
+ setStatus("error");
27
40
  });
28
41
  }, [client]);
29
42
  return status;
@@ -54,6 +67,14 @@ function FeatureDisabledNotice(props) {
54
67
  })
55
68
  });
56
69
  }
70
+ function FeatureError() {
71
+ return /* @__PURE__ */jsx(Card, {
72
+ padding: 4,
73
+ border: true,
74
+ tone: "critical",
75
+ children: "An error occurred. See console for details."
76
+ });
77
+ }
57
78
 
58
79
  /******************************************************************************
59
80
  Copyright (c) Microsoft Corporation.
@@ -1925,22 +1946,6 @@ function deleteIndex(indexName, client) {
1925
1946
  url: "/embeddings-index/".concat(dataset, "/").concat(indexName, "?projectId=").concat(projectId)
1926
1947
  });
1927
1948
  }
1928
- function useApiClient() {
1929
- const client = useClient({
1930
- apiVersion: "vX"
1931
- });
1932
- return useMemo(() => {
1933
- const customHost = localStorage.getItem("embeddings-index-host");
1934
- if (customHost) {
1935
- return client.withConfig({
1936
- apiHost: customHost,
1937
- useProjectHostname: false,
1938
- withCredentials: false
1939
- });
1940
- }
1941
- return client;
1942
- }, [client]);
1943
- }
1944
1949
  const NO_RESULTS_VALUE = "";
1945
1950
  const NO_OPTIONS = [];
1946
1951
  const NO_FILTER = () => true;
@@ -2133,6 +2138,9 @@ function SemanticSearchReferenceInput(props) {
2133
2138
  children: /* @__PURE__ */jsx(Spinner, {})
2134
2139
  }) : null, semantic && featureState == "disabled" ? /* @__PURE__ */jsx(FeatureDisabledNotice, {
2135
2140
  urlSuffix: "?ref=embeddings-ref"
2141
+ }) : null, semantic && featureState === "error" ? /* @__PURE__ */jsx(Box, {
2142
+ padding: 4,
2143
+ children: /* @__PURE__ */jsx(FeatureError, {})
2136
2144
  }) : null, /* @__PURE__ */jsx(Box, {
2137
2145
  flex: 1,
2138
2146
  style: {
@@ -2741,25 +2749,31 @@ function IndexStatus(_ref4) {
2741
2749
  function EmbeddingsIndexTool() {
2742
2750
  const featureState = useIsFeatureEnabled();
2743
2751
  return /* @__PURE__ */jsx(Card, {
2752
+ flex: 1,
2744
2753
  children: /* @__PURE__ */jsxs(Flex, {
2745
2754
  justify: "center",
2746
2755
  flex: 1,
2747
- children: [featureState == "disabled" ? /* @__PURE__ */jsx(Box, {
2756
+ children: [featureState === "error" ? /* @__PURE__ */jsx(Box, {
2757
+ padding: 4,
2758
+ children: /* @__PURE__ */jsx(FeatureError, {})
2759
+ }) : null, featureState === "disabled" ? /* @__PURE__ */jsx(Box, {
2748
2760
  padding: 4,
2749
2761
  children: /* @__PURE__ */jsx(FeatureDisabledNotice, {
2750
2762
  urlSuffix: "?ref=embeddings-tab"
2751
2763
  })
2752
- }) : null, /* @__PURE__ */jsxs(Card, {
2764
+ }) : null, featureState === "loading" ? /* @__PURE__ */jsx(Box, {
2765
+ padding: 6,
2766
+ children: /* @__PURE__ */jsx(Spinner, {
2767
+ size: 4
2768
+ })
2769
+ }) : null, featureState === "enabled" ? /* @__PURE__ */jsx(Card, {
2753
2770
  flex: 1,
2754
2771
  style: {
2755
2772
  maxWidth: 1200
2756
2773
  },
2757
2774
  padding: 5,
2758
- children: [featureState == "loading" ? /* @__PURE__ */jsx(Box, {
2759
- padding: 2,
2760
- children: /* @__PURE__ */jsx(Spinner, {})
2761
- }) : null, featureState == "enabled" ? /* @__PURE__ */jsx(Indexes, {}) : null]
2762
- })]
2775
+ children: /* @__PURE__ */jsx(Indexes, {})
2776
+ }) : null]
2763
2777
  })
2764
2778
  });
2765
2779
  }