@sanity/assist 5.0.4 → 6.0.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.
Files changed (131) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +28 -254
  3. package/dist/index.d.ts +322 -410
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +3181 -2649
  6. package/dist/index.js.map +1 -1
  7. package/package.json +38 -78
  8. package/dist/index.cjs +0 -4239
  9. package/dist/index.cjs.map +0 -1
  10. package/dist/index.d.cts +0 -791
  11. package/sanity.json +0 -8
  12. package/src/_lib/connector/ConnectFromRegion.tsx +0 -25
  13. package/src/_lib/connector/ConnectToRegion.tsx +0 -23
  14. package/src/_lib/connector/ConnectorRegion.tsx +0 -24
  15. package/src/_lib/connector/ConnectorsProvider.tsx +0 -20
  16. package/src/_lib/connector/ConnectorsStore.ts +0 -122
  17. package/src/_lib/connector/ConnectorsStoreContext.ts +0 -5
  18. package/src/_lib/connector/helpers.ts +0 -5
  19. package/src/_lib/connector/index.ts +0 -9
  20. package/src/_lib/connector/mapConnectorToLine.ts +0 -83
  21. package/src/_lib/connector/types.ts +0 -56
  22. package/src/_lib/connector/useConnectorsStore.ts +0 -14
  23. package/src/_lib/connector/useRegionRects.ts +0 -142
  24. package/src/_lib/fixedListenQuery.ts +0 -101
  25. package/src/_lib/form/DocumentForm.tsx +0 -201
  26. package/src/_lib/form/constants.ts +0 -1
  27. package/src/_lib/form/helpers.ts +0 -32
  28. package/src/_lib/form/index.ts +0 -1
  29. package/src/_lib/randomKey.ts +0 -29
  30. package/src/_lib/useListeningQuery.ts +0 -62
  31. package/src/_lib/usePrevious.ts +0 -9
  32. package/src/assistConnectors/AssistConnectorsOverlay.tsx +0 -133
  33. package/src/assistConnectors/ConnectorPath.tsx +0 -63
  34. package/src/assistConnectors/draw/arrowPath.ts +0 -9
  35. package/src/assistConnectors/draw/connectorPath.ts +0 -142
  36. package/src/assistConnectors/index.ts +0 -1
  37. package/src/assistDocument/AssistDocumentContext.tsx +0 -51
  38. package/src/assistDocument/AssistDocumentContextProvider.tsx +0 -17
  39. package/src/assistDocument/AssistDocumentInput.tsx +0 -61
  40. package/src/assistDocument/AssistDocumentLayout.tsx +0 -12
  41. package/src/assistDocument/RequestRunInstructionProvider.tsx +0 -61
  42. package/src/assistDocument/components/AssistDocumentForm.tsx +0 -287
  43. package/src/assistDocument/components/AssistTypeContext.tsx +0 -7
  44. package/src/assistDocument/components/FieldRefPreview.tsx +0 -26
  45. package/src/assistDocument/components/InstructionsArrayField.tsx +0 -8
  46. package/src/assistDocument/components/InstructionsArrayInput.tsx +0 -27
  47. package/src/assistDocument/components/SelectedFieldContext.tsx +0 -10
  48. package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +0 -5
  49. package/src/assistDocument/components/helpers.ts +0 -21
  50. package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +0 -32
  51. package/src/assistDocument/components/instruction/FieldRefInput.tsx +0 -54
  52. package/src/assistDocument/components/instruction/InstructionInput.tsx +0 -89
  53. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +0 -46
  54. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +0 -206
  55. package/src/assistDocument/components/instruction/PromptInput.tsx +0 -59
  56. package/src/assistDocument/components/instruction/appearance/IconInput.tsx +0 -46
  57. package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +0 -37
  58. package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +0 -127
  59. package/src/assistDocument/hooks/useDocumentState.ts +0 -6
  60. package/src/assistDocument/hooks/useInstructionToaster.tsx +0 -75
  61. package/src/assistDocument/hooks/useStudioAssistDocument.ts +0 -99
  62. package/src/assistDocument/index.ts +0 -1
  63. package/src/assistFormComponents/AssistField.tsx +0 -63
  64. package/src/assistFormComponents/AssistFormBlock.tsx +0 -31
  65. package/src/assistFormComponents/AssistInlineFormBlock.tsx +0 -13
  66. package/src/assistFormComponents/AssistItem.tsx +0 -21
  67. package/src/assistFormComponents/validation/listItem.tsx +0 -63
  68. package/src/assistFormComponents/validation/validationList.tsx +0 -90
  69. package/src/assistInspector/AssistInspector.tsx +0 -419
  70. package/src/assistInspector/FieldAutocomplete.tsx +0 -146
  71. package/src/assistInspector/InstructionTaskHistoryButton.tsx +0 -262
  72. package/src/assistInspector/constants.ts +0 -1
  73. package/src/assistInspector/helpers.ts +0 -211
  74. package/src/assistInspector/index.ts +0 -27
  75. package/src/assistLayout/AiAssistanceConfigContext.tsx +0 -32
  76. package/src/assistLayout/AiAssistanceConfigProvider.tsx +0 -98
  77. package/src/assistLayout/AssistLayout.tsx +0 -39
  78. package/src/assistLayout/RunInstructionProvider.tsx +0 -278
  79. package/src/assistLayout/fieldRefCache.tsx +0 -34
  80. package/src/assistTypes.ts +0 -83
  81. package/src/components/AssistFeatureBadge.tsx +0 -9
  82. package/src/components/FadeInContent.tsx +0 -40
  83. package/src/components/HideReferenceChangedBannerInput.tsx +0 -25
  84. package/src/components/ImageContext.tsx +0 -85
  85. package/src/components/SafeValueInput.tsx +0 -74
  86. package/src/components/TimeAgo.tsx +0 -18
  87. package/src/constants.ts +0 -20
  88. package/src/fieldActions/PrivateIcon.tsx +0 -20
  89. package/src/fieldActions/assistFieldActions.tsx +0 -320
  90. package/src/fieldActions/customFieldActions.tsx +0 -333
  91. package/src/fieldActions/generateCaptionActions.tsx +0 -77
  92. package/src/fieldActions/generateImageActions.tsx +0 -58
  93. package/src/fieldActions/useUserInput.ts +0 -107
  94. package/src/globals.d.ts +0 -4
  95. package/src/helpers/assistSupported.ts +0 -49
  96. package/src/helpers/conditionalMembers.test.ts +0 -319
  97. package/src/helpers/conditionalMembers.ts +0 -134
  98. package/src/helpers/ids.test.ts +0 -28
  99. package/src/helpers/ids.ts +0 -23
  100. package/src/helpers/misc.ts +0 -25
  101. package/src/helpers/styleguide.ts +0 -24
  102. package/src/helpers/typeUtils.ts +0 -60
  103. package/src/helpers/useAssistSupported.ts +0 -8
  104. package/src/index.ts +0 -26
  105. package/src/onboarding/FirstAssistedPathProvider.tsx +0 -30
  106. package/src/onboarding/InspectorOnboarding.tsx +0 -47
  107. package/src/onboarding/onboardingStore.ts +0 -32
  108. package/src/plugin.tsx +0 -162
  109. package/src/presence/AiFieldPresence.tsx +0 -28
  110. package/src/presence/AssistAvatar.tsx +0 -96
  111. package/src/presence/AssistDocumentPresence.tsx +0 -50
  112. package/src/presence/useAssistPresence.ts +0 -64
  113. package/src/schemas/assistDocumentSchema.tsx +0 -497
  114. package/src/schemas/contextDocumentSchema.tsx +0 -57
  115. package/src/schemas/index.ts +0 -69
  116. package/src/schemas/serialize/SchemTypeTool.tsx +0 -103
  117. package/src/schemas/serialize/schemaUtils.ts +0 -38
  118. package/src/schemas/serialize/serializeSchema.test.ts +0 -819
  119. package/src/schemas/serialize/serializeSchema.ts +0 -224
  120. package/src/schemas/serializedSchemaTypeSchema.ts +0 -60
  121. package/src/schemas/typeDefExtensions.ts +0 -127
  122. package/src/translate/FieldTranslationProvider.tsx +0 -382
  123. package/src/translate/getLanguageParams.ts +0 -26
  124. package/src/translate/languageStore.ts +0 -18
  125. package/src/translate/paths.test.ts +0 -181
  126. package/src/translate/paths.ts +0 -183
  127. package/src/translate/translateActions.tsx +0 -205
  128. package/src/translate/types.ts +0 -197
  129. package/src/types.ts +0 -220
  130. package/src/useApiClient.ts +0 -338
  131. package/v2-incompatible.js +0 -11
package/dist/index.d.cts DELETED
@@ -1,791 +0,0 @@
1
- import {AgentActionPath} from '@sanity/client/stega'
2
- import {CurrentUser} from 'sanity'
3
- import {DocumentFieldActionDivider} from 'sanity'
4
- import {DocumentFieldActionGroup} from 'sanity'
5
- import {DocumentFieldActionItem} from 'sanity'
6
- import {JSX} from 'react/jsx-runtime'
7
- import {ObjectSchemaType} from 'sanity'
8
- import {Path} from 'sanity'
9
- import {Plugin as Plugin_2} from 'sanity'
10
- import {PortableTextBlock} from '@portabletext/types'
11
- import {PortableTextMarkDefinition} from '@portabletext/types'
12
- import {PortableTextSpan} from '@portabletext/types'
13
- import {SanityClient} from 'sanity'
14
- import type {SanityClient as SanityClient_2} from '@sanity/client'
15
- import {SanityDocumentLike} from 'sanity'
16
- import {SchemaType} from 'sanity'
17
-
18
- declare interface AgentActionConditionalPath {
19
- path: AgentActionPath
20
- readOnly: boolean
21
- hidden: boolean
22
- }
23
-
24
- export declare const assist: Plugin_2<void | AssistPluginConfig>
25
-
26
- export declare interface AssistConfig {
27
- /**
28
- * As of v3.0 Assist can write to date and datetime fields.
29
- *
30
- * If this function is omitted from config, the plugin will use the default timeZone and locale
31
- * in the browser:
32
- *
33
- * ```ts
34
- * const {timeZone, locale} = Intl.DateTimeFormat().resolvedOptions()
35
- * ```
36
- *
37
- * The function will be called any time an instruction runs.
38
- *
39
- * @see #LocaleSettings.locale
40
- * @see #LocaleSettings.timeZone
41
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
42
- * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
43
- */
44
- localeSettings?: (context: LocaleSettingsContext) => LocaleSettings
45
- /**
46
- * The max depth for document paths AI Assist will write to.
47
- *
48
- * Depth is based on field path segments:
49
- * - `title` has depth 1
50
- * - `array[_key="no"].title` has depth 3
51
- *
52
- * Be careful not to set this too high in studios with recursive document schemas, as it could have
53
- * negative impact on performance.
54
- *
55
- * Depth will be counted from the field the instruction is run from. For example, if an instruction
56
- * is attached to depth 6, the count starts from there (at 0, not at 6).
57
- *
58
- * Default: 4
59
- */
60
- maxPathDepth?: number
61
- /**
62
- * Influences how much the output of an instruction will vary.
63
- *
64
- * Min: 0 – re-running an instruction will often produce the same outcomes
65
- * Max: 1 – re-running an instruction can produce wildly different outcomes
66
- *
67
- * This parameter applies to _all_ instructions in the studio.
68
- *
69
- * Prior to v3.0, this defaulted to 0
70
- *
71
- * Default: 0.3
72
- */
73
- temperature?: number
74
- }
75
-
76
- export declare type AssistFieldActionGroup = Omit<
77
- DocumentFieldActionGroup,
78
- 'renderAsButton' | 'expanded' | 'children'
79
- > & {
80
- /**
81
- * `children` can include undefined entries in the action array. These will be filtered out.
82
- * If the group has no defined children, the group will also be filtered out.
83
- */
84
- children: (AssistFieldActionNode | undefined)[]
85
- }
86
-
87
- export declare type AssistFieldActionItem = Omit<
88
- DocumentFieldActionItem,
89
- 'renderAsButton' | 'selected' | 'onAction'
90
- > & {
91
- onAction: () => void | Promise<void>
92
- }
93
-
94
- export declare type AssistFieldActionNode =
95
- | AssistFieldActionItem
96
- | AssistFieldActionGroup
97
- | DocumentFieldActionDivider
98
-
99
- export declare interface AssistFieldActionProps {
100
- /**
101
- * `actionType` will be `document` for action invoked from the top right document action menu, and
102
- * `field` when invoked from a field action menu.
103
- */
104
- actionType: 'document' | 'field'
105
- /**
106
- * This is the id of the current document pane; it contains `drafts.`or `versions. prefix` ect depending on context.
107
- * Use this for `documentId` when calling any `client.agent.action`.
108
- *
109
- * It is generally recommended to call actions from the studio like this:
110
- * ```ts
111
- * await client.agent.action.generate({
112
- * targetDocument: {
113
- * operation: 'createIfNotExists',
114
- * _id: props.documentIdForAction,
115
- * _type: props.documentSchemaType.name,
116
- * initialValues: props.getDocumentValue()
117
- * },
118
- * //...
119
- * })
120
- * ```
121
- */
122
- documentIdForAction: string
123
- /**
124
- * Schema type of the current document.
125
- * @see documentIdForAction
126
- */
127
- documentSchemaType: ObjectSchemaType
128
- /**
129
- * Returns the current document value.
130
- *
131
- * Prefer passing this function to your hooks instead of passing the document value directly to avoid unnecessary re-renders.
132
- * @see documentIdForAction
133
- */
134
- getDocumentValue: () => SanityDocumentLike
135
- /**
136
- * Returns the current readOnly and hidden state of all conditional members in the current document form.
137
- *
138
- * Intended to be passed to agent actions `conditionalPaths.paths`.
139
- */
140
- getConditionalPaths: () => AgentActionConditionalPath[]
141
- /**
142
- * `schemaId` for the current workspace.
143
- *
144
- * Note: the workspace schema has to be deployed using `sanity schema deploy` or `sanity deploy`.
145
- *
146
- * Use this for `schemaId` when calling any `client.agent.action`.
147
- *
148
- * It is generally recommended to call actions from the studio like this:
149
- * ```ts
150
- * await client.agent.action.generate({
151
- * targetDocument: {
152
- * operation: 'createIfNotExists',
153
- * _id: props.documentIdForAction,
154
- * _type: props.documentSchemaType.name,
155
- * initialValues: props.getDocumentValue()
156
- * },
157
- * //...
158
- * })
159
- *
160
- * ```
161
- */
162
- schemaId: string
163
- /**
164
- * This is the schema type of the field the actions will be attached to (ie, schemaType for `path`)
165
- *
166
- * It can be used with agent actions using `target.path`, to scope the action to a specific field.
167
- *
168
- * It is generally recommended to call actions from the studio like this:
169
- * ```ts
170
- * await client.agent.action.generate({
171
- * targetDocument: {
172
- * operation: 'createIfNotExists',
173
- * _id: props.documentIdForAction,
174
- * _type: props.documentSchemaType.name,
175
- * initialValues: props.getDocumentValue()
176
- * },
177
- * target: {
178
- * path: props.path
179
- * },
180
- * })
181
- * ```
182
- */
183
- path: AgentActionPath
184
- /**
185
- * This is the schema type of the field the actions will be attached to (ie, schemaType for `path`).
186
- *
187
- * Typically useful to dynamically return different actions based on the schema type of the field.
188
- *
189
- * ```ts
190
- * if(isObjectSchemaType(schemaType)) {
191
- * return [
192
- * defineAssistFieldAction({
193
- * title: 'Fill the object fields',
194
- * icon: RobotIcon,
195
- * onAction: () => {
196
- * //...
197
- * }
198
- * })
199
- * ]
200
- * }
201
- * return useMemo(() => {
202
- *
203
- *
204
- * }, [])
205
- *
206
- * ```
207
- */
208
- schemaType: SchemaType
209
- /**
210
- * Schema type of the parent field or array item holding this field.
211
- *
212
- * This can be undefined if the action was unable to resolve the parent type is excluded from AI Assist.
213
- *
214
- * @see schemaType
215
- * @see documentSchemaType
216
- */
217
- parentSchemaType?: SchemaType
218
- }
219
-
220
- export declare interface AssistOptions {
221
- aiAssist?: {
222
- /** Set to true to disable assistance for this field or type */
223
- exclude?: boolean
224
- /**
225
- * Set to true to add translation field-action to the field.
226
- * Only has an effect in document types configured for document or field level translations.
227
- */
228
- translateAction?: boolean
229
- }
230
- }
231
-
232
- declare interface AssistPluginConfig {
233
- translate?: TranslationConfig
234
- /**
235
- * Config that affects all instructions
236
- */
237
- assist?: AssistConfig
238
- fieldActions?: {
239
- title?: string
240
- /**
241
- * The returned array can include `undefined` entries in the action array. These will be filtered out.
242
- */
243
- useFieldActions?: (props: AssistFieldActionProps) => (AssistFieldActionNode | undefined)[]
244
- }
245
- /**
246
- * @internal
247
- */
248
- __customApiClient?: (defaultClient: SanityClient_2) => SanityClient_2
249
- /**
250
- * @internal
251
- */
252
- __presets?: Record<string, AssistPreset>
253
- }
254
-
255
- declare interface AssistPreset {
256
- fields?: PresetField[]
257
- }
258
-
259
- declare interface ContextBlock {
260
- _type: typeof instructionContextTypeName
261
- reference?: {
262
- _type: 'reference'
263
- _ref?: string
264
- }
265
- }
266
-
267
- export declare const contextDocumentTypeName: 'assist.instruction.context'
268
-
269
- /**
270
- *
271
- */
272
- export declare interface CustomInput {
273
- /**
274
- * Id for the input
275
- */
276
- id: string
277
- /**
278
- * Title of the input field
279
- */
280
- title: string
281
- /**
282
- * Additional info that will be displayed over the input
283
- */
284
- description?: string
285
- }
286
-
287
- export declare type CustomInputResult = {
288
- /**
289
- * Identifies which custom input the `result`belongs to
290
- */
291
- input: CustomInput
292
- /**
293
- * The text provided by the user in the input
294
- */
295
- result: string
296
- }
297
-
298
- /**
299
- * Default implementation for plugin config `translate.field.translationOutputs`
300
- *
301
- * @see FieldTranslationConfig#translationOutputs
302
- */
303
- export declare const defaultLanguageOutputs: TranslationOutputsFunction
304
-
305
- export declare function defineAssistFieldAction(
306
- action: Omit<AssistFieldActionItem, 'type'>,
307
- ): AssistFieldActionItem
308
-
309
- export declare function defineAssistFieldActionGroup(
310
- group: Omit<AssistFieldActionGroup, 'type'>,
311
- ): AssistFieldActionGroup
312
-
313
- export declare function defineFieldActionDivider(): DocumentFieldActionDivider
314
-
315
- export declare interface DocumentMember {
316
- schemaType: SchemaType
317
- path: Path
318
- name: string
319
- value: unknown
320
- }
321
-
322
- export declare interface DocumentTranslationConfig {
323
- /**
324
- * Path to language field in documents. Can be a hidden field.
325
- * For instance: 'config.language'
326
- *
327
- * For projects that use the `@sanity/document-internationalization` plugin,
328
- * this should be the same as `languageField` config for that plugin.
329
- *
330
- * Default: 'language'
331
- */
332
- languageField: string
333
- /**
334
- * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
335
- *
336
- * If defined, this property will add a translate instruction to these document types.
337
- * If undefined, the instruction will be added to all documents with aiAssistance enabled and a field matching `documentLanguageField` config.
338
- *
339
- * Documents with translation support will get a "Translate document>" instruction added.
340
- **/
341
- documentTypes?: string[]
342
- }
343
-
344
- declare interface FieldRef extends PortableTextMarkDefinition {
345
- _type: typeof fieldReferenceTypeName
346
- path?: string
347
- }
348
-
349
- declare const fieldReferenceTypeName: 'sanity.assist.instruction.fieldRef'
350
-
351
- export declare interface FieldTranslationConfig {
352
- /**
353
- * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
354
- *
355
- * If defined, matching document will get a "Translate fields" instruction added.
356
- **/
357
- documentTypes?: string[]
358
- /**
359
- *
360
- * Used for display strings in the Studio, and to determine languages for field level translations
361
- *
362
- * If the studio is using the sanity-plugin-internationalized-array plugin, this
363
- * should be set to the same configuration.
364
- */
365
- languages: Language[] | LanguageCallback
366
- /**
367
- * API version for client passed to LanguageCallback for languages
368
- * https://www.sanity.io/docs/api-versioning
369
- * @defaultValue '2022-11-27'
370
- */
371
- apiVersion?: string
372
- /**
373
- * Specify fields that should be available in the languages callback:
374
- * ```tsx
375
- * {
376
- * select: {
377
- * markets: 'markets'
378
- * },
379
- * languages: (client, {markets}) =>
380
- * client.fetch('*[_type == "language" && market in $markets]{id,title}', {markets})
381
- * }
382
- * ```
383
- *
384
- * If the studio is using the sanity-plugin-internationalized-array plugin, this
385
- * should be set to the same configuration.
386
- */
387
- selectLanguageParams?: Record<string, string>
388
- /**
389
- * `translationOutputs` is used when the "Translate fields" instruction is started by a Studio user.
390
- *
391
- * It determines the relationships between document paths: Given a document path and a language, into which
392
- * sibling paths should translations be output.
393
- *
394
- * `translationOutputs` is invoked once per path in the document (limited to a depth of 6), with the following:
395
- *
396
- * * `documentMember` - the field or array item for a given path; contains the path and its schemaType,
397
- * * `enclosingType` - the schema type of parent holding the member
398
- * * `translateFromLanguageId` - the languageId for the language the user want to translate from
399
- * * `translateToLanguageIds` - all languageIds the user can translate to
400
- *
401
- * The function should return a `TranslationOutput[]` array that contains all the paths where translations from
402
- * documentMember language (translateFromLanguageId) should be output.
403
- *
404
- * The function should return `undefined` for all documentMembers that should not be directly translated,
405
- * or are nested fields under a translated path.
406
- *
407
- * ## Default function
408
- *
409
- * The default function for `translationOutputs` is configured to be automatically compatible with sanity-plugin-internationalized-array
410
- * and object types prefixed with "locale".
411
- *
412
- * See <link to source for defaultTranslationOutputs> implementation details.
413
- *
414
- * ## Example
415
- * A document has the following document members:
416
- * * `{path: 'localeObject.en', schemaType: ObjectSchemaType}`
417
- * * `{path: 'localeObject.en.title', schemaType: StringSchemaType}`
418
- * * `{path: 'localeObject.de', schemaType: ObjectSchemaType}`,
419
- * * `{path: 'localeObject.de.title', schemaType: StringSchemaType}`
420
- *
421
- * `translationOutputs` for invoked with `translateFromLanguageId` `en`,
422
- * should only return [{id: 'de', outputPath: 'localeObject.de'}] for the `'localeObject.en'` path,
423
- * and undefined for all the other members.
424
- *
425
- * ### Example implementation
426
- * ```ts
427
- * function translationOutputs(member, enclosingType, translateFromLanguageId, translateToLanguageIds)
428
- * if (enclosingType.jsonType === 'object' && enclosingType.name.startsWith('locale') && translateFromLanguageId === member.name) {
429
- * return translateToLanguageIds.map((translateToId) => ({
430
- * id: translateToId,
431
- * outputPath: [...member.path.slice(0, -1), translateToId],
432
- * }))
433
- * }
434
- * return undefined
435
- * }
436
- * ```
437
- *
438
- * @see #maxPathDepth
439
- **/
440
- translationOutputs?: TranslationOutputsFunction
441
- /**
442
- * The max depth for document paths AI Assist will translate.
443
- *
444
- * Depth is based on field path segments:
445
- * - `title` has depth 1
446
- * - `array[_key="no"].title` has depth 3
447
- *
448
- * Be careful not to set this too high in studios with recursive document schemas, as it could have
449
- * negative impact on performance.
450
- *
451
- * Default: 6
452
- */
453
- maxPathDepth?: number
454
- }
455
-
456
- export declare type GetUserInput = (args: {
457
- /**
458
- * Dialog title
459
- */
460
- title: string
461
- /**
462
- * One titled input per array item
463
- */
464
- inputs: CustomInput[]
465
- }) => Promise<CustomInputResult[] | undefined>
466
-
467
- declare type InlinePromptBlock = PortableTextSpan | FieldRef | UserInputBlock | ContextBlock
468
-
469
- declare const instructionContextTypeName: 'sanity.assist.instruction.context'
470
-
471
- /**
472
- * Returns true if the `schemaType` or any of its parent types (`schemaType.type`)` has `name` equal
473
- * to `typeName`.
474
- *
475
- * Useful for checking if `schemaType` is a type alias of `ìmage`, `code` or similar.
476
- */
477
- export declare function isType(schemaType: SchemaType, typeName: string): boolean
478
-
479
- export declare interface Language {
480
- id: string
481
- title?: string
482
- }
483
-
484
- export declare type LanguageCallback = (
485
- client: SanityClient,
486
- selectedLanguageParams: Record<string, unknown>,
487
- ) => Promise<Language[]>
488
-
489
- export declare interface LocaleSettings {
490
- /**
491
- * A valid Unicode BCP 47 locale identifier used to interpret and format
492
- * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
493
- *
494
- * This affects how phrases like "next Friday" or "in two weeks" are parsed,
495
- * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
496
- *
497
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
498
- */
499
- locale: string
500
- /**
501
- * A valid IANA time zone identifier used to resolve relative and absolute
502
- * date expressions to a specific point in time. Examples include
503
- * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
504
- *
505
- * This ensures phrases like "tomorrow at 9am" are interpreted correctly
506
- * based on the user's local time.
507
- *
508
- * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
509
- */
510
- timeZone: string
511
- }
512
-
513
- export declare interface LocaleSettingsContext {
514
- user: CurrentUser
515
- defaultSettings: LocaleSettings
516
- }
517
-
518
- declare interface OutputFieldItem {
519
- _type: typeof outputFieldTypeName
520
- _key: string
521
- relativePath?: string
522
- }
523
-
524
- declare const outputFieldTypeName: 'sanity.assist.output.field'
525
-
526
- declare interface OutputTypeItem {
527
- _type: typeof outputTypeTypeName
528
- _key: string
529
- type?: string
530
- relativePath?: string
531
- }
532
-
533
- declare const outputTypeTypeName: 'sanity.assist.output.type'
534
-
535
- declare interface PresetField {
536
- path?: string
537
- instructions?: PresetInstruction[]
538
- }
539
-
540
- declare interface PresetInstruction {
541
- _key: string
542
- prompt?: PromptTextBlock[]
543
- title?: string
544
- /**
545
- * String key from `@sanity/icons` IconMap
546
- */
547
- icon?: string
548
- /**
549
- * Type/field filter
550
- */
551
- output?: (OutputFieldItem | OutputTypeItem)[]
552
- }
553
-
554
- declare type PromptTextBlock = Omit<
555
- PortableTextBlock<never, InlinePromptBlock, 'normal', never>,
556
- '_type'
557
- > & {
558
- _type: 'block'
559
- }
560
-
561
- export declare function SchemaTypeTool(): JSX.Element
562
-
563
- export declare type TranslateStyleguide =
564
- | string
565
- | ((context: TranslateStyleguideContext) => Promise<string>)
566
-
567
- export declare interface TranslateStyleguideContext {
568
- documentId: string
569
- schemaType: ObjectSchemaType
570
- client: SanityClient
571
- /**
572
- * Only provided for field translations
573
- */
574
- translatePath?: Path
575
- }
576
-
577
- export declare interface TranslationConfig {
578
- /**
579
- * Config for document types with fields in multiple languages in the same document.
580
- */
581
- field?: FieldTranslationConfig
582
- /**
583
- * Config for document types with a single language field that determines the language for the whole document.
584
- */
585
- document?: DocumentTranslationConfig
586
- /**
587
- * A "style guide" that can be used to provide guidance on how to translate content.
588
- * Will be passed to the LLM - ergo this is only a guide and the model _may_ not
589
- * always follow it to the letter.
590
- *
591
- * When providing a function, consider caching the results of any async operation; it will invoked every time translate runs
592
- */
593
- styleguide?: TranslateStyleguide
594
- }
595
-
596
- export declare interface TranslationOutput {
597
- /** Language id */
598
- id: string
599
- outputPath: Path
600
- }
601
-
602
- export declare type TranslationOutputsFunction = (
603
- documentMember: DocumentMember,
604
- enclosingType: SchemaType,
605
- translateFromLanguageId: string,
606
- translateToLanguageIds: string[],
607
- ) => TranslationOutput[] | undefined
608
-
609
- declare interface UserInputBlock {
610
- _type: typeof userInputTypeName
611
- _key: string
612
- message?: string
613
- description?: string
614
- }
615
-
616
- declare const userInputTypeName: 'sanity.assist.instruction.userInput'
617
-
618
- /**
619
- * `useUserInput` returns a function that can be used to await user input.
620
- *
621
- * Useful for custom `fieldActions` to get user input for populating Agent Action requests,.
622
- *
623
- * ```ts
624
- * fieldActions: {
625
- * useFieldActions: (props) => {
626
- * const {
627
- * documentSchemaType,
628
- * schemaId,
629
- * getDocumentValue,
630
- * getConditionalPaths,
631
- * documentIdForAction,
632
- * } = props
633
- * const client = useClient({apiVersion: 'vX'})
634
- * const getUserInput = useUserInput()
635
- * return useMemo(() => {
636
- * return [
637
- * defineAssistFieldAction({
638
- * title: 'Log user input',
639
- * icon: UserIcon,
640
- * onAction: async () => {
641
- * const input = await getUserInput({
642
- * title: 'Topic',
643
- * inputs: [{id: 'about', title: 'What should the article be about?'}],
644
- * })
645
- * if (!input) return // user canceled input
646
- * await client.agent.action.generate({
647
- * schemaId,
648
- * targetDocument: {
649
- * operation: 'createIfNotExists',
650
- * _id: documentIdForAction,
651
- * _type: documentSchemaType.name,
652
- * initialValues: getDocumentValue(),
653
- * },
654
- * instruction: `
655
- * Create a document about the following topic:
656
- * $about
657
- * ---
658
- * `,
659
- * instructionParams: {about: input[0].result},
660
- * conditionalPaths: {paths: getConditionalPaths()},
661
- * })
662
- * },
663
- * }),
664
- * ]
665
- * }, [
666
- * client,
667
- * documentSchemaType,
668
- * schemaId,
669
- * getDocumentValue,
670
- * getConditionalPaths,
671
- * documentIdForAction,
672
- * getUserInput,
673
- * ])
674
- * },
675
- * }
676
- * ```
677
- */
678
- export declare function useUserInput(): GetUserInput
679
-
680
- export {}
681
-
682
- declare module 'sanity' {
683
- interface ArrayOptions extends AssistOptions {}
684
- interface BlockOptions extends AssistOptions {}
685
- interface BooleanOptions extends AssistOptions {}
686
- interface CrossDatasetReferenceOptions extends AssistOptions {}
687
- interface DateOptions extends AssistOptions {}
688
- interface DatetimeOptions extends AssistOptions {}
689
- interface DocumentOptions extends AssistOptions {}
690
- interface FileOptions extends AssistOptions {}
691
- interface GeopointOptions extends AssistOptions {}
692
- interface ImageOptions {
693
- aiAssist?: AssistOptions['aiAssist'] & {
694
- /**
695
- * When set, an image will be created whenever the `imageInstructionField` is written to by
696
- * an AI Assist instruction.
697
- *
698
- * The value output by AI Assist will be use as an image prompt for an generative image AI.
699
- *
700
- * This means that instructions directly for the field or instructions that visit the field when running,
701
- * will result in the image being changed.
702
- *
703
- * `imageInstructionField` must be a child-path relative to the image field, ie:
704
- * * field
705
- * * path.to.field
706
- *
707
- * ### Example
708
- * ```ts
709
- * defineType({
710
- * type: 'image',
711
- * name: 'articleImage',
712
- * fields: [
713
- * defineField({
714
- * type: 'text',
715
- * name: 'imagePrompt',
716
- * title: 'Image prompt',
717
- * rows: 2,
718
- * }),
719
- * ],
720
- * options: {
721
- * aiAssist: {
722
- * imageInstructionField: 'imagePrompt',
723
- * }
724
- * },
725
- * })
726
- * ```
727
- */
728
- imageInstructionField?: string
729
- /**
730
- * When set, an image description will be automatically created for the image.
731
- *
732
- * `imageDescriptionField` must be a child-path relative to the image field, ie:
733
- * * field
734
- * * path.to.field
735
- *
736
- * Whenever the image asset for the field is changed in the Studio,
737
- * an image description is generated and set into the `imageDescriptionField`.
738
- *
739
- * ### Example
740
- * ```ts
741
- * defineType({
742
- * type: 'image',
743
- * name: 'articleImage',
744
- * fields: [
745
- * defineField({
746
- * type: 'string',
747
- * name: 'altText',
748
- * title: 'Alt text',
749
- * }),
750
- * ],
751
- * options: {
752
- * aiAssist: {
753
- * imageDescriptionField: 'altText',
754
- * }
755
- * },
756
- * })
757
- * ```
758
- */
759
- imageDescriptionField?:
760
- | string
761
- | {
762
- path: string
763
- /**
764
- * When updateOnImageChange is true (or undefined), whenever the
765
- * image asset changes, imageDescriptionField will be regenerated.
766
- *
767
- * default: true
768
- * */
769
- updateOnImageChange?: boolean
770
- }
771
- }
772
- }
773
- interface NumberOptions extends AssistOptions {}
774
- interface ObjectOptions extends AssistOptions {}
775
- interface ReferenceBaseOptions {
776
- aiAssist?: {
777
- /** Set to true to disable assistance for this field or type */
778
- exclude?: boolean
779
- /**
780
- * When set, the reference field will allow instructions to be added to it.
781
- * Should be the name of the embeddings-index where assist will look for contextually relevant documents
782
- * */
783
- embeddingsIndex?: string
784
- }
785
- }
786
- interface SlugOptions extends AssistOptions {}
787
- interface StringOptions extends AssistOptions {}
788
- interface TextOptions extends AssistOptions {}
789
- interface UrlOptions extends AssistOptions {}
790
- interface EmailOptions extends AssistOptions {}
791
- }