@sanity/assist 5.0.4 → 6.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.
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 +3205 -2670
  6. package/dist/index.js.map +1 -1
  7. package/package.json +41 -81
  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.ts CHANGED
@@ -1,29 +1,10 @@
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 {
1
+ import * as sanity from "sanity";
2
+ import { CurrentUser, DocumentFieldActionDivider, DocumentFieldActionGroup, DocumentFieldActionItem, ObjectSchemaType, Path, SanityClient, SanityDocumentLike, SchemaType } from "sanity";
3
+ import { SanityClient as SanityClient$1 } from "@sanity/client";
4
+ import { AgentActionPath } from "@sanity/client/stega";
5
+ import { PortableTextBlock, PortableTextMarkDefinition, PortableTextSpan } from "@portabletext/types";
6
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
7
+ interface AssistConfig {
27
8
  /**
28
9
  * As of v3.0 Assist can write to date and datetime fields.
29
10
  *
@@ -41,7 +22,7 @@ export declare interface AssistConfig {
41
22
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
42
23
  * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
43
24
  */
44
- localeSettings?: (context: LocaleSettingsContext) => LocaleSettings
25
+ localeSettings?: (context: LocaleSettingsContext) => LocaleSettings;
45
26
  /**
46
27
  * The max depth for document paths AI Assist will write to.
47
28
  *
@@ -57,7 +38,7 @@ export declare interface AssistConfig {
57
38
  *
58
39
  * Default: 4
59
40
  */
60
- maxPathDepth?: number
41
+ maxPathDepth?: number;
61
42
  /**
62
43
  * Influences how much the output of an instruction will vary.
63
44
  *
@@ -70,38 +51,46 @@ export declare interface AssistConfig {
70
51
  *
71
52
  * Default: 0.3
72
53
  */
73
- temperature?: number
54
+ temperature?: number;
55
+ }
56
+ interface LocaleSettingsContext {
57
+ user: CurrentUser;
58
+ defaultSettings: LocaleSettings;
74
59
  }
75
-
76
- export declare type AssistFieldActionGroup = Omit<
77
- DocumentFieldActionGroup,
78
- 'renderAsButton' | 'expanded' | 'children'
79
- > & {
60
+ interface LocaleSettings {
80
61
  /**
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.
62
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
63
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
64
+ *
65
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
66
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
67
+ *
68
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
69
+ */
70
+ locale: string;
71
+ /**
72
+ * A valid IANA time zone identifier used to resolve relative and absolute
73
+ * date expressions to a specific point in time. Examples include
74
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
75
+ *
76
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
77
+ * based on the user's local time.
78
+ *
79
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
83
80
  */
84
- children: (AssistFieldActionNode | undefined)[]
81
+ timeZone: string;
85
82
  }
86
-
87
- export declare type AssistFieldActionItem = Omit<
88
- DocumentFieldActionItem,
89
- 'renderAsButton' | 'selected' | 'onAction'
90
- > & {
91
- onAction: () => void | Promise<void>
83
+ interface AgentActionConditionalPath {
84
+ path: AgentActionPath;
85
+ readOnly: boolean;
86
+ hidden: boolean;
92
87
  }
93
-
94
- export declare type AssistFieldActionNode =
95
- | AssistFieldActionItem
96
- | AssistFieldActionGroup
97
- | DocumentFieldActionDivider
98
-
99
- export declare interface AssistFieldActionProps {
88
+ interface AssistFieldActionProps {
100
89
  /**
101
90
  * `actionType` will be `document` for action invoked from the top right document action menu, and
102
91
  * `field` when invoked from a field action menu.
103
92
  */
104
- actionType: 'document' | 'field'
93
+ actionType: 'document' | 'field';
105
94
  /**
106
95
  * This is the id of the current document pane; it contains `drafts.`or `versions. prefix` ect depending on context.
107
96
  * Use this for `documentId` when calling any `client.agent.action`.
@@ -119,25 +108,25 @@ export declare interface AssistFieldActionProps {
119
108
  * })
120
109
  * ```
121
110
  */
122
- documentIdForAction: string
111
+ documentIdForAction: string;
123
112
  /**
124
113
  * Schema type of the current document.
125
114
  * @see documentIdForAction
126
115
  */
127
- documentSchemaType: ObjectSchemaType
116
+ documentSchemaType: ObjectSchemaType;
128
117
  /**
129
118
  * Returns the current document value.
130
119
  *
131
120
  * Prefer passing this function to your hooks instead of passing the document value directly to avoid unnecessary re-renders.
132
121
  * @see documentIdForAction
133
122
  */
134
- getDocumentValue: () => SanityDocumentLike
123
+ getDocumentValue: () => SanityDocumentLike;
135
124
  /**
136
125
  * Returns the current readOnly and hidden state of all conditional members in the current document form.
137
126
  *
138
127
  * Intended to be passed to agent actions `conditionalPaths.paths`.
139
128
  */
140
- getConditionalPaths: () => AgentActionConditionalPath[]
129
+ getConditionalPaths: () => AgentActionConditionalPath[];
141
130
  /**
142
131
  * `schemaId` for the current workspace.
143
132
  *
@@ -159,7 +148,7 @@ export declare interface AssistFieldActionProps {
159
148
  *
160
149
  * ```
161
150
  */
162
- schemaId: string
151
+ schemaId: string;
163
152
  /**
164
153
  * This is the schema type of the field the actions will be attached to (ie, schemaType for `path`)
165
154
  *
@@ -180,7 +169,7 @@ export declare interface AssistFieldActionProps {
180
169
  * })
181
170
  * ```
182
171
  */
183
- path: AgentActionPath
172
+ path: AgentActionPath;
184
173
  /**
185
174
  * This is the schema type of the field the actions will be attached to (ie, schemaType for `path`).
186
175
  *
@@ -205,7 +194,7 @@ export declare interface AssistFieldActionProps {
205
194
  *
206
195
  * ```
207
196
  */
208
- schemaType: SchemaType
197
+ schemaType: SchemaType;
209
198
  /**
210
199
  * Schema type of the parent field or array item holding this field.
211
200
  *
@@ -214,147 +203,46 @@ export declare interface AssistFieldActionProps {
214
203
  * @see schemaType
215
204
  * @see documentSchemaType
216
205
  */
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
- }
206
+ parentSchemaType?: SchemaType;
265
207
  }
266
-
267
- export declare const contextDocumentTypeName: 'assist.instruction.context'
268
-
269
- /**
270
- *
271
- */
272
- export declare interface CustomInput {
208
+ type AssistFieldActionNode = AssistFieldActionItem | AssistFieldActionGroup | DocumentFieldActionDivider;
209
+ type AssistFieldActionItem = Omit<DocumentFieldActionItem, 'renderAsButton' | 'selected' | 'onAction'> & {
210
+ onAction: () => void | Promise<void>;
211
+ };
212
+ type AssistFieldActionGroup = Omit<DocumentFieldActionGroup, 'renderAsButton' | 'expanded' | 'children'> & {
273
213
  /**
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
214
+ * `children` can include undefined entries in the action array. These will be filtered out.
215
+ * If the group has no defined children, the group will also be filtered out.
294
216
  */
295
- result: string
217
+ children: (AssistFieldActionNode | undefined)[];
218
+ };
219
+ declare function defineAssistFieldAction(action: Omit<AssistFieldActionItem, 'type'>): AssistFieldActionItem;
220
+ declare function defineFieldActionDivider(): DocumentFieldActionDivider;
221
+ declare function defineAssistFieldActionGroup(group: Omit<AssistFieldActionGroup, 'type'>): AssistFieldActionGroup;
222
+ interface Language {
223
+ id: string;
224
+ title?: string;
296
225
  }
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
226
+ interface DocumentMember {
227
+ schemaType: SchemaType;
228
+ path: Path;
229
+ name: string;
230
+ value: unknown;
320
231
  }
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
232
+ interface TranslationOutput {
233
+ /** Language id */
234
+ id: string;
235
+ outputPath: Path;
347
236
  }
348
-
349
- declare const fieldReferenceTypeName: 'sanity.assist.instruction.fieldRef'
350
-
351
- export declare interface FieldTranslationConfig {
237
+ type TranslationOutputsFunction = (documentMember: DocumentMember, enclosingType: SchemaType, translateFromLanguageId: string, translateToLanguageIds: string[]) => TranslationOutput[] | undefined;
238
+ type LanguageCallback = (client: SanityClient, selectedLanguageParams: Record<string, unknown>) => Promise<Language[]>;
239
+ interface FieldTranslationConfig {
352
240
  /**
353
241
  * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
354
242
  *
355
243
  * If defined, matching document will get a "Translate fields" instruction added.
356
244
  **/
357
- documentTypes?: string[]
245
+ documentTypes?: string[];
358
246
  /**
359
247
  *
360
248
  * Used for display strings in the Studio, and to determine languages for field level translations
@@ -362,13 +250,13 @@ export declare interface FieldTranslationConfig {
362
250
  * If the studio is using the sanity-plugin-internationalized-array plugin, this
363
251
  * should be set to the same configuration.
364
252
  */
365
- languages: Language[] | LanguageCallback
253
+ languages: Language[] | LanguageCallback;
366
254
  /**
367
255
  * API version for client passed to LanguageCallback for languages
368
256
  * https://www.sanity.io/docs/api-versioning
369
257
  * @defaultValue '2022-11-27'
370
258
  */
371
- apiVersion?: string
259
+ apiVersion?: string;
372
260
  /**
373
261
  * Specify fields that should be available in the languages callback:
374
262
  * ```tsx
@@ -384,7 +272,7 @@ export declare interface FieldTranslationConfig {
384
272
  * If the studio is using the sanity-plugin-internationalized-array plugin, this
385
273
  * should be set to the same configuration.
386
274
  */
387
- selectLanguageParams?: Record<string, string>
275
+ selectLanguageParams?: Record<string, string>;
388
276
  /**
389
277
  * `translationOutputs` is used when the "Translate fields" instruction is started by a Studio user.
390
278
  *
@@ -437,7 +325,7 @@ export declare interface FieldTranslationConfig {
437
325
  *
438
326
  * @see #maxPathDepth
439
327
  **/
440
- translationOutputs?: TranslationOutputsFunction
328
+ translationOutputs?: TranslationOutputsFunction;
441
329
  /**
442
330
  * The max depth for document paths AI Assist will translate.
443
331
  *
@@ -450,139 +338,48 @@ export declare interface FieldTranslationConfig {
450
338
  *
451
339
  * Default: 6
452
340
  */
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
341
+ maxPathDepth?: number;
482
342
  }
483
-
484
- export declare type LanguageCallback = (
485
- client: SanityClient,
486
- selectedLanguageParams: Record<string, unknown>,
487
- ) => Promise<Language[]>
488
-
489
- export declare interface LocaleSettings {
343
+ interface DocumentTranslationConfig {
490
344
  /**
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".
345
+ * Path to language field in documents. Can be a hidden field.
346
+ * For instance: 'config.language'
493
347
  *
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).
348
+ * For projects that use the `@sanity/document-internationalization` plugin,
349
+ * this should be the same as `languageField` config for that plugin.
496
350
  *
497
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
351
+ * Default: 'language'
498
352
  */
499
- locale: string
353
+ languageField: string;
500
354
  /**
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".
355
+ * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
504
356
  *
505
- * This ensures phrases like "tomorrow at 9am" are interpreted correctly
506
- * based on the user's local time.
357
+ * If defined, this property will add a translate instruction to these document types.
358
+ * If undefined, the instruction will be added to all documents with aiAssistance enabled and a field matching `documentLanguageField` config.
507
359
  *
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'
360
+ * Documents with translation support will get a "Translate document>" instruction added.
361
+ **/
362
+ documentTypes?: string[];
559
363
  }
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
364
+ interface TranslateStyleguideContext {
365
+ documentId: string;
366
+ schemaType: ObjectSchemaType;
367
+ client: SanityClient;
571
368
  /**
572
369
  * Only provided for field translations
573
370
  */
574
- translatePath?: Path
371
+ translatePath?: Path;
575
372
  }
576
-
577
- export declare interface TranslationConfig {
373
+ type TranslateStyleguide = string | ((context: TranslateStyleguideContext) => Promise<string>);
374
+ interface TranslationConfig {
578
375
  /**
579
376
  * Config for document types with fields in multiple languages in the same document.
580
377
  */
581
- field?: FieldTranslationConfig
378
+ field?: FieldTranslationConfig;
582
379
  /**
583
380
  * Config for document types with a single language field that determines the language for the whole document.
584
381
  */
585
- document?: DocumentTranslationConfig
382
+ document?: DocumentTranslationConfig;
586
383
  /**
587
384
  * A "style guide" that can be used to provide guidance on how to translate content.
588
385
  * Will be passed to the LLM - ergo this is only a guide and the model _may_ not
@@ -590,95 +387,100 @@ export declare interface TranslationConfig {
590
387
  *
591
388
  * When providing a function, consider caching the results of any async operation; it will invoked every time translate runs
592
389
  */
593
- styleguide?: TranslateStyleguide
390
+ styleguide?: TranslateStyleguide;
594
391
  }
595
-
596
- export declare interface TranslationOutput {
597
- /** Language id */
598
- id: string
599
- outputPath: Path
392
+ declare const userInputTypeName: "sanity.assist.instruction.userInput";
393
+ declare const instructionContextTypeName: "sanity.assist.instruction.context";
394
+ declare const fieldReferenceTypeName: "sanity.assist.instruction.fieldRef";
395
+ declare const contextDocumentTypeName: "assist.instruction.context";
396
+ declare const outputFieldTypeName: "sanity.assist.output.field";
397
+ declare const outputTypeTypeName: "sanity.assist.output.type";
398
+ interface PresetInstruction {
399
+ _key: string;
400
+ prompt?: PromptTextBlock[];
401
+ title?: string;
402
+ /**
403
+ * String key from `@sanity/icons` IconMap
404
+ */
405
+ icon?: string;
406
+ /**
407
+ * Type/field filter
408
+ */
409
+ output?: (OutputFieldItem | OutputTypeItem)[];
600
410
  }
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
411
+ interface PresetField {
412
+ path?: string;
413
+ instructions?: PresetInstruction[];
414
+ }
415
+ interface AssistPreset {
416
+ fields?: PresetField[];
417
+ }
418
+ interface FieldRef extends PortableTextMarkDefinition {
419
+ _type: typeof fieldReferenceTypeName;
420
+ path?: string;
421
+ }
422
+ interface ContextBlock {
423
+ _type: typeof instructionContextTypeName;
424
+ reference?: {
425
+ _type: 'reference';
426
+ _ref?: string;
427
+ };
428
+ }
429
+ interface UserInputBlock {
430
+ _type: typeof userInputTypeName;
431
+ _key: string;
432
+ message?: string;
433
+ description?: string;
434
+ }
435
+ type InlinePromptBlock = PortableTextSpan | FieldRef | UserInputBlock | ContextBlock;
436
+ type PromptTextBlock = Omit<PortableTextBlock<never, InlinePromptBlock, 'normal', never>, '_type'> & {
437
+ _type: 'block';
438
+ };
439
+ interface OutputFieldItem {
440
+ _type: typeof outputFieldTypeName;
441
+ _key: string;
442
+ relativePath?: string;
443
+ }
444
+ interface OutputTypeItem {
445
+ _type: typeof outputTypeTypeName;
446
+ _key: string;
447
+ type?: string;
448
+ relativePath?: string;
449
+ }
450
+ interface AssistPluginConfig {
451
+ translate?: TranslationConfig;
452
+ /**
453
+ * Config that affects all instructions
454
+ */
455
+ assist?: AssistConfig;
456
+ fieldActions?: {
457
+ title?: string;
458
+ /**
459
+ * The returned array can include `undefined` entries in the action array. These will be filtered out.
460
+ */
461
+ useFieldActions?: (props: AssistFieldActionProps) => (AssistFieldActionNode | undefined)[];
462
+ };
463
+ /**
464
+ * @internal
465
+ */
466
+ __customApiClient?: (defaultClient: SanityClient$1) => SanityClient$1;
467
+ /**
468
+ * @internal
469
+ */
470
+ __presets?: Record<string, AssistPreset>;
471
+ }
472
+ declare const assist: sanity.Plugin<void | AssistPluginConfig>;
473
+ declare function SchemaTypeTool(): react_jsx_runtime0.JSX.Element;
474
+ interface AssistOptions {
475
+ aiAssist?: {
476
+ /** Set to true to disable assistance for this field or type */exclude?: boolean;
477
+ /**
478
+ * Set to true to add translation field-action to the field.
479
+ * Only has an effect in document types configured for document or field level translations.
480
+ */
481
+ translateAction?: boolean;
482
+ };
614
483
  }
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
484
  declare module 'sanity' {
683
485
  interface ArrayOptions extends AssistOptions {}
684
486
  interface BlockOptions extends AssistOptions {}
@@ -725,7 +527,7 @@ declare module 'sanity' {
725
527
  * })
726
528
  * ```
727
529
  */
728
- imageInstructionField?: string
530
+ imageInstructionField?: string;
729
531
  /**
730
532
  * When set, an image description will be automatically created for the image.
731
533
  *
@@ -756,36 +558,146 @@ declare module 'sanity' {
756
558
  * })
757
559
  * ```
758
560
  */
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
- }
561
+ imageDescriptionField?: string | {
562
+ path: string;
563
+ /**
564
+ * When updateOnImageChange is true (or undefined), whenever the
565
+ * image asset changes, imageDescriptionField will be regenerated.
566
+ *
567
+ * default: true
568
+ * */
569
+ updateOnImageChange?: boolean;
570
+ };
571
+ };
772
572
  }
773
573
  interface NumberOptions extends AssistOptions {}
774
574
  interface ObjectOptions extends AssistOptions {}
775
575
  interface ReferenceBaseOptions {
776
576
  aiAssist?: {
777
- /** Set to true to disable assistance for this field or type */
778
- exclude?: boolean
577
+ /** Set to true to disable assistance for this field or type */exclude?: boolean;
779
578
  /**
780
579
  * When set, the reference field will allow instructions to be added to it.
781
580
  * Should be the name of the embeddings-index where assist will look for contextually relevant documents
782
581
  * */
783
- embeddingsIndex?: string
784
- }
582
+ embeddingsIndex?: string;
583
+ };
785
584
  }
786
585
  interface SlugOptions extends AssistOptions {}
787
586
  interface StringOptions extends AssistOptions {}
788
587
  interface TextOptions extends AssistOptions {}
789
588
  interface UrlOptions extends AssistOptions {}
790
589
  interface EmailOptions extends AssistOptions {}
590
+ } //# sourceMappingURL=typeDefExtensions.d.ts.map
591
+ /**
592
+ * Default implementation for plugin config `translate.field.translationOutputs`
593
+ *
594
+ * @see FieldTranslationConfig#translationOutputs
595
+ */
596
+ declare const defaultLanguageOutputs: TranslationOutputsFunction;
597
+ type GetUserInput = (args: {
598
+ /**
599
+ * Dialog title
600
+ */
601
+ title: string;
602
+ /**
603
+ * One titled input per array item
604
+ */
605
+ inputs: CustomInput[];
606
+ }) => Promise<CustomInputResult[] | undefined>;
607
+ /**
608
+ *
609
+ */
610
+ interface CustomInput {
611
+ /**
612
+ * Id for the input
613
+ */
614
+ id: string;
615
+ /**
616
+ * Title of the input field
617
+ */
618
+ title: string;
619
+ /**
620
+ * Additional info that will be displayed over the input
621
+ */
622
+ description?: string;
791
623
  }
624
+ type CustomInputResult = {
625
+ /**
626
+ * Identifies which custom input the `result`belongs to
627
+ */
628
+ input: CustomInput;
629
+ /**
630
+ * The text provided by the user in the input
631
+ */
632
+ result: string;
633
+ };
634
+ /**
635
+ * `useUserInput` returns a function that can be used to await user input.
636
+ *
637
+ * Useful for custom `fieldActions` to get user input for populating Agent Action requests,.
638
+ *
639
+ * ```ts
640
+ * fieldActions: {
641
+ * useFieldActions: (props) => {
642
+ * const {
643
+ * documentSchemaType,
644
+ * schemaId,
645
+ * getDocumentValue,
646
+ * getConditionalPaths,
647
+ * documentIdForAction,
648
+ * } = props
649
+ * const client = useClient({apiVersion: 'vX'})
650
+ * const getUserInput = useUserInput()
651
+ * return useMemo(() => {
652
+ * return [
653
+ * defineAssistFieldAction({
654
+ * title: 'Log user input',
655
+ * icon: UserIcon,
656
+ * onAction: async () => {
657
+ * const input = await getUserInput({
658
+ * title: 'Topic',
659
+ * inputs: [{id: 'about', title: 'What should the article be about?'}],
660
+ * })
661
+ * if (!input) return // user canceled input
662
+ * await client.agent.action.generate({
663
+ * schemaId,
664
+ * targetDocument: {
665
+ * operation: 'createIfNotExists',
666
+ * _id: documentIdForAction,
667
+ * _type: documentSchemaType.name,
668
+ * initialValues: getDocumentValue(),
669
+ * },
670
+ * instruction: `
671
+ * Create a document about the following topic:
672
+ * $about
673
+ * ---
674
+ * `,
675
+ * instructionParams: {about: input[0].result},
676
+ * conditionalPaths: {paths: getConditionalPaths()},
677
+ * })
678
+ * },
679
+ * }),
680
+ * ]
681
+ * }, [
682
+ * client,
683
+ * documentSchemaType,
684
+ * schemaId,
685
+ * getDocumentValue,
686
+ * getConditionalPaths,
687
+ * documentIdForAction,
688
+ * getUserInput,
689
+ * ])
690
+ * },
691
+ * }
692
+ * ```
693
+ */
694
+ declare function useUserInput(): GetUserInput;
695
+ /**
696
+ * Returns true if the `schemaType` or any of its parent types (`schemaType.type`)` has `name` equal
697
+ * to `typeName`.
698
+ *
699
+ * Useful for checking if `schemaType` is a type alias of `ìmage`, `code` or similar.
700
+ */
701
+ declare function isType(schemaType: SchemaType, typeName: string): boolean;
702
+ export { AssistConfig, type AssistFieldActionGroup, type AssistFieldActionItem, type AssistFieldActionNode, type AssistFieldActionProps, AssistOptions, type CustomInput, type CustomInputResult, DocumentMember, DocumentTranslationConfig, FieldTranslationConfig, type GetUserInput, Language, LanguageCallback, LocaleSettings, LocaleSettingsContext, SchemaTypeTool, TranslateStyleguide, TranslateStyleguideContext, TranslationConfig, TranslationOutput, TranslationOutputsFunction, assist, contextDocumentTypeName, defaultLanguageOutputs, defineAssistFieldAction, defineAssistFieldActionGroup, defineFieldActionDivider, isType, useUserInput };
703
+ //# sourceMappingURL=index.d.ts.map