@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 {ClientConfig as ClientConfig_2} from '@sanity/client'
9
9
  import {Observable} from 'rxjs'
10
10
  import {Requester} from 'get-it'
@@ -40,6 +40,19 @@ export declare interface ActionErrorItem {
40
40
  index: number
41
41
  }
42
42
 
43
+ /** @beta */
44
+ export declare interface AgentActionAsync {
45
+ /**
46
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
47
+ * The instruction operation will carry on in the background.
48
+ *
49
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
50
+ *
51
+ * async: true is incompatible with noWrite, as async: true does not return the resulting document
52
+ */
53
+ async: true
54
+ }
55
+
43
56
  /** @beta */
44
57
  export declare type AgentActionParam =
45
58
  | string
@@ -61,28 +74,147 @@ export declare type AgentActionPathSegment =
61
74
  _key: string
62
75
  }
63
76
 
77
+ /** @beta */
78
+ export declare interface AgentActionRequestBase {
79
+ /** schemaId as reported by sanity deploy / sanity schema store */
80
+ schemaId: string
81
+ /**
82
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
83
+ *
84
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
85
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
86
+ *
87
+ * `conditionalPaths` param allows setting the default conditional value for
88
+ * `hidden` and `readOnly` to false,
89
+ * or individually set `hidden` and `readOnly` state for individual document paths.
90
+ *
91
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
92
+ * and cannot be changed via conditionalPaths
93
+ *
94
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
95
+ *
96
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
97
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
98
+ *
99
+ * @see GenerateRequestBase#target
100
+ */
101
+ conditionalPaths?: {
102
+ defaultReadOnly?: boolean
103
+ defaultHidden?: boolean
104
+ paths?: {
105
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
106
+ path: AgentActionPath
107
+ readOnly: boolean
108
+ hidden: boolean
109
+ }[]
110
+ }
111
+ /**
112
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
113
+ * Otherwise, such fields will be ignored.
114
+ */
115
+ localeSettings?: {
116
+ /**
117
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
118
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
119
+ *
120
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
121
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
122
+ *
123
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
124
+ */
125
+ locale: string
126
+ /**
127
+ * A valid IANA time zone identifier used to resolve relative and absolute
128
+ * date expressions to a specific point in time. Examples include
129
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
130
+ *
131
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
132
+ * based on the user's local time.
133
+ *
134
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
135
+ */
136
+ timeZone: string
137
+ }
138
+ /**
139
+ * Controls how much variance the instructions will run with.
140
+ *
141
+ * Value must be in the range [0, 1] (inclusive).
142
+ *
143
+ * Defaults:
144
+ * - generate: 0.3
145
+ * - translate: 0
146
+ * - transform: 0
147
+ */
148
+ temperature?: number
149
+ }
150
+
64
151
  /** @public */
65
152
  declare class AgentActionsClient {
66
153
  #private
67
154
  constructor(client: SanityClient, httpRequest: HttpRequest)
68
- generate(request: GenerateAsyncInstruction): Promise<{
69
- _id: string
70
- }>
155
+ /**
156
+ * Run an instruction to generate content in a target document.
157
+ * @param request instruction request
158
+ */
71
159
  generate<DocumentShape extends Record<string, Any>>(
72
- request: GenerateSyncInstruction<DocumentShape>,
73
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
74
- transform(request: TransformDocumentAsync): Promise<{
75
- _id: string
76
- }>
160
+ request: GenerateInstruction<DocumentShape>,
161
+ ): Promise<
162
+ (typeof request)['async'] extends true
163
+ ? {
164
+ _id: string
165
+ }
166
+ : IdentifiedSanityDocumentStub & DocumentShape
167
+ >
168
+ /**
169
+ * Transform a target document based on a source.
170
+ * @param request translation request
171
+ */
77
172
  transform<DocumentShape extends Record<string, Any>>(
78
- request: TransformDocumentSync,
79
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
80
- translate(request: TranslateDocumentAsync): Promise<{
81
- _id: string
82
- }>
173
+ request: TransformDocument<DocumentShape>,
174
+ ): Promise<
175
+ (typeof request)['async'] extends true
176
+ ? {
177
+ _id: string
178
+ }
179
+ : IdentifiedSanityDocumentStub & DocumentShape
180
+ >
181
+ /**
182
+ * Translate a target document based on a source.
183
+ * @param request translation request
184
+ */
83
185
  translate<DocumentShape extends Record<string, Any>>(
84
- request: TranslateDocumentSync,
85
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
186
+ request: TranslateDocument<DocumentShape>,
187
+ ): Promise<
188
+ (typeof request)['async'] extends true
189
+ ? {
190
+ _id: string
191
+ }
192
+ : IdentifiedSanityDocumentStub & DocumentShape
193
+ >
194
+ }
195
+
196
+ /** @beta */
197
+ export declare interface AgentActionSync {
198
+ /**
199
+ * By default, noWrite: false.
200
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
201
+ *
202
+ * When noWrite: true, the api will not mutate any documents nor emit presence.
203
+ * Ie, when true, no changes will be made to content-lake
204
+ *
205
+ * noWrite: true is incompatible with async: true,
206
+ * as noWrite implies that you will use the return value of the operation
207
+ */
208
+ noWrite?: boolean
209
+ /**
210
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
211
+ * The instruction operation will carry on in the background.
212
+ *
213
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
214
+ *
215
+ * async: true is incompatible with noWrite: true, as async: true does not return the resulting document
216
+ */
217
+ async?: false
86
218
  }
87
219
 
88
220
  /**
@@ -137,7 +269,24 @@ export declare interface AgentActionTarget {
137
269
  }
138
270
 
139
271
  /** @beta */
140
- declare type AgentActionTypeConfig =
272
+ export declare interface AgentActionTargetInclude {
273
+ path: AgentActionPathSegment | AgentActionPath
274
+ /**
275
+ * By default, all children up to `target.maxPathDepth` are included.
276
+ * Fields or array items not on the exclude list, are implicitly included.
277
+ */
278
+ exclude?: AgentActionPathSegment[]
279
+ /**
280
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
281
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
282
+ *
283
+ * `types.include` and `types.exclude` are mutually exclusive.
284
+ */
285
+ types?: AgentActionTypeConfig
286
+ }
287
+
288
+ /** @beta */
289
+ export declare type AgentActionTypeConfig =
141
290
  | {
142
291
  include: string[]
143
292
  exclude?: never
@@ -1164,12 +1313,10 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1164
1313
  }
1165
1314
 
1166
1315
  /** @beta */
1167
- declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1168
- | GenerateExistingDocumentRequest
1169
- | GenerateCreateDocumentRequest<T>
1170
- ) &
1171
- GenerateRequestBase &
1172
- AgentActionAsync
1316
+ export declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> =
1317
+ (GenerateExistingDocumentRequest | GenerateCreateDocumentRequest<T>) &
1318
+ GenerateRequestBase &
1319
+ AgentActionAsync_2
1173
1320
 
1174
1321
  /**
1175
1322
  * Instruction to create a new document
@@ -1204,7 +1351,7 @@ export declare type GenerateInstruction<T extends Record<string, Any> = Record<s
1204
1351
  export declare type GenerateOperation = 'set' | 'append' | 'mixed'
1205
1352
 
1206
1353
  /** @beta */
1207
- declare interface GenerateRequestBase extends AgentActionRequestBase {
1354
+ export declare interface GenerateRequestBase extends AgentActionRequestBase_2 {
1208
1355
  /** schemaId as reported by sanity deploy / sanity schema store */
1209
1356
  schemaId: string
1210
1357
  /** string template using $variable */
@@ -1228,12 +1375,12 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1228
1375
  }
1229
1376
 
1230
1377
  /** @beta */
1231
- declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1378
+ export declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1232
1379
  | GenerateExistingDocumentRequest
1233
1380
  | GenerateCreateDocumentRequest<T>
1234
1381
  ) &
1235
1382
  GenerateRequestBase &
1236
- AgentActionSync
1383
+ AgentActionSync_2
1237
1384
 
1238
1385
  /** @beta */
1239
1386
  export declare interface GenerateTarget extends AgentActionTarget_2 {
@@ -1281,7 +1428,7 @@ export declare interface GenerateTarget extends AgentActionTarget_2 {
1281
1428
  }
1282
1429
 
1283
1430
  /** @beta */
1284
- export declare interface GenerateTargetInclude extends AgentActionTargetInclude {
1431
+ export declare interface GenerateTargetInclude extends AgentActionTargetInclude_2 {
1285
1432
  /**
1286
1433
  * Sets the operation for this path, and all its children.
1287
1434
  * This overrides any operation set parents or the root target.
@@ -1762,24 +1909,45 @@ export declare type MutationSelectionQueryParams = {
1762
1909
  declare class ObservableAgentsActionClient {
1763
1910
  #private
1764
1911
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1765
- generate(request: GenerateAsyncInstruction): Observable<{
1766
- _id: string
1767
- }>
1912
+ /**
1913
+ * Run an instruction to generate content in a target document.
1914
+ * @param request instruction request
1915
+ */
1768
1916
  generate<DocumentShape extends Record<string, Any>>(
1769
- request: GenerateSyncInstruction<DocumentShape>,
1770
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1771
- transform(request: TransformDocumentAsync): Observable<{
1772
- _id: string
1773
- }>
1917
+ request: GenerateInstruction<DocumentShape>,
1918
+ ): Observable<
1919
+ (typeof request)['async'] extends true
1920
+ ? {
1921
+ _id: string
1922
+ }
1923
+ : IdentifiedSanityDocumentStub & DocumentShape
1924
+ >
1925
+ /**
1926
+ * Transform a target document based on a source.
1927
+ * @param request translation request
1928
+ */
1774
1929
  transform<DocumentShape extends Record<string, Any>>(
1775
- request: TransformDocumentSync,
1776
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1777
- translate(request: TranslateDocumentAsync): Observable<{
1778
- _id: string
1779
- }>
1930
+ request: TransformDocument<DocumentShape>,
1931
+ ): Observable<
1932
+ (typeof request)['async'] extends true
1933
+ ? {
1934
+ _id: string
1935
+ }
1936
+ : IdentifiedSanityDocumentStub & DocumentShape
1937
+ >
1938
+ /**
1939
+ * Translate a target document based on a source.
1940
+ * @param request translation request
1941
+ */
1780
1942
  translate<DocumentShape extends Record<string, Any>>(
1781
- request: TranslateDocumentSync,
1782
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1943
+ request: TranslateDocument<DocumentShape>,
1944
+ ): Observable<
1945
+ (typeof request)['async'] extends true
1946
+ ? {
1947
+ _id: string
1948
+ }
1949
+ : IdentifiedSanityDocumentStub & DocumentShape
1950
+ >
1783
1951
  }
1784
1952
 
1785
1953
  /** @internal */
@@ -3780,16 +3948,19 @@ export declare type TransactionMutationOptions =
3780
3948
  | TransactionAllDocumentIdsMutationOptions
3781
3949
 
3782
3950
  /** @beta */
3783
- export declare type TransformDocument = TransformDocumentSync | TransformDocumentAsync
3951
+ export declare type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
3952
+ | TransformDocumentSync<T>
3953
+ | TransformDocumentAsync
3784
3954
 
3785
3955
  /** @beta */
3786
- declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
3956
+ export declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync_2
3787
3957
 
3788
3958
  /** @beta */
3789
- declare type TransformDocumentSync = TransformRequestBase & AgentActionSync
3959
+ export declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
3960
+ TransformRequestBase & AgentActionSync_2
3790
3961
 
3791
3962
  /** @beta */
3792
- declare interface TransformRequestBase extends AgentActionRequestBase {
3963
+ export declare interface TransformRequestBase extends AgentActionRequestBase_2 {
3793
3964
  /** schemaId as reported by sanity deploy / sanity schema store */
3794
3965
  schemaId: string
3795
3966
  documentId: string
@@ -3848,7 +4019,7 @@ export declare type TransformTargetDocument =
3848
4019
  }
3849
4020
 
3850
4021
  /** @beta */
3851
- export declare interface TransformTargetInclude extends AgentActionTargetInclude {
4022
+ export declare interface TransformTargetInclude extends AgentActionTargetInclude_2 {
3852
4023
  /** string template using $variable from instructionParams */
3853
4024
  transformation?: string
3854
4025
  /**
@@ -3862,22 +4033,25 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
3862
4033
  }
3863
4034
 
3864
4035
  /** @beta */
3865
- export declare type TranslateDocument = TranslateDocumentSync | TranslateDocumentAsync
4036
+ export declare type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
4037
+ | TranslateDocumentSync<T>
4038
+ | TranslateDocumentAsync
3866
4039
 
3867
4040
  /** @beta */
3868
- declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
4041
+ export declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync_2
3869
4042
 
3870
4043
  /** @beta */
3871
- declare type TranslateDocumentSync = TranslateRequestBase & AgentActionSync
4044
+ export declare type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
4045
+ TranslateRequestBase & AgentActionSync_2
3872
4046
 
3873
4047
  /** @beta */
3874
- declare interface TranslateLanguage {
4048
+ export declare interface TranslateLanguage {
3875
4049
  id: string
3876
4050
  title?: string
3877
4051
  }
3878
4052
 
3879
4053
  /** @beta */
3880
- declare interface TranslateRequestBase extends AgentActionRequestBase {
4054
+ export declare interface TranslateRequestBase extends AgentActionRequestBase_2 {
3881
4055
  /** schemaId as reported by sanity deploy / sanity schema store */
3882
4056
  schemaId: string
3883
4057
  documentId: string
@@ -3921,7 +4095,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
3921
4095
  }
3922
4096
 
3923
4097
  /** @beta */
3924
- export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
4098
+ export declare interface TranslateTargetInclude extends AgentActionTargetInclude_2 {
3925
4099
  /** string template using $variable from instructionParams */
3926
4100
  styleGuide?: string
3927
4101
  /**