@sanity/client 6.29.0-generate.2 → 6.29.0-generate.5

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.
@@ -1,10 +1,10 @@
1
- import type {AgentActionAsync} from '@sanity/client/agent/actions/commonTypes'
1
+ import type {AgentActionAsync as AgentActionAsync_2} from '@sanity/client/agent/actions/commonTypes'
2
2
  import type {AgentActionPath as AgentActionPath_2} from '@sanity/client/agent/actions/commonTypes'
3
3
  import type {AgentActionPathSegment as AgentActionPathSegment_2} from '@sanity/client/agent/actions/commonTypes'
4
- import type {AgentActionRequestBase} from '@sanity/client/agent/actions/commonTypes'
5
- import type {AgentActionSync} from '@sanity/client/agent/actions/commonTypes'
4
+ import type {AgentActionRequestBase as AgentActionRequestBase_2} from '@sanity/client/agent/actions/commonTypes'
5
+ import type {AgentActionSync as AgentActionSync_2} from '@sanity/client/agent/actions/commonTypes'
6
6
  import type {AgentActionTarget as AgentActionTarget_2} from '@sanity/client/agent/actions/commonTypes'
7
- import type {AgentActionTargetInclude} from '@sanity/client/agent/actions/commonTypes'
7
+ import type {AgentActionTargetInclude as AgentActionTargetInclude_2} from '@sanity/client/agent/actions/commonTypes'
8
8
  import type {ContentSourceMapDocuments as ContentSourceMapDocuments_2} from '@sanity/client/csm'
9
9
  import {ContentSourceMapParsedPath} from '@sanity/client/csm'
10
10
  import {ContentSourceMapParsedPathKeyedSegment} from '@sanity/client/csm'
@@ -46,6 +46,19 @@ export declare interface ActionErrorItem {
46
46
  index: number
47
47
  }
48
48
 
49
+ /** @beta */
50
+ export declare interface AgentActionAsync {
51
+ /**
52
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
53
+ * The instruction operation will carry on in the background.
54
+ *
55
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
56
+ *
57
+ * async: true is incompatible with noWrite, as async: true does not return the resulting document
58
+ */
59
+ async: true
60
+ }
61
+
49
62
  /** @beta */
50
63
  export declare type AgentActionParam =
51
64
  | string
@@ -67,28 +80,147 @@ export declare type AgentActionPathSegment =
67
80
  _key: string
68
81
  }
69
82
 
83
+ /** @beta */
84
+ export declare interface AgentActionRequestBase {
85
+ /** schemaId as reported by sanity deploy / sanity schema store */
86
+ schemaId: string
87
+ /**
88
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
89
+ *
90
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
91
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
92
+ *
93
+ * `conditionalPaths` param allows setting the default conditional value for
94
+ * `hidden` and `readOnly` to false,
95
+ * or individually set `hidden` and `readOnly` state for individual document paths.
96
+ *
97
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
98
+ * and cannot be changed via conditionalPaths
99
+ *
100
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
101
+ *
102
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
103
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
104
+ *
105
+ * @see GenerateRequestBase#target
106
+ */
107
+ conditionalPaths?: {
108
+ defaultReadOnly?: boolean
109
+ defaultHidden?: boolean
110
+ paths?: {
111
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
112
+ path: AgentActionPath
113
+ readOnly: boolean
114
+ hidden: boolean
115
+ }[]
116
+ }
117
+ /**
118
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
119
+ * Otherwise, such fields will be ignored.
120
+ */
121
+ localeSettings?: {
122
+ /**
123
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
124
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
125
+ *
126
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
127
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
128
+ *
129
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
130
+ */
131
+ locale: string
132
+ /**
133
+ * A valid IANA time zone identifier used to resolve relative and absolute
134
+ * date expressions to a specific point in time. Examples include
135
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
136
+ *
137
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
138
+ * based on the user's local time.
139
+ *
140
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
141
+ */
142
+ timeZone: string
143
+ }
144
+ /**
145
+ * Controls how much variance the instructions will run with.
146
+ *
147
+ * Value must be in the range [0, 1] (inclusive).
148
+ *
149
+ * Defaults:
150
+ * - generate: 0.3
151
+ * - translate: 0
152
+ * - transform: 0
153
+ */
154
+ temperature?: number
155
+ }
156
+
70
157
  /** @public */
71
158
  declare class AgentActionsClient {
72
159
  #private
73
160
  constructor(client: SanityClient, httpRequest: HttpRequest)
74
- generate(request: GenerateAsyncInstruction): Promise<{
75
- _id: string
76
- }>
161
+ /**
162
+ * Run an instruction to generate content in a target document.
163
+ * @param request instruction request
164
+ */
77
165
  generate<DocumentShape extends Record<string, Any>>(
78
- request: GenerateSyncInstruction<DocumentShape>,
79
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
80
- transform(request: TransformDocumentAsync): Promise<{
81
- _id: string
82
- }>
166
+ request: GenerateInstruction<DocumentShape>,
167
+ ): Promise<
168
+ (typeof request)['async'] extends true
169
+ ? {
170
+ _id: string
171
+ }
172
+ : IdentifiedSanityDocumentStub & DocumentShape
173
+ >
174
+ /**
175
+ * Transform a target document based on a source.
176
+ * @param request translation request
177
+ */
83
178
  transform<DocumentShape extends Record<string, Any>>(
84
- request: TransformDocumentSync,
85
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
86
- translate(request: TranslateDocumentAsync): Promise<{
87
- _id: string
88
- }>
179
+ request: TransformDocument<DocumentShape>,
180
+ ): Promise<
181
+ (typeof request)['async'] extends true
182
+ ? {
183
+ _id: string
184
+ }
185
+ : IdentifiedSanityDocumentStub & DocumentShape
186
+ >
187
+ /**
188
+ * Translate a target document based on a source.
189
+ * @param request translation request
190
+ */
89
191
  translate<DocumentShape extends Record<string, Any>>(
90
- request: TranslateDocumentSync,
91
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
192
+ request: TranslateDocument<DocumentShape>,
193
+ ): Promise<
194
+ (typeof request)['async'] extends true
195
+ ? {
196
+ _id: string
197
+ }
198
+ : IdentifiedSanityDocumentStub & DocumentShape
199
+ >
200
+ }
201
+
202
+ /** @beta */
203
+ export declare interface AgentActionSync {
204
+ /**
205
+ * By default, noWrite: false.
206
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
207
+ *
208
+ * When noWrite: true, the api will not mutate any documents nor emit presence.
209
+ * Ie, when true, no changes will be made to content-lake
210
+ *
211
+ * noWrite: true is incompatible with async: true,
212
+ * as noWrite implies that you will use the return value of the operation
213
+ */
214
+ noWrite?: boolean
215
+ /**
216
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
217
+ * The instruction operation will carry on in the background.
218
+ *
219
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
220
+ *
221
+ * async: true is incompatible with noWrite: true, as async: true does not return the resulting document
222
+ */
223
+ async?: false
92
224
  }
93
225
 
94
226
  /**
@@ -143,7 +275,24 @@ export declare interface AgentActionTarget {
143
275
  }
144
276
 
145
277
  /** @beta */
146
- declare type AgentActionTypeConfig =
278
+ export declare interface AgentActionTargetInclude {
279
+ path: AgentActionPathSegment | AgentActionPath
280
+ /**
281
+ * By default, all children up to `target.maxPathDepth` are included.
282
+ * Fields or array items not on the exclude list, are implicitly included.
283
+ */
284
+ exclude?: AgentActionPathSegment[]
285
+ /**
286
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
287
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
288
+ *
289
+ * `types.include` and `types.exclude` are mutually exclusive.
290
+ */
291
+ types?: AgentActionTypeConfig
292
+ }
293
+
294
+ /** @beta */
295
+ export declare type AgentActionTypeConfig =
147
296
  | {
148
297
  include: string[]
149
298
  exclude?: never
@@ -1004,12 +1153,10 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1004
1153
  }
1005
1154
 
1006
1155
  /** @beta */
1007
- declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1008
- | GenerateExistingDocumentRequest
1009
- | GenerateCreateDocumentRequest<T>
1010
- ) &
1011
- GenerateRequestBase &
1012
- AgentActionAsync
1156
+ export declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> =
1157
+ (GenerateExistingDocumentRequest | GenerateCreateDocumentRequest<T>) &
1158
+ GenerateRequestBase &
1159
+ AgentActionAsync_2
1013
1160
 
1014
1161
  /**
1015
1162
  * Instruction to create a new document
@@ -1044,7 +1191,7 @@ export declare type GenerateInstruction<T extends Record<string, Any> = Record<s
1044
1191
  export declare type GenerateOperation = 'set' | 'append' | 'mixed'
1045
1192
 
1046
1193
  /** @beta */
1047
- declare interface GenerateRequestBase extends AgentActionRequestBase {
1194
+ export declare interface GenerateRequestBase extends AgentActionRequestBase_2 {
1048
1195
  /** schemaId as reported by sanity deploy / sanity schema store */
1049
1196
  schemaId: string
1050
1197
  /** string template using $variable */
@@ -1068,12 +1215,12 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1068
1215
  }
1069
1216
 
1070
1217
  /** @beta */
1071
- declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1218
+ export declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1072
1219
  | GenerateExistingDocumentRequest
1073
1220
  | GenerateCreateDocumentRequest<T>
1074
1221
  ) &
1075
1222
  GenerateRequestBase &
1076
- AgentActionSync
1223
+ AgentActionSync_2
1077
1224
 
1078
1225
  /** @beta */
1079
1226
  export declare interface GenerateTarget extends AgentActionTarget_2 {
@@ -1121,7 +1268,7 @@ export declare interface GenerateTarget extends AgentActionTarget_2 {
1121
1268
  }
1122
1269
 
1123
1270
  /** @beta */
1124
- export declare interface GenerateTargetInclude extends AgentActionTargetInclude {
1271
+ export declare interface GenerateTargetInclude extends AgentActionTargetInclude_2 {
1125
1272
  /**
1126
1273
  * Sets the operation for this path, and all its children.
1127
1274
  * This overrides any operation set parents or the root target.
@@ -1585,24 +1732,45 @@ export declare type MutationSelectionQueryParams = {
1585
1732
  declare class ObservableAgentsActionClient {
1586
1733
  #private
1587
1734
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1588
- generate(request: GenerateAsyncInstruction): Observable<{
1589
- _id: string
1590
- }>
1735
+ /**
1736
+ * Run an instruction to generate content in a target document.
1737
+ * @param request instruction request
1738
+ */
1591
1739
  generate<DocumentShape extends Record<string, Any>>(
1592
- request: GenerateSyncInstruction<DocumentShape>,
1593
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1594
- transform(request: TransformDocumentAsync): Observable<{
1595
- _id: string
1596
- }>
1740
+ request: GenerateInstruction<DocumentShape>,
1741
+ ): Observable<
1742
+ (typeof request)['async'] extends true
1743
+ ? {
1744
+ _id: string
1745
+ }
1746
+ : IdentifiedSanityDocumentStub & DocumentShape
1747
+ >
1748
+ /**
1749
+ * Transform a target document based on a source.
1750
+ * @param request translation request
1751
+ */
1597
1752
  transform<DocumentShape extends Record<string, Any>>(
1598
- request: TransformDocumentSync,
1599
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1600
- translate(request: TranslateDocumentAsync): Observable<{
1601
- _id: string
1602
- }>
1753
+ request: TransformDocument<DocumentShape>,
1754
+ ): Observable<
1755
+ (typeof request)['async'] extends true
1756
+ ? {
1757
+ _id: string
1758
+ }
1759
+ : IdentifiedSanityDocumentStub & DocumentShape
1760
+ >
1761
+ /**
1762
+ * Translate a target document based on a source.
1763
+ * @param request translation request
1764
+ */
1603
1765
  translate<DocumentShape extends Record<string, Any>>(
1604
- request: TranslateDocumentSync,
1605
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1766
+ request: TranslateDocument<DocumentShape>,
1767
+ ): Observable<
1768
+ (typeof request)['async'] extends true
1769
+ ? {
1770
+ _id: string
1771
+ }
1772
+ : IdentifiedSanityDocumentStub & DocumentShape
1773
+ >
1606
1774
  }
1607
1775
 
1608
1776
  /** @internal */
@@ -3522,16 +3690,19 @@ export declare type TransactionMutationOptions =
3522
3690
  | TransactionAllDocumentIdsMutationOptions
3523
3691
 
3524
3692
  /** @beta */
3525
- export declare type TransformDocument = TransformDocumentSync | TransformDocumentAsync
3693
+ export declare type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
3694
+ | TransformDocumentSync<T>
3695
+ | TransformDocumentAsync
3526
3696
 
3527
3697
  /** @beta */
3528
- declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
3698
+ export declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync_2
3529
3699
 
3530
3700
  /** @beta */
3531
- declare type TransformDocumentSync = TransformRequestBase & AgentActionSync
3701
+ export declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
3702
+ TransformRequestBase & AgentActionSync_2
3532
3703
 
3533
3704
  /** @beta */
3534
- declare interface TransformRequestBase extends AgentActionRequestBase {
3705
+ export declare interface TransformRequestBase extends AgentActionRequestBase_2 {
3535
3706
  /** schemaId as reported by sanity deploy / sanity schema store */
3536
3707
  schemaId: string
3537
3708
  documentId: string
@@ -3590,7 +3761,7 @@ export declare type TransformTargetDocument =
3590
3761
  }
3591
3762
 
3592
3763
  /** @beta */
3593
- export declare interface TransformTargetInclude extends AgentActionTargetInclude {
3764
+ export declare interface TransformTargetInclude extends AgentActionTargetInclude_2 {
3594
3765
  /** string template using $variable from instructionParams */
3595
3766
  transformation?: string
3596
3767
  /**
@@ -3604,22 +3775,25 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
3604
3775
  }
3605
3776
 
3606
3777
  /** @beta */
3607
- export declare type TranslateDocument = TranslateDocumentSync | TranslateDocumentAsync
3778
+ export declare type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
3779
+ | TranslateDocumentSync<T>
3780
+ | TranslateDocumentAsync
3608
3781
 
3609
3782
  /** @beta */
3610
- declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
3783
+ export declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync_2
3611
3784
 
3612
3785
  /** @beta */
3613
- declare type TranslateDocumentSync = TranslateRequestBase & AgentActionSync
3786
+ export declare type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
3787
+ TranslateRequestBase & AgentActionSync_2
3614
3788
 
3615
3789
  /** @beta */
3616
- declare interface TranslateLanguage {
3790
+ export declare interface TranslateLanguage {
3617
3791
  id: string
3618
3792
  title?: string
3619
3793
  }
3620
3794
 
3621
3795
  /** @beta */
3622
- declare interface TranslateRequestBase extends AgentActionRequestBase {
3796
+ export declare interface TranslateRequestBase extends AgentActionRequestBase_2 {
3623
3797
  /** schemaId as reported by sanity deploy / sanity schema store */
3624
3798
  schemaId: string
3625
3799
  documentId: string
@@ -3663,7 +3837,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
3663
3837
  }
3664
3838
 
3665
3839
  /** @beta */
3666
- export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
3840
+ export declare interface TranslateTargetInclude extends AgentActionTargetInclude_2 {
3667
3841
  /** string template using $variable from instructionParams */
3668
3842
  styleGuide?: string
3669
3843
  /**