@sanity/assist 1.2.16 → 2.0.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/LICENSE +1 -1
- package/README.md +551 -30
- package/dist/index.cjs.mjs +1 -0
- package/dist/index.d.ts +333 -9
- package/dist/index.esm.js +2463 -390
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2457 -383
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
- package/src/_lib/form/DocumentForm.tsx +2 -1
- package/src/_lib/form/constants.ts +1 -0
- package/src/assistDocument/AssistDocumentInput.tsx +24 -4
- package/src/assistDocument/RequestRunInstructionProvider.tsx +37 -21
- package/src/assistDocument/components/AssistDocumentForm.tsx +65 -21
- package/src/assistDocument/components/instruction/InstructionInput.tsx +5 -4
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +45 -0
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +205 -0
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +5 -32
- package/src/assistFormComponents/AssistField.tsx +11 -5
- package/src/assistFormComponents/AssistFormBlock.tsx +2 -3
- package/src/assistFormComponents/validation/listItem.tsx +2 -2
- package/src/assistInspector/AssistInspector.tsx +6 -0
- package/src/assistInspector/FieldAutocomplete.tsx +1 -0
- package/src/assistInspector/helpers.ts +9 -11
- package/src/assistLayout/AssistLayout.tsx +9 -9
- package/src/components/ImageContext.tsx +30 -13
- package/src/components/SafeValueInput.tsx +4 -1
- package/src/fieldActions/assistFieldActions.tsx +42 -13
- package/src/fieldActions/generateCaptionActions.tsx +17 -6
- package/src/fieldActions/generateImageActions.tsx +57 -0
- package/src/helpers/assistSupported.ts +10 -16
- package/src/helpers/conditionalMembers.test.ts +200 -0
- package/src/helpers/conditionalMembers.ts +127 -0
- package/src/helpers/misc.ts +8 -4
- package/src/helpers/typeUtils.ts +19 -5
- package/src/index.ts +3 -0
- package/src/plugin.tsx +18 -4
- package/src/schemas/assistDocumentSchema.tsx +40 -1
- package/src/schemas/serialize/serializeSchema.test.ts +239 -8
- package/src/schemas/serialize/serializeSchema.ts +77 -10
- package/src/schemas/typeDefExtensions.ts +89 -5
- package/src/translate/FieldTranslationProvider.tsx +360 -0
- package/src/translate/getLanguageParams.ts +26 -0
- package/src/translate/languageStore.ts +18 -0
- package/src/translate/paths.test.ts +133 -0
- package/src/translate/paths.ts +175 -0
- package/src/translate/translateActions.tsx +188 -0
- package/src/translate/types.ts +160 -0
- package/src/types.ts +67 -15
- package/src/useApiClient.ts +134 -2
- package/src/assistLayout/AlphaMigration.tsx +0 -310
- package/src/legacy-types.ts +0 -72
|
@@ -32,7 +32,7 @@ describe('serializeSchema', () => {
|
|
|
32
32
|
name: 'article',
|
|
33
33
|
fields: [{type: 'string', name: 'title'}],
|
|
34
34
|
options: {
|
|
35
|
-
|
|
35
|
+
aiAssist: {
|
|
36
36
|
exclude: true,
|
|
37
37
|
},
|
|
38
38
|
},
|
|
@@ -123,7 +123,7 @@ describe('serializeSchema', () => {
|
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
test('should not serialize excluded fields or types or types with every member excluded', () => {
|
|
126
|
-
const options: AssistOptions = {
|
|
126
|
+
const options: AssistOptions = {aiAssist: {exclude: true}}
|
|
127
127
|
|
|
128
128
|
const schema = Schema.compile({
|
|
129
129
|
name: 'test',
|
|
@@ -138,14 +138,14 @@ describe('serializeSchema', () => {
|
|
|
138
138
|
name: 'excludedObject',
|
|
139
139
|
// all fields excluded should exclude field
|
|
140
140
|
fields: [{type: 'string', name: 'title', options}],
|
|
141
|
-
options: {
|
|
141
|
+
options: {aiAssist: {exclude: true}},
|
|
142
142
|
}),
|
|
143
143
|
defineField({
|
|
144
144
|
type: 'array',
|
|
145
145
|
name: 'excludedArray',
|
|
146
146
|
// all items excluded should exclude field
|
|
147
147
|
of: [{type: 'object', name: 'remove', options}, {type: 'excluded'}],
|
|
148
|
-
options: {
|
|
148
|
+
options: {aiAssist: {exclude: true}},
|
|
149
149
|
}),
|
|
150
150
|
//image without extra fields should be excluded
|
|
151
151
|
defineField({type: 'image', name: 'image'}),
|
|
@@ -169,7 +169,7 @@ describe('serializeSchema', () => {
|
|
|
169
169
|
type: 'object',
|
|
170
170
|
name: 'excluded',
|
|
171
171
|
fields: [{type: 'string', name: 'title', options}],
|
|
172
|
-
options: {
|
|
172
|
+
options: {aiAssist: {exclude: true}},
|
|
173
173
|
}),
|
|
174
174
|
...mockStudioTypes,
|
|
175
175
|
],
|
|
@@ -484,7 +484,7 @@ describe('serializeSchema', () => {
|
|
|
484
484
|
])
|
|
485
485
|
})
|
|
486
486
|
|
|
487
|
-
test('should
|
|
487
|
+
test('should annotate truthy readonly', () => {
|
|
488
488
|
const schema = Schema.compile({
|
|
489
489
|
name: 'test',
|
|
490
490
|
types: [
|
|
@@ -492,7 +492,7 @@ describe('serializeSchema', () => {
|
|
|
492
492
|
type: 'document',
|
|
493
493
|
name: 'article',
|
|
494
494
|
fields: [
|
|
495
|
-
{type: 'string', name: 'title',
|
|
495
|
+
{type: 'string', name: 'title', readOnly: () => true},
|
|
496
496
|
{type: 'some', name: 'some'},
|
|
497
497
|
],
|
|
498
498
|
},
|
|
@@ -507,6 +507,237 @@ describe('serializeSchema', () => {
|
|
|
507
507
|
|
|
508
508
|
const serializedTypes = serializeSchema(schema, {leanFormat: true})
|
|
509
509
|
|
|
510
|
-
expect(serializedTypes).toEqual([
|
|
510
|
+
expect(serializedTypes).toEqual([
|
|
511
|
+
{
|
|
512
|
+
name: 'article',
|
|
513
|
+
title: 'Article',
|
|
514
|
+
type: 'document',
|
|
515
|
+
fields: [
|
|
516
|
+
{name: 'title', readOnly: 'function', title: 'Title', type: 'string'},
|
|
517
|
+
{name: 'some', readOnly: true, title: 'Some', type: 'some'},
|
|
518
|
+
],
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: 'some',
|
|
522
|
+
readOnly: true,
|
|
523
|
+
title: 'Some',
|
|
524
|
+
type: 'object',
|
|
525
|
+
fields: [{name: 'title', title: 'Title', type: 'string'}],
|
|
526
|
+
},
|
|
527
|
+
])
|
|
528
|
+
})
|
|
529
|
+
|
|
530
|
+
test('should annotate truthy hidden', () => {
|
|
531
|
+
const schema = Schema.compile({
|
|
532
|
+
name: 'test',
|
|
533
|
+
types: [
|
|
534
|
+
{
|
|
535
|
+
type: 'document',
|
|
536
|
+
name: 'article',
|
|
537
|
+
fields: [
|
|
538
|
+
{type: 'string', name: 'title', hidden: true},
|
|
539
|
+
{type: 'some', name: 'some'},
|
|
540
|
+
],
|
|
541
|
+
},
|
|
542
|
+
defineType({
|
|
543
|
+
type: 'object',
|
|
544
|
+
name: 'some',
|
|
545
|
+
hidden: () => true,
|
|
546
|
+
fields: [{type: 'string', name: 'title'}],
|
|
547
|
+
}),
|
|
548
|
+
],
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
const serializedTypes = serializeSchema(schema, {leanFormat: true})
|
|
552
|
+
|
|
553
|
+
expect(serializedTypes).toEqual([
|
|
554
|
+
{
|
|
555
|
+
name: 'article',
|
|
556
|
+
title: 'Article',
|
|
557
|
+
type: 'document',
|
|
558
|
+
fields: [
|
|
559
|
+
{hidden: true, name: 'title', title: 'Title', type: 'string'},
|
|
560
|
+
{hidden: 'function', name: 'some', title: 'Some', type: 'some'},
|
|
561
|
+
],
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
hidden: 'function',
|
|
565
|
+
name: 'some',
|
|
566
|
+
title: 'Some',
|
|
567
|
+
type: 'object',
|
|
568
|
+
fields: [{name: 'title', title: 'Title', type: 'string'}],
|
|
569
|
+
},
|
|
570
|
+
])
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
test('should serialize annotations', () => {
|
|
574
|
+
const schema = Schema.compile({
|
|
575
|
+
name: 'test',
|
|
576
|
+
types: [
|
|
577
|
+
defineType({
|
|
578
|
+
type: 'object',
|
|
579
|
+
name: 'annotation',
|
|
580
|
+
fields: [defineField({type: 'string', name: 'fact', title: 'Fact'})],
|
|
581
|
+
}),
|
|
582
|
+
defineType({
|
|
583
|
+
name: 'blockAlias',
|
|
584
|
+
type: 'block',
|
|
585
|
+
marks: {annotations: [{type: 'annotation'}]},
|
|
586
|
+
}),
|
|
587
|
+
defineType({
|
|
588
|
+
type: 'document',
|
|
589
|
+
name: 'article',
|
|
590
|
+
fields: [
|
|
591
|
+
{
|
|
592
|
+
type: 'array',
|
|
593
|
+
name: 'inlinePte',
|
|
594
|
+
of: [
|
|
595
|
+
defineArrayMember({
|
|
596
|
+
type: 'block',
|
|
597
|
+
marks: {
|
|
598
|
+
annotations: [
|
|
599
|
+
defineArrayMember({
|
|
600
|
+
type: 'object',
|
|
601
|
+
name: 'inline-annotation',
|
|
602
|
+
fields: [defineField({type: 'string', name: 'fact', title: 'Fact'})],
|
|
603
|
+
}),
|
|
604
|
+
],
|
|
605
|
+
},
|
|
606
|
+
}),
|
|
607
|
+
],
|
|
608
|
+
},
|
|
609
|
+
{type: 'array', name: 'pte', of: [{type: 'blockAlias'}]},
|
|
610
|
+
],
|
|
611
|
+
}),
|
|
612
|
+
],
|
|
613
|
+
})
|
|
614
|
+
|
|
615
|
+
const serializedTypes = serializeSchema(schema, {leanFormat: true})
|
|
616
|
+
|
|
617
|
+
expect(serializedTypes).toEqual([
|
|
618
|
+
{
|
|
619
|
+
name: 'annotation',
|
|
620
|
+
title: 'Annotation',
|
|
621
|
+
type: 'object',
|
|
622
|
+
fields: [{name: 'fact', title: 'Fact', type: 'string'}],
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
name: 'article',
|
|
626
|
+
title: 'Article',
|
|
627
|
+
type: 'document',
|
|
628
|
+
fields: [
|
|
629
|
+
{
|
|
630
|
+
name: 'inlinePte',
|
|
631
|
+
title: 'Inline Pte',
|
|
632
|
+
type: 'array',
|
|
633
|
+
of: [
|
|
634
|
+
{
|
|
635
|
+
name: 'block',
|
|
636
|
+
title: 'Block',
|
|
637
|
+
type: 'block',
|
|
638
|
+
inlineOf: [],
|
|
639
|
+
annotations: [
|
|
640
|
+
{
|
|
641
|
+
name: 'inline-annotation',
|
|
642
|
+
title: 'Inline Annotation',
|
|
643
|
+
type: 'object',
|
|
644
|
+
fields: [{name: 'fact', title: 'Fact', type: 'string'}],
|
|
645
|
+
},
|
|
646
|
+
],
|
|
647
|
+
},
|
|
648
|
+
],
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
name: 'pte',
|
|
652
|
+
of: [{name: 'blockAlias', title: 'Block', type: 'blockAlias'}],
|
|
653
|
+
title: 'Pte',
|
|
654
|
+
type: 'array',
|
|
655
|
+
},
|
|
656
|
+
],
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
name: 'blockAlias',
|
|
660
|
+
title: 'Block',
|
|
661
|
+
type: 'block',
|
|
662
|
+
annotations: [{name: 'annotation', title: 'Annotation', type: 'annotation'}],
|
|
663
|
+
inlineOf: [],
|
|
664
|
+
},
|
|
665
|
+
])
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
test('should serialize inline block types', () => {
|
|
669
|
+
const schema = Schema.compile({
|
|
670
|
+
name: 'test',
|
|
671
|
+
types: [
|
|
672
|
+
defineType({
|
|
673
|
+
type: 'object',
|
|
674
|
+
name: 'inline-block',
|
|
675
|
+
fields: [
|
|
676
|
+
defineField({type: 'string', name: 'fact', title: 'Fact'}),
|
|
677
|
+
defineField({type: 'blockAlias', name: 'recurse', title: 'Recursive'}),
|
|
678
|
+
],
|
|
679
|
+
}),
|
|
680
|
+
defineType({
|
|
681
|
+
name: 'blockAlias',
|
|
682
|
+
type: 'block',
|
|
683
|
+
of: [{type: 'inline-block'}],
|
|
684
|
+
}),
|
|
685
|
+
defineType({
|
|
686
|
+
type: 'document',
|
|
687
|
+
name: 'article',
|
|
688
|
+
fields: [{type: 'array', name: 'pte', of: [{type: 'blockAlias'}]}],
|
|
689
|
+
}),
|
|
690
|
+
],
|
|
691
|
+
})
|
|
692
|
+
|
|
693
|
+
const serializedTypes = serializeSchema(schema, {leanFormat: true})
|
|
694
|
+
|
|
695
|
+
expect(serializedTypes).toEqual([
|
|
696
|
+
{
|
|
697
|
+
name: 'article',
|
|
698
|
+
title: 'Article',
|
|
699
|
+
type: 'document',
|
|
700
|
+
fields: [
|
|
701
|
+
{
|
|
702
|
+
name: 'pte',
|
|
703
|
+
of: [
|
|
704
|
+
{
|
|
705
|
+
name: 'blockAlias',
|
|
706
|
+
title: 'Block',
|
|
707
|
+
type: 'blockAlias',
|
|
708
|
+
},
|
|
709
|
+
],
|
|
710
|
+
title: 'Pte',
|
|
711
|
+
type: 'array',
|
|
712
|
+
},
|
|
713
|
+
],
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
name: 'blockAlias',
|
|
717
|
+
title: 'Block',
|
|
718
|
+
type: 'block',
|
|
719
|
+
annotations: [],
|
|
720
|
+
inlineOf: [
|
|
721
|
+
{
|
|
722
|
+
name: 'inline-block',
|
|
723
|
+
title: 'Inline Block',
|
|
724
|
+
type: 'inline-block',
|
|
725
|
+
},
|
|
726
|
+
],
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
name: 'inline-block',
|
|
730
|
+
title: 'Inline Block',
|
|
731
|
+
type: 'object',
|
|
732
|
+
fields: [
|
|
733
|
+
{name: 'fact', title: 'Fact', type: 'string'},
|
|
734
|
+
{
|
|
735
|
+
name: 'recurse',
|
|
736
|
+
title: 'Recursive',
|
|
737
|
+
type: 'blockAlias',
|
|
738
|
+
},
|
|
739
|
+
],
|
|
740
|
+
},
|
|
741
|
+
])
|
|
511
742
|
})
|
|
512
743
|
})
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ArraySchemaType,
|
|
3
3
|
ImageOptions,
|
|
4
|
+
isArraySchemaType,
|
|
4
5
|
ObjectSchemaType,
|
|
6
|
+
ReferenceOptions,
|
|
5
7
|
ReferenceSchemaType,
|
|
6
8
|
Schema,
|
|
7
9
|
SchemaType,
|
|
8
10
|
typed,
|
|
9
11
|
} from 'sanity'
|
|
10
12
|
import {
|
|
13
|
+
assistSchemaIdPrefix,
|
|
11
14
|
assistSerializedFieldTypeName,
|
|
12
15
|
assistSerializedTypeName,
|
|
13
16
|
SerializedSchemaMember,
|
|
14
17
|
SerializedSchemaType,
|
|
15
|
-
assistSchemaIdPrefix,
|
|
16
18
|
} from '../../types'
|
|
17
19
|
import {hiddenTypes} from './schemaUtils'
|
|
18
20
|
import {isAssistSupported} from '../../helpers/assistSupported'
|
|
21
|
+
import {isType} from '../../helpers/typeUtils'
|
|
19
22
|
|
|
20
23
|
interface Options {
|
|
21
24
|
leanFormat?: boolean
|
|
@@ -31,7 +34,6 @@ export function serializeSchema(schema: Schema, options?: Options): SerializedSc
|
|
|
31
34
|
.filter((t): t is SchemaType => !!t)
|
|
32
35
|
// because a field can override exclude at the type level, we have to also serialize excluded types
|
|
33
36
|
// so don't do this: .filter((t) => isAssistSupported(t))
|
|
34
|
-
.filter((t) => !t.hidden && !t.readOnly)
|
|
35
37
|
.map((t) => getSchemaStub(t, schema, options))
|
|
36
38
|
.filter((t) => {
|
|
37
39
|
if ('to' in t && t.to && !t.to.length) {
|
|
@@ -78,13 +80,12 @@ function getBaseFields(
|
|
|
78
80
|
typeName: string,
|
|
79
81
|
options: Options | undefined
|
|
80
82
|
) {
|
|
81
|
-
const
|
|
83
|
+
const schemaOptions: SerializedSchemaType['options'] = removeUndef({
|
|
84
|
+
imagePromptField: (type.options as ImageOptions)?.aiAssist?.imageInstructionField,
|
|
85
|
+
embeddingsIndex: (type.options as ReferenceOptions)?.aiAssist?.embeddingsIndex,
|
|
86
|
+
})
|
|
82
87
|
return removeUndef({
|
|
83
|
-
options:
|
|
84
|
-
? {
|
|
85
|
-
imagePromptField: imagePromptField,
|
|
86
|
-
}
|
|
87
|
-
: undefined,
|
|
88
|
+
options: Object.keys(schemaOptions).length ? schemaOptions : undefined,
|
|
88
89
|
values: Array.isArray(type?.options?.list)
|
|
89
90
|
? type?.options?.list.map((v: string | {value: string; title: string}) =>
|
|
90
91
|
typeof v === 'string' ? v : v.value ?? `${v.title}`
|
|
@@ -99,6 +100,22 @@ function getBaseFields(
|
|
|
99
100
|
'fields' in type && inlineTypes.includes(typeName)
|
|
100
101
|
? serializeFields(schema, type, options)
|
|
101
102
|
: undefined,
|
|
103
|
+
annotations:
|
|
104
|
+
typeName === 'block' && 'fields' in type
|
|
105
|
+
? serializeAnnotations(type, schema, options)
|
|
106
|
+
: undefined,
|
|
107
|
+
inlineOf:
|
|
108
|
+
typeName === 'block' && 'fields' in type
|
|
109
|
+
? serializeInlineOf(type, schema, options)
|
|
110
|
+
: undefined,
|
|
111
|
+
hidden:
|
|
112
|
+
typeof type.hidden === 'function' ? ('function' as const) : type.hidden ? true : undefined,
|
|
113
|
+
readOnly:
|
|
114
|
+
typeof type.readOnly === 'function'
|
|
115
|
+
? ('function' as const)
|
|
116
|
+
: type.readOnly
|
|
117
|
+
? true
|
|
118
|
+
: undefined,
|
|
102
119
|
})
|
|
103
120
|
}
|
|
104
121
|
|
|
@@ -107,10 +124,27 @@ function serializeFields(
|
|
|
107
124
|
schemaType: ObjectSchemaType,
|
|
108
125
|
options: Options | undefined
|
|
109
126
|
) {
|
|
110
|
-
|
|
127
|
+
const fields = schemaType.fieldsets
|
|
128
|
+
? schemaType.fieldsets.flatMap((fs) =>
|
|
129
|
+
fs.single
|
|
130
|
+
? fs.field
|
|
131
|
+
: fs.fields.map((f) => ({
|
|
132
|
+
...f,
|
|
133
|
+
type: {
|
|
134
|
+
...f.type,
|
|
135
|
+
// if fieldset is (conditionally) hidden, the field must be considered the same way
|
|
136
|
+
// ie, if the field does not show up in conditionalMembers, it is hidden
|
|
137
|
+
// regardless of weather or not it is the field function or the fieldset function that hides it
|
|
138
|
+
hidden:
|
|
139
|
+
typeof fs.hidden === 'function' ? fs.hidden : fs.hidden ? true : f.type.hidden,
|
|
140
|
+
},
|
|
141
|
+
}))
|
|
142
|
+
)
|
|
143
|
+
: schemaType.fields
|
|
144
|
+
|
|
145
|
+
return fields
|
|
111
146
|
.filter((f) => !['sanity.imageHotspot', 'sanity.imageCrop'].includes(f.type?.name ?? ''))
|
|
112
147
|
.filter((f) => isAssistSupported(f.type))
|
|
113
|
-
.filter((f) => !f.type.hidden && !f.type.readOnly)
|
|
114
148
|
.map((field) => serializeMember(schema, field.type, field.name, options))
|
|
115
149
|
}
|
|
116
150
|
|
|
@@ -131,6 +165,39 @@ function serializeMember(
|
|
|
131
165
|
})
|
|
132
166
|
}
|
|
133
167
|
|
|
168
|
+
function serializeInlineOf(
|
|
169
|
+
blockSchemaType: ObjectSchemaType,
|
|
170
|
+
schema: Schema,
|
|
171
|
+
options: Options | undefined
|
|
172
|
+
): SerializedSchemaMember[] | undefined {
|
|
173
|
+
const childrenField = blockSchemaType.fields.find((f) => f.name === 'children')
|
|
174
|
+
const childrenType = childrenField?.type
|
|
175
|
+
if (!childrenType || !isArraySchemaType(childrenType)) {
|
|
176
|
+
return undefined
|
|
177
|
+
}
|
|
178
|
+
return arrayOf(
|
|
179
|
+
{
|
|
180
|
+
...childrenType,
|
|
181
|
+
of: childrenType.of.filter((t) => !isType(t, 'span')),
|
|
182
|
+
},
|
|
183
|
+
schema,
|
|
184
|
+
options
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function serializeAnnotations(
|
|
189
|
+
blockSchemaType: ObjectSchemaType,
|
|
190
|
+
schema: Schema,
|
|
191
|
+
options: Options | undefined
|
|
192
|
+
): SerializedSchemaMember[] | undefined {
|
|
193
|
+
const markDefs = blockSchemaType.fields.find((f) => f.name === 'markDefs')
|
|
194
|
+
const marksType = markDefs?.type
|
|
195
|
+
if (!marksType || !isArraySchemaType(marksType)) {
|
|
196
|
+
return undefined
|
|
197
|
+
}
|
|
198
|
+
return arrayOf(marksType, schema, options)
|
|
199
|
+
}
|
|
200
|
+
|
|
134
201
|
function arrayOf(
|
|
135
202
|
arrayType: ArraySchemaType,
|
|
136
203
|
schema: Schema,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
2
|
export interface AssistOptions {
|
|
3
|
-
|
|
3
|
+
aiAssist?: {
|
|
4
4
|
/** Set to true to disable assistance for this field or type */
|
|
5
5
|
exclude?: boolean
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Set to true to add translation field-action to the field.
|
|
9
|
+
* Only has an effect in document types configured for document or field level translations.
|
|
10
|
+
*/
|
|
11
|
+
translateAction?: boolean
|
|
6
12
|
}
|
|
7
13
|
}
|
|
8
14
|
|
|
@@ -16,13 +22,91 @@ declare module 'sanity' {
|
|
|
16
22
|
interface DocumentOptions extends AssistOptions {}
|
|
17
23
|
interface FileOptions extends AssistOptions {}
|
|
18
24
|
interface GeopointOptions extends AssistOptions {}
|
|
19
|
-
interface ImageOptions
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
interface ImageOptions {
|
|
26
|
+
aiAssist?: AssistOptions['aiAssist'] & {
|
|
27
|
+
/**
|
|
28
|
+
* When set, an image will be created whenever the `imageInstructionField` is written to by
|
|
29
|
+
* an AI Assist instruction.
|
|
30
|
+
*
|
|
31
|
+
* The value output by AI Assist will be use as an image prompt for an generative image AI.
|
|
32
|
+
*
|
|
33
|
+
* This means that instructions directly for the field or instructions that visit the field when running,
|
|
34
|
+
* will result in the image being changed.
|
|
35
|
+
*
|
|
36
|
+
* `imageInstructionField` must be a child-path relative to the image field, ie:
|
|
37
|
+
* * field
|
|
38
|
+
* * path.to.field
|
|
39
|
+
*
|
|
40
|
+
* ### Example
|
|
41
|
+
* ```ts
|
|
42
|
+
* defineType({
|
|
43
|
+
* type: 'image',
|
|
44
|
+
* name: 'articleImage',
|
|
45
|
+
* fields: [
|
|
46
|
+
* defineField({
|
|
47
|
+
* type: 'text',
|
|
48
|
+
* name: 'imagePrompt',
|
|
49
|
+
* title: 'Image prompt',
|
|
50
|
+
* rows: 2,
|
|
51
|
+
* }),
|
|
52
|
+
* ],
|
|
53
|
+
* options: {
|
|
54
|
+
* aiAssist: {
|
|
55
|
+
* imageInstructionField: 'imagePrompt',
|
|
56
|
+
* }
|
|
57
|
+
* },
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
imageInstructionField?: string
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* When set, an image description will be automatically created for the image.
|
|
65
|
+
*
|
|
66
|
+
* `imageDescriptionField` must be a child-path relative to the image field, ie:
|
|
67
|
+
* * field
|
|
68
|
+
* * path.to.field
|
|
69
|
+
*
|
|
70
|
+
* Whenever the image asset for the field is changed in the Studio,
|
|
71
|
+
* an image description is generated and set into the `imageDescriptionField`.
|
|
72
|
+
*
|
|
73
|
+
* ### Example
|
|
74
|
+
* ```ts
|
|
75
|
+
* defineType({
|
|
76
|
+
* type: 'image',
|
|
77
|
+
* name: 'articleImage',
|
|
78
|
+
* fields: [
|
|
79
|
+
* defineField({
|
|
80
|
+
* type: 'string',
|
|
81
|
+
* name: 'altText',
|
|
82
|
+
* title: 'Alt text',
|
|
83
|
+
* }),
|
|
84
|
+
* ],
|
|
85
|
+
* options: {
|
|
86
|
+
* aiAssist: {
|
|
87
|
+
* imageDescriptionField: 'altText',
|
|
88
|
+
* }
|
|
89
|
+
* },
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
imageDescriptionField?: string
|
|
94
|
+
}
|
|
22
95
|
}
|
|
23
96
|
interface NumberOptions extends AssistOptions {}
|
|
24
97
|
interface ObjectOptions extends AssistOptions {}
|
|
25
|
-
interface ReferenceBaseOptions
|
|
98
|
+
interface ReferenceBaseOptions {
|
|
99
|
+
aiAssist?: {
|
|
100
|
+
/** Set to true to disable assistance for this field or type */
|
|
101
|
+
exclude?: boolean
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* When set, the reference field will allow instructions to be added to it.
|
|
105
|
+
* Should be the name of the embeddings-index where assist will look for contextually relevant documents
|
|
106
|
+
* */
|
|
107
|
+
embeddingsIndex?: string
|
|
108
|
+
}
|
|
109
|
+
}
|
|
26
110
|
interface SlugOptions extends AssistOptions {}
|
|
27
111
|
interface StringOptions extends AssistOptions {}
|
|
28
112
|
interface TextOptions extends AssistOptions {}
|