@sanity/assist 2.0.1 → 2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/assist",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "You create the instructions; Sanity AI Assist does the rest.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -244,6 +244,7 @@ function FieldsInitializer({
244
244
  _key: pathKey,
245
245
  _type: assistFieldTypeName,
246
246
  path: pathKey,
247
+ instructions: [],
247
248
  }),
248
249
  ],
249
250
  'after',
@@ -251,6 +252,11 @@ function FieldsInitializer({
251
252
  )
252
253
  )
253
254
  }
255
+
256
+ if (!existingField?.instructions?.length) {
257
+ event = event.append([setIfMissing([], ['fields', {_key: pathKey}, 'instructions'])])
258
+ }
259
+
254
260
  if (missingPresetInstructions?.length) {
255
261
  event = event.append(
256
262
  insert(
@@ -5,6 +5,7 @@ import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
5
5
  import {canUseAssist, useApiClient, useGenerateCaption} from '../useApiClient'
6
6
  import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
7
7
  import {publicId} from '../helpers/ids'
8
+ import {usePaneRouter} from 'sanity/desk'
8
9
 
9
10
  export interface ImageContextValue {
10
11
  imageDescriptionPath?: string
@@ -15,7 +16,7 @@ export interface ImageContextValue {
15
16
  export const ImageContext = createContext<ImageContextValue>({})
16
17
 
17
18
  export function ImageContextProvider(props: InputProps) {
18
- const {schemaType, path, value} = props
19
+ const {schemaType, path, value, readOnly} = props
19
20
  const assetRef = (value as any)?.asset?._ref
20
21
  const [assetRefState, setAssetRefState] = useState<string | undefined>(assetRef)
21
22
 
@@ -26,6 +27,9 @@ export function ImageContextProvider(props: InputProps) {
26
27
 
27
28
  const {isSyncing} = useSyncState(publicId(documentId), documentSchemaType.name)
28
29
 
30
+ const router = usePaneRouter()
31
+ const isShowingOlderRevision = !!router.params?.rev
32
+
29
33
  useEffect(() => {
30
34
  const descriptionField = getDescriptionFieldOption(schemaType)
31
35
  if (
@@ -34,12 +38,26 @@ export function ImageContextProvider(props: InputProps) {
34
38
  descriptionField &&
35
39
  assetRef !== assetRefState &&
36
40
  !isSyncing &&
37
- canUseAssist(status)
41
+ !isShowingOlderRevision &&
42
+ !readOnly
38
43
  ) {
39
44
  setAssetRefState(assetRef)
40
- generateCaption({path: pathToString([...path, descriptionField]), documentId: documentId})
45
+ if (canUseAssist(status)) {
46
+ generateCaption({path: pathToString([...path, descriptionField]), documentId: documentId})
47
+ }
41
48
  }
42
- }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing, status])
49
+ }, [
50
+ schemaType,
51
+ path,
52
+ assetRef,
53
+ assetRefState,
54
+ documentId,
55
+ generateCaption,
56
+ isSyncing,
57
+ status,
58
+ readOnly,
59
+ isShowingOlderRevision,
60
+ ])
43
61
 
44
62
  const context: ImageContextValue = useMemo(() => {
45
63
  const descriptionField = getDescriptionFieldOption(schemaType)