@sanity/assist 2.0.5 → 3.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.
@@ -0,0 +1,377 @@
1
+ import {JSX as JSX_2} from 'react/jsx-runtime'
2
+ import {Path} from 'sanity'
3
+ import {Plugin as Plugin_2} from 'sanity'
4
+ import {PortableTextBlock} from '@portabletext/types'
5
+ import {PortableTextMarkDefinition} from '@portabletext/types'
6
+ import {PortableTextSpan} from '@portabletext/types'
7
+ import {SanityClient} from 'sanity'
8
+ import {SanityClient as SanityClient_2} from '@sanity/client'
9
+ import {SchemaType} from 'sanity'
10
+
11
+ export declare const assist: Plugin_2<void | AssistPluginConfig>
12
+
13
+ export declare interface AssistOptions {
14
+ aiAssist?: {
15
+ /** Set to true to disable assistance for this field or type */
16
+ exclude?: boolean
17
+ /**
18
+ * Set to true to add translation field-action to the field.
19
+ * Only has an effect in document types configured for document or field level translations.
20
+ */
21
+ translateAction?: boolean
22
+ }
23
+ }
24
+
25
+ declare interface AssistPluginConfig {
26
+ translate?: TranslationConfig
27
+ /**
28
+ * @internal
29
+ */
30
+ __customApiClient?: (defaultClient: SanityClient_2) => SanityClient_2
31
+ /**
32
+ * @internal
33
+ */
34
+ __presets?: Record<string, AssistPreset>
35
+ }
36
+
37
+ declare interface AssistPreset {
38
+ fields?: PresetField[]
39
+ }
40
+
41
+ declare interface ContextBlock {
42
+ _type: typeof instructionContextTypeName
43
+ reference?: {
44
+ _type: 'reference'
45
+ _ref?: string
46
+ }
47
+ }
48
+
49
+ export declare const contextDocumentTypeName: 'assist.instruction.context'
50
+
51
+ /**
52
+ * Default implementation for plugin config `translate.field.translationOutputs`
53
+ *
54
+ * @see FieldTranslationConfig#translationOutputs
55
+ */
56
+ export declare const defaultLanguageOutputs: TranslationOutputsFunction
57
+
58
+ export declare interface DocumentMember {
59
+ schemaType: SchemaType
60
+ path: Path
61
+ name: string
62
+ value: unknown
63
+ }
64
+
65
+ export declare interface DocumentTranslationConfig {
66
+ /**
67
+ * Path to language field in documents. Can be a hidden field.
68
+ * For instance: 'config.language'
69
+ *
70
+ * For projects that use the `@sanity/document-internationalization` plugin,
71
+ * this should be the same as `languageField` config for that plugin.
72
+ *
73
+ * Default: 'language'
74
+ */
75
+ languageField: string
76
+ /**
77
+ * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
78
+ *
79
+ * If defined, this property will add a translate instruction to these document types.
80
+ * If undefined, the instruction will be added to all documents with aiAssistance enabled and a field matching `documentLanguageField` config.
81
+ *
82
+ * Documents with translation support will get a "Translate document>" instruction added.
83
+ **/
84
+ documentTypes?: string[]
85
+ }
86
+
87
+ declare interface FieldRef extends PortableTextMarkDefinition {
88
+ _type: typeof fieldReferenceTypeName
89
+ path?: string
90
+ }
91
+
92
+ declare const fieldReferenceTypeName: 'sanity.assist.instruction.fieldRef'
93
+
94
+ export declare interface FieldTranslationConfig {
95
+ /**
96
+ * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
97
+ *
98
+ * If defined, matching document will get a "Translate fields" instruction added.
99
+ **/
100
+ documentTypes?: string[]
101
+ /**
102
+ *
103
+ * Used for display strings in the Studio, and to determine languages for field level translations
104
+ *
105
+ * If the studio is using the sanity-plugin-internationalized-array plugin, this
106
+ * should be set to the same configuration.
107
+ */
108
+ languages: Language[] | LanguageCallback
109
+ /**
110
+ * API version for client passed to LanguageCallback for languages
111
+ * https://www.sanity.io/docs/api-versioning
112
+ * @defaultValue '2022-11-27'
113
+ */
114
+ apiVersion?: string
115
+ /**
116
+ * Specify fields that should be available in the languages callback:
117
+ * ```tsx
118
+ * {
119
+ * select: {
120
+ * markets: 'markets'
121
+ * },
122
+ * languages: (client, {markets}) =>
123
+ * client.fetch('*[_type == "language" && market in $markets]{id,title}', {markets})
124
+ * }
125
+ * ```
126
+ *
127
+ * If the studio is using the sanity-plugin-internationalized-array plugin, this
128
+ * should be set to the same configuration.
129
+ */
130
+ selectLanguageParams?: Record<string, string>
131
+ /**
132
+ * `translationOutputs` is used when the "Translate fields" instruction is started by a Studio user.
133
+ *
134
+ * It determines the relationships between document paths: Given a document path and a language, into which
135
+ * sibling paths should translations be output.
136
+
137
+ *
138
+ * `translationOutputs` is invoked once per path in the document (limited to a depth of 6), with the following:
139
+ *
140
+ * * `documentMember` - the field or array item for a given path; contains the path and its schemaType,
141
+ * * `enclosingType` - the schema type of parent holding the member
142
+ * * `translateFromLanguageId` - the languageId for the language the user want to translate from
143
+ * * `translateToLanguageIds` - all languageIds the user can translate to
144
+ *
145
+ * The function should return a `TranslationOutput[]` array that contains all the paths where translations from
146
+ * documentMember language (translateFromLanguageId) should be output.
147
+ *
148
+ * The function should return `undefined` for all documentMembers that should not be directly translated,
149
+ * or are nested fields under a translated path.
150
+ *
151
+ * ## Default function
152
+ *
153
+ * The default function for `translationOutputs` is configured to be automatically compatible with sanity-plugin-internationalized-array
154
+ * and object types prefixed with "locale".
155
+ *
156
+ * See <link to source for defaultTranslationOutputs> implementation details.
157
+ *
158
+ * ## Example
159
+ * A document has the following document members:
160
+ * * `{path: 'localeObject.en', schemaType: ObjectSchemaType}`
161
+ * * `{path: 'localeObject.en.title', schemaType: StringSchemaType}`
162
+ * * `{path: 'localeObject.de', schemaType: ObjectSchemaType}`,
163
+ * * `{path: 'localeObject.de.title', schemaType: StringSchemaType}`
164
+ *
165
+ * `translationOutputs` for invoked with `translateFromLanguageId` `en`,
166
+ * should only return [{id: 'de', outputPath: 'localeObject.de'}] for the `'localeObject.en'` path,
167
+ * and undefined for all the other members.
168
+ *
169
+ * ### Example implementation
170
+ * ```ts
171
+ * function translationOutputs(member, enclosingType, translateFromLanguageId, translateToLanguageIds)
172
+ * if (enclosingType.jsonType === 'object' && enclosingType.name.startsWith('locale') && translateFromLanguageId === member.name) {
173
+ * return translateToLanguageIds.map((translateToId) => ({
174
+ * id: translateToId,
175
+ * outputPath: [...member.path.slice(0, -1), translateToId],
176
+ * }))
177
+ * }
178
+ * return undefined
179
+ * }
180
+ * ```
181
+ **/
182
+ translationOutputs?: TranslationOutputsFunction
183
+ }
184
+
185
+ declare type InlinePromptBlock = PortableTextSpan | FieldRef | UserInputBlock | ContextBlock
186
+
187
+ declare const instructionContextTypeName: 'sanity.assist.instruction.context'
188
+
189
+ export declare interface Language {
190
+ id: string
191
+ title?: string
192
+ }
193
+
194
+ export declare type LanguageCallback = (
195
+ client: SanityClient,
196
+ selectedLanguageParams: Record<string, unknown>,
197
+ ) => Promise<Language[]>
198
+
199
+ declare interface OutputFieldItem {
200
+ _type: typeof outputFieldTypeName
201
+ _key: string
202
+ relativePath?: string
203
+ }
204
+
205
+ declare const outputFieldTypeName: 'sanity.assist.output.field'
206
+
207
+ declare interface OutputTypeItem {
208
+ _type: typeof outputTypeTypeName
209
+ _key: string
210
+ type?: string
211
+ relativePath?: string
212
+ }
213
+
214
+ declare const outputTypeTypeName: 'sanity.assist.output.type'
215
+
216
+ declare interface PresetField {
217
+ path?: string
218
+ instructions?: PresetInstruction[]
219
+ }
220
+
221
+ declare interface PresetInstruction {
222
+ _key: string
223
+ prompt?: PromptTextBlock[]
224
+ title?: string
225
+ /**
226
+ * String key from @sanity/icons IconMap
227
+ */
228
+ icon?: string
229
+ /**
230
+ * Type/field filter
231
+ */
232
+ output?: (OutputFieldItem | OutputTypeItem)[]
233
+ }
234
+
235
+ declare type PromptTextBlock = Omit<
236
+ PortableTextBlock<never, InlinePromptBlock, 'normal', never>,
237
+ '_type'
238
+ > & {
239
+ _type: 'block'
240
+ }
241
+
242
+ export declare function SchemaTypeTool(): JSX_2.Element
243
+
244
+ export declare interface TranslationConfig {
245
+ /**
246
+ * Config for document types with fields in multiple languages in the same document.
247
+ */
248
+ field?: FieldTranslationConfig
249
+ /**
250
+ * Config for document types with a single language field that determines the language for the whole document.
251
+ */
252
+ document?: DocumentTranslationConfig
253
+ }
254
+
255
+ export declare interface TranslationOutput {
256
+ /** Language id */
257
+ id: string
258
+ outputPath: Path
259
+ }
260
+
261
+ export declare type TranslationOutputsFunction = (
262
+ documentMember: DocumentMember,
263
+ enclosingType: SchemaType,
264
+ translateFromLanguageId: string,
265
+ translateToLanguageIds: string[],
266
+ ) => TranslationOutput[] | undefined
267
+
268
+ declare interface UserInputBlock {
269
+ _type: typeof userInputTypeName
270
+ _key: string
271
+ message?: string
272
+ description?: string
273
+ }
274
+
275
+ declare const userInputTypeName: 'sanity.assist.instruction.userInput'
276
+
277
+ export {}
278
+
279
+ declare module 'sanity' {
280
+ interface ArrayOptions extends AssistOptions {}
281
+ interface BlockOptions extends AssistOptions {}
282
+ interface BooleanOptions extends AssistOptions {}
283
+ interface CrossDatasetReferenceOptions extends AssistOptions {}
284
+ interface DateOptions extends AssistOptions {}
285
+ interface DatetimeOptions extends AssistOptions {}
286
+ interface DocumentOptions extends AssistOptions {}
287
+ interface FileOptions extends AssistOptions {}
288
+ interface GeopointOptions extends AssistOptions {}
289
+ interface ImageOptions {
290
+ aiAssist?: AssistOptions['aiAssist'] & {
291
+ /**
292
+ * When set, an image will be created whenever the `imageInstructionField` is written to by
293
+ * an AI Assist instruction.
294
+ *
295
+ * The value output by AI Assist will be use as an image prompt for an generative image AI.
296
+ *
297
+ * This means that instructions directly for the field or instructions that visit the field when running,
298
+ * will result in the image being changed.
299
+ *
300
+ * `imageInstructionField` must be a child-path relative to the image field, ie:
301
+ * * field
302
+ * * path.to.field
303
+ *
304
+ * ### Example
305
+ * ```ts
306
+ * defineType({
307
+ * type: 'image',
308
+ * name: 'articleImage',
309
+ * fields: [
310
+ * defineField({
311
+ * type: 'text',
312
+ * name: 'imagePrompt',
313
+ * title: 'Image prompt',
314
+ * rows: 2,
315
+ * }),
316
+ * ],
317
+ * options: {
318
+ * aiAssist: {
319
+ * imageInstructionField: 'imagePrompt',
320
+ * }
321
+ * },
322
+ * })
323
+ * ```
324
+ */
325
+ imageInstructionField?: string
326
+ /**
327
+ * When set, an image description will be automatically created for the image.
328
+ *
329
+ * `imageDescriptionField` must be a child-path relative to the image field, ie:
330
+ * * field
331
+ * * path.to.field
332
+ *
333
+ * Whenever the image asset for the field is changed in the Studio,
334
+ * an image description is generated and set into the `imageDescriptionField`.
335
+ *
336
+ * ### Example
337
+ * ```ts
338
+ * defineType({
339
+ * type: 'image',
340
+ * name: 'articleImage',
341
+ * fields: [
342
+ * defineField({
343
+ * type: 'string',
344
+ * name: 'altText',
345
+ * title: 'Alt text',
346
+ * }),
347
+ * ],
348
+ * options: {
349
+ * aiAssist: {
350
+ * imageDescriptionField: 'altText',
351
+ * }
352
+ * },
353
+ * })
354
+ * ```
355
+ */
356
+ imageDescriptionField?: string
357
+ }
358
+ }
359
+ interface NumberOptions extends AssistOptions {}
360
+ interface ObjectOptions extends AssistOptions {}
361
+ interface ReferenceBaseOptions {
362
+ aiAssist?: {
363
+ /** Set to true to disable assistance for this field or type */
364
+ exclude?: boolean
365
+ /**
366
+ * When set, the reference field will allow instructions to be added to it.
367
+ * Should be the name of the embeddings-index where assist will look for contextually relevant documents
368
+ * */
369
+ embeddingsIndex?: string
370
+ }
371
+ }
372
+ interface SlugOptions extends AssistOptions {}
373
+ interface StringOptions extends AssistOptions {}
374
+ interface TextOptions extends AssistOptions {}
375
+ interface UrlOptions extends AssistOptions {}
376
+ interface EmailOptions extends AssistOptions {}
377
+ }