@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.
package/dist/index.d.cts CHANGED
@@ -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
@@ -1008,12 +1157,10 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1008
1157
  }
1009
1158
 
1010
1159
  /** @beta */
1011
- declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1012
- | GenerateExistingDocumentRequest
1013
- | GenerateCreateDocumentRequest<T>
1014
- ) &
1015
- GenerateRequestBase &
1016
- AgentActionAsync
1160
+ export declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> =
1161
+ (GenerateExistingDocumentRequest | GenerateCreateDocumentRequest<T>) &
1162
+ GenerateRequestBase &
1163
+ AgentActionAsync_2
1017
1164
 
1018
1165
  /**
1019
1166
  * Instruction to create a new document
@@ -1048,7 +1195,7 @@ export declare type GenerateInstruction<T extends Record<string, Any> = Record<s
1048
1195
  export declare type GenerateOperation = 'set' | 'append' | 'mixed'
1049
1196
 
1050
1197
  /** @beta */
1051
- declare interface GenerateRequestBase extends AgentActionRequestBase {
1198
+ export declare interface GenerateRequestBase extends AgentActionRequestBase_2 {
1052
1199
  /** schemaId as reported by sanity deploy / sanity schema store */
1053
1200
  schemaId: string
1054
1201
  /** string template using $variable */
@@ -1072,12 +1219,12 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1072
1219
  }
1073
1220
 
1074
1221
  /** @beta */
1075
- declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1222
+ export declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1076
1223
  | GenerateExistingDocumentRequest
1077
1224
  | GenerateCreateDocumentRequest<T>
1078
1225
  ) &
1079
1226
  GenerateRequestBase &
1080
- AgentActionSync
1227
+ AgentActionSync_2
1081
1228
 
1082
1229
  /** @beta */
1083
1230
  export declare interface GenerateTarget extends AgentActionTarget_2 {
@@ -1125,7 +1272,7 @@ export declare interface GenerateTarget extends AgentActionTarget_2 {
1125
1272
  }
1126
1273
 
1127
1274
  /** @beta */
1128
- export declare interface GenerateTargetInclude extends AgentActionTargetInclude {
1275
+ export declare interface GenerateTargetInclude extends AgentActionTargetInclude_2 {
1129
1276
  /**
1130
1277
  * Sets the operation for this path, and all its children.
1131
1278
  * This overrides any operation set parents or the root target.
@@ -1589,24 +1736,45 @@ export declare type MutationSelectionQueryParams = {
1589
1736
  declare class ObservableAgentsActionClient {
1590
1737
  #private
1591
1738
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1592
- generate(request: GenerateAsyncInstruction): Observable<{
1593
- _id: string
1594
- }>
1739
+ /**
1740
+ * Run an instruction to generate content in a target document.
1741
+ * @param request instruction request
1742
+ */
1595
1743
  generate<DocumentShape extends Record<string, Any>>(
1596
- request: GenerateSyncInstruction<DocumentShape>,
1597
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1598
- transform(request: TransformDocumentAsync): Observable<{
1599
- _id: string
1600
- }>
1744
+ request: GenerateInstruction<DocumentShape>,
1745
+ ): Observable<
1746
+ (typeof request)['async'] extends true
1747
+ ? {
1748
+ _id: string
1749
+ }
1750
+ : IdentifiedSanityDocumentStub & DocumentShape
1751
+ >
1752
+ /**
1753
+ * Transform a target document based on a source.
1754
+ * @param request translation request
1755
+ */
1601
1756
  transform<DocumentShape extends Record<string, Any>>(
1602
- request: TransformDocumentSync,
1603
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1604
- translate(request: TranslateDocumentAsync): Observable<{
1605
- _id: string
1606
- }>
1757
+ request: TransformDocument<DocumentShape>,
1758
+ ): Observable<
1759
+ (typeof request)['async'] extends true
1760
+ ? {
1761
+ _id: string
1762
+ }
1763
+ : IdentifiedSanityDocumentStub & DocumentShape
1764
+ >
1765
+ /**
1766
+ * Translate a target document based on a source.
1767
+ * @param request translation request
1768
+ */
1607
1769
  translate<DocumentShape extends Record<string, Any>>(
1608
- request: TranslateDocumentSync,
1609
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1770
+ request: TranslateDocument<DocumentShape>,
1771
+ ): Observable<
1772
+ (typeof request)['async'] extends true
1773
+ ? {
1774
+ _id: string
1775
+ }
1776
+ : IdentifiedSanityDocumentStub & DocumentShape
1777
+ >
1610
1778
  }
1611
1779
 
1612
1780
  /** @internal */
@@ -3526,16 +3694,19 @@ export declare type TransactionMutationOptions =
3526
3694
  | TransactionAllDocumentIdsMutationOptions
3527
3695
 
3528
3696
  /** @beta */
3529
- export declare type TransformDocument = TransformDocumentSync | TransformDocumentAsync
3697
+ export declare type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
3698
+ | TransformDocumentSync<T>
3699
+ | TransformDocumentAsync
3530
3700
 
3531
3701
  /** @beta */
3532
- declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
3702
+ export declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync_2
3533
3703
 
3534
3704
  /** @beta */
3535
- declare type TransformDocumentSync = TransformRequestBase & AgentActionSync
3705
+ export declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
3706
+ TransformRequestBase & AgentActionSync_2
3536
3707
 
3537
3708
  /** @beta */
3538
- declare interface TransformRequestBase extends AgentActionRequestBase {
3709
+ export declare interface TransformRequestBase extends AgentActionRequestBase_2 {
3539
3710
  /** schemaId as reported by sanity deploy / sanity schema store */
3540
3711
  schemaId: string
3541
3712
  documentId: string
@@ -3594,7 +3765,7 @@ export declare type TransformTargetDocument =
3594
3765
  }
3595
3766
 
3596
3767
  /** @beta */
3597
- export declare interface TransformTargetInclude extends AgentActionTargetInclude {
3768
+ export declare interface TransformTargetInclude extends AgentActionTargetInclude_2 {
3598
3769
  /** string template using $variable from instructionParams */
3599
3770
  transformation?: string
3600
3771
  /**
@@ -3608,22 +3779,25 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
3608
3779
  }
3609
3780
 
3610
3781
  /** @beta */
3611
- export declare type TranslateDocument = TranslateDocumentSync | TranslateDocumentAsync
3782
+ export declare type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
3783
+ | TranslateDocumentSync<T>
3784
+ | TranslateDocumentAsync
3612
3785
 
3613
3786
  /** @beta */
3614
- declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
3787
+ export declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync_2
3615
3788
 
3616
3789
  /** @beta */
3617
- declare type TranslateDocumentSync = TranslateRequestBase & AgentActionSync
3790
+ export declare type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
3791
+ TranslateRequestBase & AgentActionSync_2
3618
3792
 
3619
3793
  /** @beta */
3620
- declare interface TranslateLanguage {
3794
+ export declare interface TranslateLanguage {
3621
3795
  id: string
3622
3796
  title?: string
3623
3797
  }
3624
3798
 
3625
3799
  /** @beta */
3626
- declare interface TranslateRequestBase extends AgentActionRequestBase {
3800
+ export declare interface TranslateRequestBase extends AgentActionRequestBase_2 {
3627
3801
  /** schemaId as reported by sanity deploy / sanity schema store */
3628
3802
  schemaId: string
3629
3803
  documentId: string
@@ -3667,7 +3841,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
3667
3841
  }
3668
3842
 
3669
3843
  /** @beta */
3670
- export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
3844
+ export declare interface TranslateTargetInclude extends AgentActionTargetInclude_2 {
3671
3845
  /** string template using $variable from instructionParams */
3672
3846
  styleGuide?: string
3673
3847
  /**