@sanity/embeddings-index-ui 2.0.1 → 2.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/embeddings-index-ui",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "Various Sanity Studio plugins for integrating with the embeddings index API",
5
5
  "keywords": [
6
6
  "sanity",
@@ -12,27 +12,21 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git+ssh://git@github.com/sanity-io/embeddings-index-ui.git"
15
+ "url": "git@github.com:sanity-io/embeddings-index-ui.git"
16
16
  },
17
17
  "license": "MIT",
18
18
  "author": "Sanity <hello@sanity.io>",
19
+ "sideEffects": false,
20
+ "type": "commonjs",
19
21
  "exports": {
20
22
  ".": {
21
- "types": "./dist/index.d.ts",
22
23
  "source": "./src/index.ts",
23
- "require": "./dist/index.js",
24
- "node": {
25
- "module": "./dist/index.esm.js",
26
- "import": "./dist/index.cjs.mjs"
27
- },
28
- "import": "./dist/index.esm.js",
29
- "default": "./dist/index.esm.js"
24
+ "import": "./dist/index.mjs",
25
+ "default": "./dist/index.js"
30
26
  },
31
27
  "./package.json": "./package.json"
32
28
  },
33
29
  "main": "./dist/index.js",
34
- "module": "./dist/index.esm.js",
35
- "source": "./src/index.ts",
36
30
  "types": "./dist/index.d.ts",
37
31
  "files": [
38
32
  "dist",
@@ -41,56 +35,58 @@
41
35
  "v2-incompatible.js"
42
36
  ],
43
37
  "scripts": {
44
- "build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
38
+ "build": "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
45
39
  "clean": "rimraf dist",
46
40
  "format": "prettier --write --cache --ignore-unknown .",
47
41
  "link-watch": "plugin-kit link-watch",
48
42
  "lint": "eslint .",
49
- "prepublishOnly": "run-s build",
43
+ "prepublishOnly": "npm run build",
50
44
  "watch": "pkg-utils watch --strict",
51
45
  "prepare": "husky install"
52
46
  },
53
47
  "dependencies": {
54
- "@sanity/icons": "^3.5.3",
48
+ "@sanity/icons": "^3.7.0",
55
49
  "@sanity/incompatible-plugin": "^1.0.5",
56
- "@sanity/ui": "^2.10.11"
50
+ "@sanity/ui": "^2.15.14"
57
51
  },
58
52
  "devDependencies": {
59
53
  "@commitlint/cli": "^17.7.1",
60
54
  "@commitlint/config-conventional": "^17.7.0",
61
- "@sanity/pkg-utils": "^2.4.8",
62
- "@sanity/plugin-kit": "^3.1.10",
63
- "@sanity/semantic-release-preset": "^4.1.4",
64
- "@types/react": "^18.2.21",
65
- "@typescript-eslint/eslint-plugin": "^6.5.0",
66
- "@typescript-eslint/parser": "^6.5.0",
67
- "eslint": "^8.48.0",
68
- "eslint-config-prettier": "^9.0.0",
69
- "eslint-config-sanity": "^6.0.0",
70
- "eslint-plugin-prettier": "^5.0.0",
71
- "eslint-plugin-react": "^7.33.2",
72
- "eslint-plugin-react-hooks": "^4.6.0",
55
+ "@sanity/pkg-utils": "^7.2.2",
56
+ "@sanity/plugin-kit": "^4.0.19",
57
+ "@sanity/semantic-release-preset": "^5.0.0",
58
+ "@types/react": "^19.1.2",
59
+ "@typescript-eslint/eslint-plugin": "^8.31.1",
60
+ "@typescript-eslint/parser": "^8.31.1",
61
+ "eslint": "^8.57.1",
62
+ "eslint-config-prettier": "^10.1.2",
63
+ "eslint-config-sanity": "^7.1.4",
64
+ "eslint-plugin-prettier": "^5.2.6",
65
+ "eslint-plugin-react": "^7.37.5",
66
+ "eslint-plugin-react-hooks": "^5.2.0",
73
67
  "husky": "^8.0.3",
74
68
  "lint-staged": "^14.0.1",
75
69
  "npm-run-all": "^4.1.5",
76
- "prettier": "^3.0.3",
77
- "prettier-plugin-packagejson": "^2.4.5",
78
- "react": "^18.2.0",
79
- "react-dom": "^18.2.0",
70
+ "prettier": "^3.5.3",
71
+ "prettier-plugin-packagejson": "^2.5.10",
72
+ "react": "^19.1.0",
73
+ "react-dom": "^19.1.0",
80
74
  "react-is": "^18.2.0",
81
75
  "rimraf": "^5.0.1",
82
- "sanity": "^3.16.1",
76
+ "sanity": "^3.87.1",
83
77
  "semantic-release": "^21.1.1",
84
- "styled-components": "^6.1",
85
- "typescript": "^5.2.2"
78
+ "styled-components": "^6.1.17",
79
+ "typescript": "^5.8.3"
86
80
  },
87
81
  "peerDependencies": {
88
82
  "react": "^18 || ^19",
89
- "sanity": "^3.14"
83
+ "sanity": "^3.80 || ^4.0.0-0"
90
84
  },
91
85
  "engines": {
92
- "node": ">=14"
86
+ "node": ">=18"
93
87
  },
88
+ "module": "./dist/index.mjs",
89
+ "browserslist": "extends @sanity/browserslist-config",
94
90
  "publishConfig": {
95
91
  "access": "public"
96
92
  }
@@ -1,5 +1,5 @@
1
- import {SanityClient, useClient} from 'sanity'
2
1
  import {useMemo} from 'react'
2
+ import {SanityClient, useClient} from 'sanity'
3
3
 
4
4
  export function useApiClient(): SanityClient {
5
5
  const client = useClient({apiVersion: 'vX'})
@@ -1,6 +1,7 @@
1
- import {useProjectId} from 'sanity'
2
- import {createContext, PropsWithChildren, useContext, useEffect, useState} from 'react'
3
1
  import {Card, Text} from '@sanity/ui'
2
+ import {createContext, PropsWithChildren, useContext, useEffect, useState} from 'react'
3
+ import {useProjectId} from 'sanity'
4
+
4
5
  import {useApiClient} from './embeddingsApiHooks'
5
6
 
6
7
  export type FeatureStatus = 'enabled' | 'disabled' | 'loading' | 'error'
@@ -28,7 +29,7 @@ export function useIsFeatureEnabled() {
28
29
  return status
29
30
  }
30
31
 
31
- export function FeatureEnabledProvider(props: PropsWithChildren<{}>) {
32
+ export function FeatureEnabledProvider(props: PropsWithChildren) {
32
33
  const status = useIsFeatureEnabled()
33
34
  return (
34
35
  <FeatureEnabledContext.Provider value={status}>{props.children}</FeatureEnabledContext.Provider>
@@ -1,12 +1,13 @@
1
+ import {AddIcon, UndoIcon} from '@sanity/icons'
1
2
  import {Box, Button, Card, Flex, Heading, Spinner, Stack} from '@sanity/ui'
2
3
  import {useCallback, useEffect, useState} from 'react'
3
- import {AddIcon, UndoIcon} from '@sanity/icons'
4
+
4
5
  import {deleteIndex, getIndexes, IndexState, NamedIndex} from '../api/embeddingsApi'
5
- import {EditIndexDialog} from './IndexEditor'
6
- import {IndexList} from './IndexList'
7
- import {IndexInfo} from './IndexInfo'
8
6
  import {useApiClient} from '../api/embeddingsApiHooks'
9
7
  import {FeatureDisabledNotice, FeatureError, useIsFeatureEnabled} from '../api/isEnabled'
8
+ import {EditIndexDialog} from './IndexEditor'
9
+ import {IndexInfo} from './IndexInfo'
10
+ import {IndexList} from './IndexList'
10
11
 
11
12
  export function EmbeddingsIndexTool() {
12
13
  const featureState = useIsFeatureEnabled()
@@ -1,8 +1,9 @@
1
- import {IndexState, NamedIndex} from '../api/embeddingsApi'
2
- import {useSchema} from 'sanity'
3
- import {FormEvent, useCallback, useEffect, useId, useRef, useState} from 'react'
4
- import {Box, Button, Card, Dialog, Spinner, Stack, Text} from '@sanity/ui'
5
1
  import {AddIcon} from '@sanity/icons'
2
+ import {Box, Button, Card, Dialog, Spinner, Stack, Text} from '@sanity/ui'
3
+ import {FormEvent, useCallback, useEffect, useId, useRef, useState} from 'react'
4
+ import {useSchema} from 'sanity'
5
+
6
+ import {IndexState, NamedIndex} from '../api/embeddingsApi'
6
7
  import {useApiClient} from '../api/embeddingsApiHooks'
7
8
  import {useDefaultIndex} from './hooks'
8
9
  import {IndexFormInput} from './IndexFormInput'
@@ -107,6 +108,7 @@ export function IndexEditor(props: {
107
108
  onSubmit(response.index)
108
109
  }
109
110
  })
111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
112
  .catch((err: any) => {
111
113
  console.error(err)
112
114
  setErrors([err.message])
@@ -1,6 +1,7 @@
1
- import {NamedIndex} from '../api/embeddingsApi'
1
+ import {Box, Label, Stack, Text, TextArea, TextInput} from '@sanity/ui'
2
2
  import {Dispatch, FormEvent, SetStateAction, useCallback, useId} from 'react'
3
- import {Box, Label, Stack, TextArea, TextInput, Text} from '@sanity/ui'
3
+
4
+ import {NamedIndex} from '../api/embeddingsApi'
4
5
 
5
6
  export interface IndexFormInputProps {
6
7
  index: Partial<NamedIndex>
@@ -1,3 +1,4 @@
1
+ import {EllipsisVerticalIcon, TrashIcon} from '@sanity/icons'
1
2
  import {
2
3
  Box,
3
4
  Button,
@@ -10,11 +11,11 @@ import {
10
11
  Stack,
11
12
  Text,
12
13
  } from '@sanity/ui'
13
- import {EllipsisVerticalIcon, TrashIcon} from '@sanity/icons'
14
+ import {useCallback} from 'react'
15
+
16
+ import {IndexState} from '../api/embeddingsApi'
14
17
  import {IndexEditor} from './IndexEditor'
15
18
  import {QueryIndex} from './QueryIndex'
16
- import {IndexState} from '../api/embeddingsApi'
17
- import {useCallback} from 'react'
18
19
 
19
20
  export interface IndexInfoProps {
20
21
  selectedIndex: IndexState
@@ -1,7 +1,8 @@
1
1
  import {Box, Button, Card, Flex, Label, Stack, Text} from '@sanity/ui'
2
- import {IndexState} from '../api/embeddingsApi'
3
2
  import {useCallback} from 'react'
4
3
 
4
+ import {IndexState} from '../api/embeddingsApi'
5
+
5
6
  export interface IndexListProps {
6
7
  loading: boolean
7
8
  selectedIndex?: IndexState
@@ -1,8 +1,9 @@
1
1
  import {useCallback, useMemo} from 'react'
2
- import {SemanticSearchAutocomplete} from '../referenceInput/SemanticSearchAutocomplete'
3
- import {EmbeddingsIndexConfig} from '../schemas/typeDefExtensions'
4
2
  import {useRouter} from 'sanity/router'
3
+
5
4
  import {QueryResult} from '../api/embeddingsApi'
5
+ import {SemanticSearchAutocomplete} from '../referenceInput/SemanticSearchAutocomplete'
6
+ import {EmbeddingsIndexConfig} from '../schemas/typeDefExtensions'
6
7
 
7
8
  export function QueryIndex(props: {indexName: string}) {
8
9
  const {indexName} = props
@@ -1,5 +1,6 @@
1
- import {definePlugin, Tool} from 'sanity'
2
1
  import {EarthGlobeIcon} from '@sanity/icons'
2
+ import {definePlugin, Tool} from 'sanity'
3
+
3
4
  import {EmbeddingsIndexTool} from './EmbeddingsIndexTool'
4
5
 
5
6
  export const embeddingsIndexTool: Tool = {
@@ -1,5 +1,6 @@
1
- import {ObjectSchemaType, Schema} from 'sanity'
2
1
  import {useMemo} from 'react'
2
+ import {ObjectSchemaType, Schema} from 'sanity'
3
+
3
4
  import {isType} from '../utils/types'
4
5
 
5
6
  const defaultProjection = '{...}'
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import './schemas/typeDefExtensions'
2
- import {embeddingsIndexReferenceInput} from './referenceInput/referencePlugin'
2
+
3
3
  import {embeddingsIndexDashboard} from './embeddingsIndexDashboard/dashboardPlugin'
4
+ import {embeddingsIndexReferenceInput} from './referenceInput/referencePlugin'
4
5
 
5
6
  export {embeddingsIndexReferenceInput}
6
7
 
@@ -1,5 +1,7 @@
1
+ import {ErrorOutlineIcon} from '@sanity/icons'
2
+ import {Box, Button, ButtonProps, Card} from '@sanity/ui'
1
3
  import {CSSProperties, useMemo} from 'react'
2
- import {useMemoObservable} from 'react-rx'
4
+ import {useObservable} from 'react-rx'
3
5
  import {
4
6
  DefaultPreview,
5
7
  getPreviewStateObservable,
@@ -11,8 +13,6 @@ import {
11
13
  useSchema,
12
14
  } from 'sanity'
13
15
  import {useIntentLink} from 'sanity/router'
14
- import {Box, Button, ButtonProps, Card} from '@sanity/ui'
15
- import {ErrorOutlineIcon} from '@sanity/icons'
16
16
 
17
17
  interface ResultPreviewProps {
18
18
  documentId: string
@@ -80,12 +80,20 @@ function DocumentPreviewInner({
80
80
  }: ResultPreviewProps & {schemaType: SchemaType} & ButtonProps) {
81
81
  const documentPreviewStore = useDocumentPreviewStore()
82
82
 
83
- // NOTE: this emits sync so can never be null
84
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
85
- const {draft, published, isLoading} = useMemoObservable(
86
- () => getPreviewStateObservable(documentPreviewStore, schemaType, documentId, ''),
83
+ const previewStateObservable = useMemo(
84
+ () => getPreviewStateObservable(documentPreviewStore, schemaType, documentId),
87
85
  [documentId, documentPreviewStore, schemaType],
88
- )!
86
+ )
87
+
88
+ const {
89
+ snapshot,
90
+ original,
91
+ isLoading: previewIsLoading,
92
+ } = useObservable(previewStateObservable, {
93
+ snapshot: null,
94
+ isLoading: true,
95
+ original: null,
96
+ })
89
97
 
90
98
  const sanityDocument = useMemo(() => {
91
99
  return {
@@ -105,11 +113,11 @@ function DocumentPreviewInner({
105
113
  const preview = (
106
114
  <SanityDefaultPreview
107
115
  {...getPreviewValueWithFallback({
108
- draft,
109
- published,
110
- value: sanityDocument,
116
+ snapshot,
117
+ original,
118
+ fallback: sanityDocument,
111
119
  })}
112
- isPlaceholder={isLoading ?? true}
120
+ isPlaceholder={previewIsLoading ?? true}
113
121
  layout="default"
114
122
  icon={schemaType?.icon}
115
123
  />
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable max-nested-callbacks */
2
2
  import {Autocomplete, AutocompleteOpenButtonProps, Box, Button, Flex, Text} from '@sanity/ui'
3
- import {DocumentPreview} from '../preview/DocumentPreview'
4
3
  import {
5
4
  FocusEventHandler,
6
5
  forwardRef,
@@ -11,10 +10,12 @@ import {
11
10
  useRef,
12
11
  useState,
13
12
  } from 'react'
14
- import {EmbeddingsIndexConfig} from '../schemas/typeDefExtensions'
15
- import {queryIndex, QueryResult} from '../api/embeddingsApi'
16
13
  import {typed} from 'sanity'
14
+
15
+ import {queryIndex, QueryResult} from '../api/embeddingsApi'
17
16
  import {useApiClient} from '../api/embeddingsApiHooks'
17
+ import {DocumentPreview} from '../preview/DocumentPreview'
18
+ import {EmbeddingsIndexConfig} from '../schemas/typeDefExtensions'
18
19
 
19
20
  export interface SemanticSearchAutocompleteProps {
20
21
  indexConfig: EmbeddingsIndexConfig
@@ -43,6 +44,7 @@ const NO_FILTER = () => true
43
44
 
44
45
  export const SemanticSearchAutocomplete = forwardRef(function SemanticSearchAutocomplete(
45
46
  props: SemanticSearchAutocompleteProps,
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
48
  ref: any,
47
49
  ) {
48
50
  const {
@@ -78,7 +80,7 @@ export const SemanticSearchAutocomplete = forwardRef(function SemanticSearchAuto
78
80
 
79
81
  queryIndex(
80
82
  {
81
- query: queryString.trim().length ? queryString : getEmptySearchValue() ?? '',
83
+ query: queryString.trim().length ? queryString : (getEmptySearchValue() ?? ''),
82
84
  indexName,
83
85
  maxResults,
84
86
  filter: {
@@ -91,6 +93,7 @@ export const SemanticSearchAutocomplete = forwardRef(function SemanticSearchAuto
91
93
  if (queryRef.current === queryString) {
92
94
  setSearching(false)
93
95
  setOptions([])
96
+ setOptions([])
94
97
  const resultOptions = result
95
98
  .filter((hit) => (filterResult ? filterResult(hit) : true))
96
99
  .map((r) => typed<Option>({result: r, value: r.value.documentId}))
@@ -1,3 +1,6 @@
1
+ import {EarthGlobeIcon, LinkIcon} from '@sanity/icons'
2
+ import {Box, Button, Flex, Spinner} from '@sanity/ui'
3
+ import {useCallback, useEffect, useMemo, useRef, useState} from 'react'
1
4
  import {
2
5
  ObjectInputProps,
3
6
  ReferenceBaseOptions,
@@ -6,14 +9,12 @@ import {
6
9
  setIfMissing,
7
10
  unset,
8
11
  } from 'sanity'
9
- import {Box, Button, Flex, Spinner} from '@sanity/ui'
10
- import {EarthGlobeIcon, LinkIcon} from '@sanity/icons'
11
- import {useCallback, useEffect, useMemo, useRef, useState} from 'react'
12
12
  import {useDocumentPane} from 'sanity/desk'
13
+
13
14
  import {QueryResult} from '../api/embeddingsApi'
14
- import {publicId} from '../utils/id'
15
15
  import {FeatureDisabledNotice, FeatureError, useIsFeatureEnabledContext} from '../api/isEnabled'
16
16
  import {EmbeddingsIndexConfig} from '../schemas/typeDefExtensions'
17
+ import {publicId} from '../utils/id'
17
18
  import {SemanticSearchAutocomplete} from './SemanticSearchAutocomplete'
18
19
 
19
20
  function useEmeddingsConfig(
@@ -1,8 +1,9 @@
1
1
  import {definePlugin, isObjectInputProps, ObjectInputProps, ReferenceSchemaType} from 'sanity'
2
- import {SemanticSearchReferenceInput} from './SemanticSearchReferenceInput'
3
- import {isType} from '../utils/types'
2
+
4
3
  import {FeatureEnabledProvider} from '../api/isEnabled'
5
4
  import {EmbeddingsIndexConfig} from '../schemas/typeDefExtensions'
5
+ import {isType} from '../utils/types'
6
+ import {SemanticSearchReferenceInput} from './SemanticSearchReferenceInput'
6
7
 
7
8
  export const embeddingsIndexReferenceInput = definePlugin<EmbeddingsIndexConfig | void>(
8
9
  (defaultConfig) => {
@@ -1,8 +0,0 @@
1
- import cjs from './index.js';
2
-
3
- export const deleteIndex = cjs.deleteIndex;
4
- export const embeddingsIndexDashboard = cjs.embeddingsIndexDashboard;
5
- export const embeddingsIndexReferenceInput = cjs.embeddingsIndexReferenceInput;
6
- export const getIndexes = cjs.getIndexes;
7
- export const queryIndex = cjs.queryIndex;
8
-