@sanity/assist 2.0.2 → 2.0.4-canary.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": "2.0.2",
3
+ "version": "2.0.4-canary.0",
4
4
  "description": "You create the instructions; Sanity AI Assist does the rest.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -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,15 +27,37 @@ 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
- if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing) {
35
+ if (
36
+ assetRef &&
37
+ documentId &&
38
+ descriptionField &&
39
+ assetRef !== assetRefState &&
40
+ !isSyncing &&
41
+ !isShowingOlderRevision &&
42
+ !readOnly
43
+ ) {
32
44
  setAssetRefState(assetRef)
33
45
  if (canUseAssist(status)) {
34
46
  generateCaption({path: pathToString([...path, descriptionField]), documentId: documentId})
35
47
  }
36
48
  }
37
- }, [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
+ ])
38
61
 
39
62
  const context: ImageContextValue = useMemo(() => {
40
63
  const descriptionField = getDescriptionFieldOption(schemaType)
@@ -218,6 +218,32 @@ export const prompt = defineType({
218
218
  ],
219
219
  })
220
220
 
221
+ export const outputFieldType = defineType({
222
+ type: 'object',
223
+ name: outputFieldTypeName,
224
+ title: 'Output field',
225
+ fields: [
226
+ defineField({
227
+ type: 'string',
228
+ name: 'path',
229
+ title: 'Path',
230
+ }),
231
+ ],
232
+ })
233
+
234
+ export const outputTypeType = defineType({
235
+ type: 'object',
236
+ name: outputTypeTypeName,
237
+ title: 'Output type',
238
+ fields: [
239
+ defineField({
240
+ type: 'string',
241
+ name: 'type',
242
+ title: 'Type',
243
+ }),
244
+ ],
245
+ })
246
+
221
247
  export const instruction = defineType({
222
248
  type: 'object',
223
249
  name: instructionTypeName,
@@ -342,30 +368,8 @@ export const instruction = defineType({
342
368
  field: InstructionOutputField,
343
369
  },
344
370
  of: [
345
- defineArrayMember({
346
- type: 'object' as const,
347
- name: outputFieldTypeName,
348
- title: 'Output field',
349
- fields: [
350
- {
351
- type: 'string',
352
- name: 'path',
353
- title: 'Path',
354
- },
355
- ],
356
- }),
357
- defineArrayMember({
358
- type: 'object' as const,
359
- name: outputTypeTypeName,
360
- title: 'Output type',
361
- fields: [
362
- {
363
- type: 'string',
364
- name: 'type',
365
- title: 'Type',
366
- },
367
- ],
368
- }),
371
+ defineArrayMember({type: outputFieldType.name}),
372
+ defineArrayMember({type: outputTypeType.name}),
369
373
  ],
370
374
  }),
371
375
  ],
@@ -6,6 +6,8 @@ import {
6
6
  fieldReference,
7
7
  instruction,
8
8
  instructionTask,
9
+ outputFieldType,
10
+ outputTypeType,
9
11
  prompt,
10
12
  promptContext,
11
13
  userInput,
@@ -57,6 +59,8 @@ const instructionForm = [
57
59
 
58
60
  export const schemaTypes = [
59
61
  ...instructionForm,
62
+ outputFieldType,
63
+ outputTypeType,
60
64
  assistDocumentSchema,
61
65
  documentInstructionStatus,
62
66
  instructionTask,