@sanity/assist 4.1.0 → 4.2.0

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": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "You create the instructions; Sanity AI Assist does the rest.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -40,7 +40,7 @@ export function ImageContextProvider(props: InputProps) {
40
40
  if (
41
41
  assetRef &&
42
42
  assistableDocumentId &&
43
- descriptionField &&
43
+ descriptionField?.updateOnImageChange &&
44
44
  assetRef !== assetRefState &&
45
45
  !isSyncing &&
46
46
  !isShowingOlderRevision &&
@@ -49,7 +49,7 @@ export function ImageContextProvider(props: InputProps) {
49
49
  setAssetRefState(assetRef)
50
50
  if (canUseAssist(status)) {
51
51
  generateCaption({
52
- path: pathToString([...path, descriptionField]),
52
+ path: pathToString([...path, descriptionField.path]),
53
53
  documentId: assistableDocumentId,
54
54
  })
55
55
  }
@@ -71,8 +71,8 @@ export function ImageContextProvider(props: InputProps) {
71
71
  const descriptionField = getDescriptionFieldOption(schemaType)
72
72
  const imageInstructionField = getImageInstructionFieldOption(schemaType)
73
73
  return {
74
- imageDescriptionPath: descriptionField
75
- ? pathToString([...path, descriptionField])
74
+ imageDescriptionPath: descriptionField?.path
75
+ ? pathToString([...path, descriptionField.path])
76
76
  : undefined,
77
77
  imageInstructionPath: imageInstructionField
78
78
  ? pathToString([...path, imageInstructionField])
@@ -18,13 +18,23 @@ export function isImage(schemaType: SchemaType) {
18
18
  return isType(schemaType, 'image')
19
19
  }
20
20
 
21
- export function getDescriptionFieldOption(schemaType: SchemaType | undefined): string | undefined {
21
+ export function getDescriptionFieldOption(
22
+ schemaType: SchemaType | undefined,
23
+ ): {path: string; updateOnImageChange: boolean} | undefined {
22
24
  if (!schemaType) {
23
25
  return undefined
24
26
  }
25
27
  const descriptionField = (schemaType.options as ImageOptions)?.aiAssist?.imageDescriptionField
26
- if (descriptionField) {
27
- return descriptionField
28
+ if (typeof descriptionField === 'string') {
29
+ return {
30
+ path: descriptionField,
31
+ updateOnImageChange: true,
32
+ }
33
+ } else if (descriptionField) {
34
+ return {
35
+ path: descriptionField.path,
36
+ updateOnImageChange: descriptionField.updateOnImageChange ?? true,
37
+ }
28
38
  }
29
39
  return getDescriptionFieldOption(schemaType.type)
30
40
  }
@@ -90,7 +90,18 @@ declare module 'sanity' {
90
90
  * })
91
91
  * ```
92
92
  */
93
- imageDescriptionField?: string
93
+ imageDescriptionField?:
94
+ | string
95
+ | {
96
+ path: string
97
+ /**
98
+ * When updateOnImageChange is true (or undefined), whenever the
99
+ * image asset changes, imageDescriptionField will be regenerated.
100
+ *
101
+ * default: true
102
+ * */
103
+ updateOnImageChange?: boolean
104
+ }
94
105
  }
95
106
  }
96
107
  interface NumberOptions extends AssistOptions {}