@sanity/client 7.0.1-canary.2 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,262 @@ export declare interface ActionErrorItem {
33
33
  index: number
34
34
  }
35
35
 
36
+ /** @beta */
37
+ declare interface AgentActionAsync {
38
+ /**
39
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
40
+ * The instruction operation will carry on in the background.
41
+ *
42
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
43
+ *
44
+ * async: true is incompatible with noWrite, as async: true does not return the resulting document
45
+ */
46
+ async: true
47
+ }
48
+
49
+ /** @beta */
50
+ export declare type AgentActionParam =
51
+ | string
52
+ | ConstantAgentActionParam
53
+ | FieldAgentActionParam
54
+ | DocumentAgentActionParam
55
+ | GroqAgentActionParam
56
+
57
+ /** @beta */
58
+ export declare type AgentActionParams = Record<string, AgentActionParam>
59
+
60
+ /** @beta */
61
+ export declare type AgentActionPath = AgentActionPathSegment[]
62
+
63
+ /** @beta */
64
+ export declare type AgentActionPathSegment =
65
+ | string
66
+ | {
67
+ _key: string
68
+ }
69
+
70
+ /** @beta */
71
+ declare interface AgentActionRequestBase {
72
+ /** schemaId as reported by sanity deploy / sanity schema store */
73
+ schemaId: string
74
+ /**
75
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
76
+ *
77
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
78
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
79
+ *
80
+ * `conditionalPaths` param allows setting the default conditional value for
81
+ * `hidden` and `readOnly` to false,
82
+ * or individually set `hidden` and `readOnly` state for individual document paths.
83
+ *
84
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
85
+ * and cannot be changed via conditionalPaths
86
+ *
87
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
88
+ *
89
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
90
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
91
+ *
92
+ * @see GenerateRequestBase#target
93
+ */
94
+ conditionalPaths?: {
95
+ defaultReadOnly?: boolean
96
+ defaultHidden?: boolean
97
+ paths?: {
98
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
99
+ path: AgentActionPath
100
+ readOnly: boolean
101
+ hidden: boolean
102
+ }[]
103
+ }
104
+ /**
105
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
106
+ * Otherwise, such fields will be ignored.
107
+ */
108
+ localeSettings?: {
109
+ /**
110
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
111
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
112
+ *
113
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
114
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
115
+ *
116
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
117
+ */
118
+ locale: string
119
+ /**
120
+ * A valid IANA time zone identifier used to resolve relative and absolute
121
+ * date expressions to a specific point in time. Examples include
122
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
123
+ *
124
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
125
+ * based on the user's local time.
126
+ *
127
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
128
+ */
129
+ timeZone: string
130
+ }
131
+ /**
132
+ * Controls how much variance the instructions will run with.
133
+ *
134
+ * Value must be in the range [0, 1] (inclusive).
135
+ *
136
+ * Defaults:
137
+ * - generate: 0.3
138
+ * - translate: 0
139
+ * - transform: 0
140
+ */
141
+ temperature?: number
142
+ }
143
+
144
+ /** @public */
145
+ declare class AgentActionsClient {
146
+ #private
147
+ constructor(client: SanityClient, httpRequest: HttpRequest)
148
+ /**
149
+ * Run an instruction to generate content in a target document.
150
+ * @param request - instruction request
151
+ */
152
+ generate<DocumentShape extends Record<string, Any>>(
153
+ request: GenerateInstruction<DocumentShape>,
154
+ ): Promise<
155
+ (typeof request)['async'] extends true
156
+ ? {
157
+ _id: string
158
+ }
159
+ : IdentifiedSanityDocumentStub & DocumentShape
160
+ >
161
+ /**
162
+ * Transform a target document based on a source.
163
+ * @param request - translation request
164
+ */
165
+ transform<DocumentShape extends Record<string, Any>>(
166
+ request: TransformDocument<DocumentShape>,
167
+ ): Promise<
168
+ (typeof request)['async'] extends true
169
+ ? {
170
+ _id: string
171
+ }
172
+ : IdentifiedSanityDocumentStub & DocumentShape
173
+ >
174
+ /**
175
+ * Translate a target document based on a source.
176
+ * @param request - translation request
177
+ */
178
+ translate<DocumentShape extends Record<string, Any>>(
179
+ request: TranslateDocument<DocumentShape>,
180
+ ): Promise<
181
+ (typeof request)['async'] extends true
182
+ ? {
183
+ _id: string
184
+ }
185
+ : IdentifiedSanityDocumentStub & DocumentShape
186
+ >
187
+ }
188
+
189
+ /** @beta */
190
+ declare interface AgentActionSync {
191
+ /**
192
+ * By default, noWrite: false.
193
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
194
+ *
195
+ * When noWrite: true, the api will not mutate any documents nor emit presence.
196
+ * Ie, when true, no changes will be made to content-lake
197
+ *
198
+ * noWrite: true is incompatible with async: true,
199
+ * as noWrite implies that you will use the return value of the operation
200
+ */
201
+ noWrite?: boolean
202
+ /**
203
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
204
+ * The instruction operation will carry on in the background.
205
+ *
206
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
207
+ *
208
+ * async: true is incompatible with noWrite: true, as async: true does not return the resulting document
209
+ */
210
+ async?: false
211
+ }
212
+
213
+ /**
214
+ * @beta
215
+ */
216
+ export declare interface AgentActionTarget {
217
+ /**
218
+ * Root target path.
219
+ *
220
+ * Use this to have the instruction only affect a part of the document.
221
+ *
222
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
223
+ * and `types.exclude`.
224
+ *
225
+ * Example:
226
+ *
227
+ * `path: ['body', {_key: 'someKey'}, 'nestedObject']`
228
+ *
229
+ * Here, the instruction will only write to fields under the nestedObject.
230
+ *
231
+ * Default: [] = the document itself
232
+ *
233
+ * @see #AgentActionPathSegment
234
+ * @see #AgentActionPath
235
+ * */
236
+ path?: AgentActionPathSegment | AgentActionPath
237
+ /**
238
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
239
+ *
240
+ * Depth is based on path segments:
241
+ * - `title` has depth 1
242
+ * - `array[_key="no"].title` has depth 3
243
+ *
244
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
245
+ * negative impact on performance; both for runtime and quality of responses.
246
+ *
247
+ * Default: 4
248
+ */
249
+ maxPathDepth?: number
250
+ /**
251
+ * By default, all children up to `target.maxPathDepth` are included.
252
+ * Fields or array items not on the exclude list, are implicitly included.
253
+ */
254
+ exclude?: AgentActionPathSegment[]
255
+ /**
256
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
257
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
258
+ *
259
+ * `types.include` and `types.exclude` are mutually exclusive.
260
+ */
261
+ types?: AgentActionTypeConfig
262
+ }
263
+
264
+ /** @beta */
265
+ declare interface AgentActionTargetInclude {
266
+ path: AgentActionPathSegment | AgentActionPath
267
+ /**
268
+ * By default, all children up to `target.maxPathDepth` are included.
269
+ * Fields or array items not on the exclude list, are implicitly included.
270
+ */
271
+ exclude?: AgentActionPathSegment[]
272
+ /**
273
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
274
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
275
+ *
276
+ * `types.include` and `types.exclude` are mutually exclusive.
277
+ */
278
+ types?: AgentActionTypeConfig
279
+ }
280
+
281
+ /** @beta */
282
+ declare type AgentActionTypeConfig =
283
+ | {
284
+ include: string[]
285
+ exclude?: never
286
+ }
287
+ | {
288
+ exclude: string[]
289
+ include?: never
290
+ }
291
+
36
292
  /** @internal */
37
293
  export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
38
294
  returnFirst: false
@@ -69,7 +325,7 @@ export declare type AssetMetadataType =
69
325
  | 'none'
70
326
 
71
327
  /** @internal */
72
- export declare class AssetsClient implements AssetsClientType {
328
+ export declare class AssetsClient {
73
329
  #private
74
330
  constructor(client: SanityClient, httpRequest: HttpRequest)
75
331
  /**
@@ -110,46 +366,6 @@ export declare class AssetsClient implements AssetsClientType {
110
366
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
111
367
  }
112
368
 
113
- /** @internal */
114
- declare interface AssetsClientType {
115
- /**
116
- * Uploads a file asset to the configured dataset
117
- *
118
- * @param assetType - Asset type (file)
119
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
120
- * @param options - Options to use for the upload
121
- */
122
- upload(
123
- assetType: 'file',
124
- body: UploadBody,
125
- options?: UploadClientConfig,
126
- ): Promise<SanityAssetDocument>
127
- /**
128
- * Uploads an image asset to the configured dataset
129
- *
130
- * @param assetType - Asset type (image)
131
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
132
- * @param options - Options to use for the upload
133
- */
134
- upload(
135
- assetType: 'image',
136
- body: UploadBody,
137
- options?: UploadClientConfig,
138
- ): Promise<SanityImageAssetDocument>
139
- /**
140
- * Uploads a file or an image asset to the configured dataset
141
- *
142
- * @param assetType - Asset type (file/image)
143
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
144
- * @param options - Options to use for the upload
145
- */
146
- upload(
147
- assetType: 'file' | 'image',
148
- body: UploadBody,
149
- options?: UploadClientConfig,
150
- ): Promise<SanityAssetDocument | SanityImageAssetDocument>
151
- }
152
-
153
369
  /** @internal */
154
370
  export declare type AttributeSet = {
155
371
  [key: string]: Any
@@ -515,6 +731,43 @@ export declare class ConnectionFailedError extends Error {
515
731
  readonly name = 'ConnectionFailedError'
516
732
  }
517
733
 
734
+ /**
735
+ * Include a string in the instruction: do not have to escape $ signs in the string.
736
+ *
737
+ * ```ts
738
+ * client.agent.action.generate({
739
+ * schemaId,
740
+ * documentId,
741
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
742
+ * instructionParams: {
743
+ * topic: {
744
+ * type: 'constant',
745
+ * value: 'Grapefruit'
746
+ * },
747
+ * },
748
+ * })
749
+ * ```
750
+ *
751
+ * `type: 'constant'` can also be provided directly as a string, as a shorthand:
752
+ *
753
+ * ```ts
754
+ * client.agent.action.generate({
755
+ * schemaId,
756
+ * documentId,
757
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
758
+ * instructionParams: {
759
+ * topic: 'Grapefruit'
760
+ * },
761
+ * })
762
+ * ```
763
+ *
764
+ * @beta
765
+ * */
766
+ export declare interface ConstantAgentActionParam {
767
+ type: 'constant'
768
+ value: string
769
+ }
770
+
518
771
  /** @public */
519
772
  export declare interface ContentSourceMap {
520
773
  mappings: ContentSourceMapMappings
@@ -752,7 +1005,7 @@ export declare type DatasetResponse = {
752
1005
  }
753
1006
 
754
1007
  /** @internal */
755
- export declare class DatasetsClient implements DatasetsClientType {
1008
+ export declare class DatasetsClient {
756
1009
  #private
757
1010
  constructor(client: SanityClient, httpRequest: HttpRequest)
758
1011
  /**
@@ -793,46 +1046,6 @@ export declare class DatasetsClient implements DatasetsClientType {
793
1046
  list(): Promise<DatasetsResponse>
794
1047
  }
795
1048
 
796
- /** @internal */
797
- declare interface DatasetsClientType {
798
- /**
799
- * Create a new dataset with the given name
800
- *
801
- * @param name - Name of the dataset to create
802
- * @param options - Options for the dataset
803
- */
804
- create(
805
- name: string,
806
- options?: {
807
- aclMode?: DatasetAclMode
808
- },
809
- ): Promise<DatasetResponse>
810
- /**
811
- * Edit a dataset with the given name
812
- *
813
- * @param name - Name of the dataset to edit
814
- * @param options - New options for the dataset
815
- */
816
- edit(
817
- name: string,
818
- options?: {
819
- aclMode?: DatasetAclMode
820
- },
821
- ): Promise<DatasetResponse>
822
- /**
823
- * Delete a dataset with the given name
824
- *
825
- * @param name - Name of the dataset to delete
826
- */
827
- delete(name: string): Promise<{
828
- deleted: true
829
- }>
830
- /**
831
- * Fetch a list of datasets for the configured project
832
- */
833
- list(): Promise<DatasetsResponse>
834
- }
835
-
836
1049
  /** @public */
837
1050
  export declare type DatasetsResponse = {
838
1051
  name: string
@@ -917,6 +1130,34 @@ export declare type DisconnectEvent = {
917
1130
  reason: string
918
1131
  }
919
1132
 
1133
+ /**
1134
+ *
1135
+ * Includes a LLM-friendly version of the document in the instruction
1136
+ *
1137
+ * ```ts
1138
+ * client.agent.action.generate({
1139
+ * schemaId,
1140
+ * documentId,
1141
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1142
+ * instructionParams: {
1143
+ * document: {
1144
+ * type: 'document',
1145
+ * },
1146
+ * },
1147
+ * target: {path: 'keywords' }
1148
+ * })
1149
+ * ```
1150
+ *
1151
+ * @beta
1152
+ * */
1153
+ export declare interface DocumentAgentActionParam {
1154
+ type: 'document'
1155
+ /**
1156
+ * If omitted, implicitly uses the documentId of the instruction target
1157
+ */
1158
+ documentId?: string
1159
+ }
1160
+
920
1161
  /**
921
1162
  * Modifies an existing draft document.
922
1163
  * It applies the given patch to the document referenced by draftId.
@@ -978,6 +1219,41 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
978
1219
  */
979
1220
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
980
1221
 
1222
+ /**
1223
+ *
1224
+ *
1225
+ * Includes a LLM-friendly version of the field value in the instruction
1226
+ *
1227
+ * ```ts
1228
+ * client.agent.action.generate({
1229
+ * schemaId,
1230
+ * documentId,
1231
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1232
+ * instructionParams: {
1233
+ * pte: {
1234
+ * type: 'field',
1235
+ * path: ['pteField'],
1236
+ * },
1237
+ * },
1238
+ * target: {path: 'keywords' }
1239
+ * })
1240
+ *
1241
+ * ```
1242
+ *
1243
+ * @beta
1244
+ * */
1245
+ export declare interface FieldAgentActionParam {
1246
+ type: 'field'
1247
+ /**
1248
+ * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1249
+ */
1250
+ path: AgentActionPathSegment | AgentActionPath
1251
+ /**
1252
+ * If omitted, implicitly uses the documentId of the instruction target
1253
+ */
1254
+ documentId?: string
1255
+ }
1256
+
981
1257
  /** @public */
982
1258
  export declare type FilterDefault = (props: {
983
1259
  /**
@@ -1093,6 +1369,274 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1093
1369
  returnDocuments?: true
1094
1370
  }
1095
1371
 
1372
+ /** @beta */
1373
+ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1374
+ | GenerateExistingDocumentRequest
1375
+ | GenerateTargetDocumentRequest<T>
1376
+ ) &
1377
+ GenerateRequestBase &
1378
+ AgentActionAsync
1379
+
1380
+ /**
1381
+ * Instruction for an existing document.
1382
+ * @beta
1383
+ */
1384
+ declare interface GenerateExistingDocumentRequest {
1385
+ documentId: string
1386
+ createDocument?: never
1387
+ }
1388
+
1389
+ /** @beta */
1390
+ export declare type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> =
1391
+ | GenerateSyncInstruction<T>
1392
+ | GenerateAsyncInstruction<T>
1393
+
1394
+ /** @beta */
1395
+ export declare type GenerateOperation = 'set' | 'append' | 'mixed'
1396
+
1397
+ /** @beta */
1398
+ declare interface GenerateRequestBase extends AgentActionRequestBase {
1399
+ /** schemaId as reported by sanity deploy / sanity schema store */
1400
+ schemaId: string
1401
+ /**
1402
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
1403
+ *
1404
+ * The LLM only has access to information in the instruction, plus the target schema.
1405
+ *
1406
+ * string template using $variable
1407
+ * */
1408
+ instruction: string
1409
+ /**
1410
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
1411
+ *
1412
+ * ### Examples
1413
+ *
1414
+ * #### Constant
1415
+ *
1416
+ * ##### Shorthand
1417
+ * ```ts
1418
+ * client.agent.action.generate({
1419
+ * schemaId,
1420
+ * documentId,
1421
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1422
+ * instructionParams: {
1423
+ * topic: 'Grapefruit'
1424
+ * },
1425
+ * })
1426
+ * ```
1427
+ * ##### Object-form
1428
+ *
1429
+ * ```ts
1430
+ * client.agent.action.generate({
1431
+ * schemaId,
1432
+ * documentId,
1433
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1434
+ * instructionParams: {
1435
+ * topic: {
1436
+ * type: 'constant',
1437
+ * value: 'Grapefruit'
1438
+ * },
1439
+ * },
1440
+ * })
1441
+ * ```
1442
+ * #### Field
1443
+ * ```ts
1444
+ * client.agent.action.generate({
1445
+ * schemaId,
1446
+ * documentId,
1447
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1448
+ * instructionParams: {
1449
+ * pte: {
1450
+ * type: 'field',
1451
+ * path: ['pteField'],
1452
+ * },
1453
+ * },
1454
+ * target: {path: 'keywords' }
1455
+ * })
1456
+ * ```
1457
+ * #### Document
1458
+ * ```ts
1459
+ * client.agent.action.generate({
1460
+ * schemaId,
1461
+ * documentId,
1462
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1463
+ * instructionParams: {
1464
+ * document: {
1465
+ * type: 'document',
1466
+ * },
1467
+ * },
1468
+ * target: {path: 'keywords' }
1469
+ * })
1470
+ * ```
1471
+ *
1472
+ * #### GROQ
1473
+ * ```ts
1474
+ * client.agent.action.generate({
1475
+ * schemaId,
1476
+ * documentId,
1477
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1478
+ * instructionParams: {
1479
+ * list: {
1480
+ * type: 'groq',
1481
+ * query: '* [_type==$type].title',
1482
+ * params: {type: 'article'}
1483
+ * },
1484
+ * },
1485
+ * target: {path: 'title' }
1486
+ * })
1487
+ * ```
1488
+ * */
1489
+ instructionParams?: AgentActionParams
1490
+ /**
1491
+ * Target defines which parts of the document will be affected by the instruction.
1492
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
1493
+ *
1494
+ * Omitting target implies that the document itself is the root.
1495
+ *
1496
+ * Notes:
1497
+ * - instruction can only affect fields up to `maxPathDepth`
1498
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1499
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1500
+ *
1501
+ * @see AgentActionRequestBase#conditionalPaths
1502
+ */
1503
+ target?: GenerateTarget | GenerateTarget[]
1504
+ }
1505
+
1506
+ /** @beta */
1507
+ declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1508
+ | GenerateExistingDocumentRequest
1509
+ | GenerateTargetDocumentRequest<T>
1510
+ ) &
1511
+ GenerateRequestBase &
1512
+ AgentActionSync
1513
+
1514
+ /** @beta */
1515
+ export declare interface GenerateTarget extends AgentActionTarget {
1516
+ /**
1517
+ * Sets the default operation for all paths in the target.
1518
+ * Generate runs in `'mixed'` operation mode by default:
1519
+ * Changes are set in all non-array fields, and append to all array fields.
1520
+ *
1521
+ * ### Operation types
1522
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1523
+ * - `'append'`:
1524
+ * – array fields: appends new items to the end of the array,
1525
+ * - string fields: '"existing content" "new content"'
1526
+ * - text fields: '"existing content"\\n"new content"'
1527
+ * - number fields: existing + new
1528
+ * - other field types not mentioned will set instead (dates, url)
1529
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1530
+ *
1531
+ * The default operation can be overridden on a per-path basis using `include`.
1532
+ *
1533
+ * Nested fields inherit the operation specified by their parent and falls back to the
1534
+ * top level target operation if not otherwise specified.
1535
+ *
1536
+ * Use `include` to change the `operation` of individual fields or items.
1537
+ *
1538
+ * #### Appending in the middle of arrays
1539
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1540
+ *
1541
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1542
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1543
+ *
1544
+ * @see #AgentActionTargetInclude.operation
1545
+ * @see #include
1546
+ * @see #AgentActionTargetInclude.include
1547
+ */
1548
+ operation?: GenerateOperation
1549
+ /**
1550
+ * By default, all children up to `target.maxPathDepth` are included.
1551
+ *
1552
+ * When `include` is specified, only segments explicitly listed will be included.
1553
+ *
1554
+ * Fields or array items not on the include list, are implicitly excluded.
1555
+ */
1556
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1557
+ }
1558
+
1559
+ /** @beta */
1560
+ export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1561
+ | {
1562
+ operation: 'edit'
1563
+ _id: string
1564
+ }
1565
+ | {
1566
+ operation: 'create'
1567
+ _id?: string
1568
+ _type: string
1569
+ initialValues?: T
1570
+ }
1571
+ | {
1572
+ operation: 'createIfNotExists'
1573
+ _id: string
1574
+ _type: string
1575
+ initialValues?: T
1576
+ }
1577
+ | {
1578
+ operation: 'createOrReplace'
1579
+ _id: string
1580
+ _type: string
1581
+ initialValues?: T
1582
+ }
1583
+
1584
+ /**
1585
+ * Instruction to create a new document
1586
+ * @beta
1587
+ */
1588
+ declare interface GenerateTargetDocumentRequest<
1589
+ T extends Record<string, Any> = Record<string, Any>,
1590
+ > {
1591
+ targetDocument: GenerateTargetDocument<T>
1592
+ documentId?: never
1593
+ }
1594
+
1595
+ /** @beta */
1596
+ export declare interface GenerateTargetInclude extends AgentActionTargetInclude {
1597
+ /**
1598
+ * Sets the operation for this path, and all its children.
1599
+ * This overrides any operation set parents or the root target.
1600
+ * @see #GenerateTarget.operation
1601
+ * @see #include
1602
+ */
1603
+ operation?: GenerateOperation
1604
+ /**
1605
+ * By default, all children up to `target.maxPathDepth` are included.
1606
+ *
1607
+ * When `include` is specified, only segments explicitly listed will be included.
1608
+ *
1609
+ * Fields or array items not on the include list, are implicitly excluded.
1610
+ */
1611
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1612
+ }
1613
+
1614
+ /**
1615
+ * Includes a LLM-friendly version of GROQ query result in the instruction
1616
+ *
1617
+ * ```ts
1618
+ * client.agent.action.generate({
1619
+ * schemaId,
1620
+ * documentId,
1621
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1622
+ * instructionParams: {
1623
+ * list: {
1624
+ * type: 'groq',
1625
+ * query: '* [_type==$type].title',
1626
+ * params: {type: 'article'}
1627
+ * },
1628
+ * },
1629
+ * target: {path: 'title' }
1630
+ * })
1631
+ * ```
1632
+ * @beta
1633
+ * */
1634
+ export declare interface GroqAgentActionParam {
1635
+ type: 'groq'
1636
+ query: string
1637
+ params?: Record<string, string>
1638
+ }
1639
+
1096
1640
  /** @public */
1097
1641
  export declare type HttpRequest = {
1098
1642
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1232,15 +1776,6 @@ export declare interface ListenOptions {
1232
1776
  * @defaultValue `false`
1233
1777
  */
1234
1778
  includePreviousRevision?: boolean
1235
- /**
1236
- * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
1237
- * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
1238
- * If you need events from drafts and versions, set this to `true`.
1239
- * Note: Keep in mind that additional document variants may be introduced in the future, so it's
1240
- * recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
1241
- * explicitly checking whether the event is for a draft or a version.
1242
- * @defaultValue `false`
1243
- */
1244
1779
  includeAllVersions?: boolean
1245
1780
  /**
1246
1781
  * Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
@@ -1542,8 +2077,53 @@ export declare type MutationSelectionQueryParams = {
1542
2077
  [key: string]: Any
1543
2078
  }
1544
2079
 
2080
+ /** @public */
2081
+ declare class ObservableAgentsActionClient {
2082
+ #private
2083
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2084
+ /**
2085
+ * Run an instruction to generate content in a target document.
2086
+ * @param request - instruction request
2087
+ */
2088
+ generate<DocumentShape extends Record<string, Any>>(
2089
+ request: GenerateInstruction<DocumentShape>,
2090
+ ): Observable<
2091
+ (typeof request)['async'] extends true
2092
+ ? {
2093
+ _id: string
2094
+ }
2095
+ : IdentifiedSanityDocumentStub & DocumentShape
2096
+ >
2097
+ /**
2098
+ * Transform a target document based on a source.
2099
+ * @param request - translation request
2100
+ */
2101
+ transform<DocumentShape extends Record<string, Any>>(
2102
+ request: TransformDocument<DocumentShape>,
2103
+ ): Observable<
2104
+ (typeof request)['async'] extends true
2105
+ ? {
2106
+ _id: string
2107
+ }
2108
+ : IdentifiedSanityDocumentStub & DocumentShape
2109
+ >
2110
+ /**
2111
+ * Translate a target document based on a source.
2112
+ * @param request - translation request
2113
+ */
2114
+ translate<DocumentShape extends Record<string, Any>>(
2115
+ request: TranslateDocument<DocumentShape>,
2116
+ ): Observable<
2117
+ (typeof request)['async'] extends true
2118
+ ? {
2119
+ _id: string
2120
+ }
2121
+ : IdentifiedSanityDocumentStub & DocumentShape
2122
+ >
2123
+ }
2124
+
1545
2125
  /** @internal */
1546
- export declare class ObservableAssetsClient implements ObservableAssetsClientType {
2126
+ export declare class ObservableAssetsClient {
1547
2127
  #private
1548
2128
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1549
2129
  /**
@@ -1597,103 +2177,11 @@ export declare class ObservableAssetsClient implements ObservableAssetsClientTyp
1597
2177
  }
1598
2178
 
1599
2179
  /** @internal */
1600
- declare interface ObservableAssetsClientType {
2180
+ export declare class ObservableDatasetsClient {
2181
+ #private
2182
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1601
2183
  /**
1602
- * Uploads a file asset to the configured dataset
1603
- *
1604
- * @param assetType - Asset type (file)
1605
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1606
- * @param options - Options to use for the upload
1607
- */
1608
- upload(
1609
- assetType: 'file',
1610
- body: UploadBody,
1611
- options?: UploadClientConfig,
1612
- ): Observable<
1613
- HttpRequestEvent<{
1614
- document: SanityAssetDocument
1615
- }>
1616
- >
1617
- /**
1618
- * Uploads an image asset to the configured dataset
1619
- *
1620
- * @param assetType - Asset type (image)
1621
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1622
- * @param options - Options to use for the upload
1623
- */
1624
- upload(
1625
- assetType: 'image',
1626
- body: UploadBody,
1627
- options?: UploadClientConfig,
1628
- ): Observable<
1629
- HttpRequestEvent<{
1630
- document: SanityImageAssetDocument
1631
- }>
1632
- >
1633
- /**
1634
- * Uploads a file or an image asset to the configured dataset
1635
- *
1636
- * @param assetType - Asset type (file/image)
1637
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1638
- * @param options - Options to use for the upload
1639
- */
1640
- upload(
1641
- assetType: 'file' | 'image',
1642
- body: UploadBody,
1643
- options?: UploadClientConfig,
1644
- ): Observable<
1645
- HttpRequestEvent<{
1646
- document: SanityAssetDocument | SanityImageAssetDocument
1647
- }>
1648
- >
1649
- }
1650
-
1651
- /** @internal */
1652
- export declare class ObservableDatasetsClient implements ObservableDatasetsClientType {
1653
- #private
1654
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1655
- /**
1656
- * Create a new dataset with the given name
1657
- *
1658
- * @param name - Name of the dataset to create
1659
- * @param options - Options for the dataset
1660
- */
1661
- create(
1662
- name: string,
1663
- options?: {
1664
- aclMode?: DatasetAclMode
1665
- },
1666
- ): Observable<DatasetResponse>
1667
- /**
1668
- * Edit a dataset with the given name
1669
- *
1670
- * @param name - Name of the dataset to edit
1671
- * @param options - New options for the dataset
1672
- */
1673
- edit(
1674
- name: string,
1675
- options?: {
1676
- aclMode?: DatasetAclMode
1677
- },
1678
- ): Observable<DatasetResponse>
1679
- /**
1680
- * Delete a dataset with the given name
1681
- *
1682
- * @param name - Name of the dataset to delete
1683
- */
1684
- delete(name: string): Observable<{
1685
- deleted: true
1686
- }>
1687
- /**
1688
- * Fetch a list of datasets for the configured project
1689
- */
1690
- list(): Observable<DatasetsResponse>
1691
- }
1692
-
1693
- /** @internal */
1694
- declare interface ObservableDatasetsClientType {
1695
- /**
1696
- * Create a new dataset with the given name
2184
+ * Create a new dataset with the given name
1697
2185
  *
1698
2186
  * @param name - Name of the dataset to create
1699
2187
  * @param options - Options for the dataset
@@ -1784,38 +2272,17 @@ export declare class ObservablePatch extends BasePatch {
1784
2272
  export declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
1785
2273
 
1786
2274
  /** @internal */
1787
- export declare class ObservableProjectsClient implements ObservableProjectsClientType {
2275
+ export declare class ObservableProjectsClient {
1788
2276
  #private
1789
2277
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1790
2278
  /**
1791
2279
  * Fetch a list of projects the authenticated user has access to.
1792
2280
  *
1793
2281
  * @param options - Options for the list request
1794
- * @param options.includeMembers - Whether to include members in the response (default: true)
1795
- */
1796
- list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1797
- list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
1798
- /**
1799
- * Fetch a project by project ID
1800
- *
1801
- * @param projectId - ID of the project to fetch
1802
- */
1803
- getById(projectId: string): Observable<SanityProject>
1804
- }
1805
-
1806
- /** @internal */
1807
- declare interface ObservableProjectsClientType {
1808
- /**
1809
- * Fetch a list of projects the authenticated user has access to.
1810
- *
1811
- * @param options - Options for the list request
1812
- * @param options.includeMembers - Whether to include members in the response (default: true)
2282
+ * - `includeMembers` - Whether to include members in the response (default: true)
1813
2283
  */
1814
2284
  list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1815
2285
  list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
1816
- list(options?: {
1817
- includeMembers?: boolean
1818
- }): Observable<SanityProject[] | Omit<SanityProject, 'members'>[]>
1819
2286
  /**
1820
2287
  * Fetch a project by project ID
1821
2288
  *
@@ -1825,13 +2292,19 @@ declare interface ObservableProjectsClientType {
1825
2292
  }
1826
2293
 
1827
2294
  /** @public */
1828
- export declare class ObservableSanityClient implements ObservableSanityClientType {
2295
+ export declare class ObservableSanityClient {
1829
2296
  #private
1830
2297
  assets: ObservableAssetsClient
1831
2298
  datasets: ObservableDatasetsClient
1832
2299
  live: LiveClient
1833
2300
  projects: ObservableProjectsClient
1834
2301
  users: ObservableUsersClient
2302
+ agent: {
2303
+ action: ObservableAgentsActionClient
2304
+ }
2305
+ /**
2306
+ * Instance properties
2307
+ */
1835
2308
  listen: typeof _listen
1836
2309
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1837
2310
  /**
@@ -1890,7 +2363,7 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
1890
2363
  Q extends QueryWithoutParams | QueryParams = QueryParams,
1891
2364
  const G extends string = string,
1892
2365
  >(
1893
- query: G,
2366
+ query: string,
1894
2367
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1895
2368
  options: UnfilteredResponseQueryOptions,
1896
2369
  ): Observable<RawQueryResponse<ClientReturn<G, R>>>
@@ -2326,1527 +2799,456 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
2326
2799
  }
2327
2800
 
2328
2801
  /**
2329
- * The interface implemented by the `ObservableSanityClient` class.
2330
- * When writing code that wants to take an instance of `ObservableSanityClient` as input it's better to use this type,
2331
- * as the `ObservableSanityClient` class has private properties and thus TypeScrict will consider the type incompatible
2332
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
2802
+ * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead
2333
2803
  * @public
2334
2804
  */
2335
- export declare interface ObservableSanityClientType extends SanityClientBase {
2336
- assets: ObservableAssetsClientType
2337
- datasets: ObservableDatasetsClientType
2338
- projects: ObservableProjectsClientType
2339
- users: ObservableUsersClientType
2805
+ export declare class ObservableSanityStegaClient extends ObservableSanityClient {}
2806
+
2807
+ /** @public */
2808
+ export declare class ObservableTransaction extends BaseTransaction {
2809
+ #private
2810
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2340
2811
  /**
2341
- * Clone the client - returns a new instance
2812
+ * Clones the transaction
2342
2813
  */
2343
- clone(): ObservableSanityClientType
2814
+ clone(): ObservableTransaction
2344
2815
  /**
2345
- * Returns the current client configuration
2816
+ * Commit the transaction, returning an observable that produces the first mutated document
2817
+ *
2818
+ * @param options - Options for the mutation operation
2346
2819
  */
2347
- config(): InitializedClientConfig
2820
+ commit<R extends Record<string, Any>>(
2821
+ options: TransactionFirstDocumentMutationOptions,
2822
+ ): Observable<SanityDocument<R>>
2348
2823
  /**
2349
- * Reconfigure the client. Note that this _mutates_ the current client.
2824
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
2825
+ *
2826
+ * @param options - Options for the mutation operation
2350
2827
  */
2351
- config(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2828
+ commit<R extends Record<string, Any>>(
2829
+ options: TransactionAllDocumentsMutationOptions,
2830
+ ): Observable<SanityDocument<R>[]>
2352
2831
  /**
2353
- * Clone the client with a new (partial) configuration.
2832
+ * Commit the transaction, returning an observable that produces a mutation result object
2354
2833
  *
2355
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
2834
+ * @param options - Options for the mutation operation
2356
2835
  */
2357
- withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2836
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2358
2837
  /**
2359
- * Perform a GROQ-query against the configured dataset.
2838
+ * Commit the transaction, returning an observable that produces a mutation result object
2360
2839
  *
2361
- * @param query - GROQ-query to perform
2840
+ * @param options - Options for the mutation operation
2362
2841
  */
2363
- fetch<
2364
- R = Any,
2365
- Q extends QueryWithoutParams = QueryWithoutParams,
2366
- const G extends string = string,
2367
- >(
2368
- query: G,
2369
- params?: Q | QueryWithoutParams,
2370
- ): Observable<ClientReturn<G, R>>
2842
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2371
2843
  /**
2372
- * Perform a GROQ-query against the configured dataset.
2844
+ * Commit the transaction, returning an observable that produces a mutation result object
2373
2845
  *
2374
- * @param query - GROQ-query to perform
2375
- * @param params - Optional query parameters
2376
- * @param options - Optional request options
2846
+ * @param options - Options for the mutation operation
2377
2847
  */
2378
- fetch<
2379
- R = Any,
2380
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2381
- const G extends string = string,
2382
- >(
2383
- query: G,
2384
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2385
- options?: FilteredResponseQueryOptions,
2386
- ): Observable<ClientReturn<G, R>>
2848
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2387
2849
  /**
2388
- * Perform a GROQ-query against the configured dataset.
2850
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2851
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2389
2852
  *
2390
- * @param query - GROQ-query to perform
2391
- * @param params - Optional query parameters
2392
- * @param options - Request options
2853
+ * @param documentId - Document ID to perform the patch operation on
2854
+ * @param patchOps - Operations to perform, or a builder function
2393
2855
  */
2394
- fetch<
2395
- R = Any,
2396
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2397
- const G extends string = string,
2398
- >(
2399
- query: G,
2400
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2401
- options: UnfilteredResponseQueryOptions,
2402
- ): Observable<RawQueryResponse<ClientReturn<G, R>>>
2856
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2403
2857
  /**
2404
- * Perform a GROQ-query against the configured dataset.
2858
+ * Adds the given patch instance to the transaction.
2859
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2405
2860
  *
2406
- * @param query - GROQ-query to perform
2407
- * @param params - Optional query parameters
2408
- * @param options - Request options
2861
+ * @param patch - ObservablePatch to execute
2409
2862
  */
2410
- fetch<
2411
- R = Any,
2412
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2413
- const G extends string = string,
2414
- >(
2415
- query: G,
2416
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2417
- options: UnfilteredResponseWithoutQuery,
2418
- ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2863
+ patch(patch: ObservablePatch): this
2864
+ }
2865
+
2866
+ /** @public */
2867
+ export declare class ObservableUsersClient {
2868
+ #private
2869
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2419
2870
  /**
2420
- * Fetch a single document with the given ID.
2871
+ * Fetch a user by user ID
2421
2872
  *
2422
- * @param id - Document ID to fetch
2423
- * @param options - Request options
2873
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2424
2874
  */
2425
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
2426
- id: string,
2427
- options?: {
2428
- tag?: string
2429
- },
2430
- ): Observable<SanityDocument<R> | undefined>
2875
+ getById<T extends 'me' | string>(
2876
+ id: T,
2877
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2878
+ }
2879
+
2880
+ /**
2881
+ * The listener connection has been established
2882
+ * note: it's usually a better option to use the 'welcome' event
2883
+ * @public
2884
+ */
2885
+ export declare type OpenEvent = {
2886
+ type: 'open'
2887
+ }
2888
+
2889
+ /** @public */
2890
+ export declare class Patch extends BasePatch {
2891
+ #private
2892
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2431
2893
  /**
2432
- * Fetch multiple documents in one request.
2433
- * Should be used sparingly - performing a query is usually a better option.
2434
- * The order/position of documents is preserved based on the original array of IDs.
2435
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2436
- *
2437
- * @param ids - Document IDs to fetch
2438
- * @param options - Request options
2894
+ * Clones the patch
2439
2895
  */
2440
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2441
- ids: string[],
2442
- options?: {
2443
- tag?: string
2444
- },
2445
- ): Observable<(SanityDocument<R> | null)[]>
2896
+ clone(): Patch
2446
2897
  /**
2447
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2448
- * Returns an observable that resolves to the created document.
2449
- *
2450
- * @param document - Document to create
2451
- * @param options - Mutation options
2452
- */
2453
- create<R extends Record<string, Any> = Record<string, Any>>(
2454
- document: SanityDocumentStub<R>,
2455
- options: FirstDocumentMutationOptions,
2456
- ): Observable<SanityDocument<R>>
2457
- /**
2458
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2459
- * Returns an observable that resolves to an array containing the created document.
2460
- *
2461
- * @param document - Document to create
2462
- * @param options - Mutation options
2463
- */
2464
- create<R extends Record<string, Any> = Record<string, Any>>(
2465
- document: SanityDocumentStub<R>,
2466
- options: AllDocumentsMutationOptions,
2467
- ): Observable<SanityDocument<R>[]>
2468
- /**
2469
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2470
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2471
- *
2472
- * @param document - Document to create
2473
- * @param options - Mutation options
2474
- */
2475
- create<R extends Record<string, Any> = Record<string, Any>>(
2476
- document: SanityDocumentStub<R>,
2477
- options: FirstDocumentIdMutationOptions,
2478
- ): Observable<SingleMutationResult>
2479
- /**
2480
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2481
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2482
- *
2483
- * @param document - Document to create
2484
- * @param options - Mutation options
2485
- */
2486
- create<R extends Record<string, Any> = Record<string, Any>>(
2487
- document: SanityDocumentStub<R>,
2488
- options: AllDocumentIdsMutationOptions,
2489
- ): Observable<MultipleMutationResult>
2490
- /**
2491
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2492
- * Returns an observable that resolves to the created document.
2493
- *
2494
- * @param document - Document to create
2495
- * @param options - Mutation options
2496
- */
2497
- create<R extends Record<string, Any> = Record<string, Any>>(
2498
- document: SanityDocumentStub<R>,
2499
- options?: BaseMutationOptions,
2500
- ): Observable<SanityDocument<R>>
2501
- /**
2502
- * Create a document if no document with the same ID already exists.
2503
- * Returns an observable that resolves to the created document.
2504
- *
2505
- * @param document - Document to create
2506
- * @param options - Mutation options
2507
- */
2508
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2509
- document: IdentifiedSanityDocumentStub<R>,
2510
- options: FirstDocumentMutationOptions,
2511
- ): Observable<SanityDocument<R>>
2512
- /**
2513
- * Create a document if no document with the same ID already exists.
2514
- * Returns an observable that resolves to an array containing the created document.
2515
- *
2516
- * @param document - Document to create
2517
- * @param options - Mutation options
2518
- */
2519
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2520
- document: IdentifiedSanityDocumentStub<R>,
2521
- options: AllDocumentsMutationOptions,
2522
- ): Observable<SanityDocument<R>[]>
2523
- /**
2524
- * Create a document if no document with the same ID already exists.
2525
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2526
- *
2527
- * @param document - Document to create
2528
- * @param options - Mutation options
2529
- */
2530
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2531
- document: IdentifiedSanityDocumentStub<R>,
2532
- options: FirstDocumentIdMutationOptions,
2533
- ): Observable<SingleMutationResult>
2534
- /**
2535
- * Create a document if no document with the same ID already exists.
2536
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2537
- *
2538
- * @param document - Document to create
2539
- * @param options - Mutation options
2540
- */
2541
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2542
- document: IdentifiedSanityDocumentStub<R>,
2543
- options: AllDocumentIdsMutationOptions,
2544
- ): Observable<MultipleMutationResult>
2545
- /**
2546
- * Create a document if no document with the same ID already exists.
2547
- * Returns an observable that resolves to the created document.
2548
- *
2549
- * @param document - Document to create
2550
- * @param options - Mutation options
2551
- */
2552
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2553
- document: IdentifiedSanityDocumentStub<R>,
2554
- options?: BaseMutationOptions,
2555
- ): Observable<SanityDocument<R>>
2556
- /**
2557
- * Create a document if it does not exist, or replace a document with the same document ID
2558
- * Returns an observable that resolves to the created document.
2559
- *
2560
- * @param document - Document to either create or replace
2561
- * @param options - Mutation options
2562
- */
2563
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2564
- document: IdentifiedSanityDocumentStub<R>,
2565
- options: FirstDocumentMutationOptions,
2566
- ): Observable<SanityDocument<R>>
2567
- /**
2568
- * Create a document if it does not exist, or replace a document with the same document ID
2569
- * Returns an observable that resolves to an array containing the created document.
2570
- *
2571
- * @param document - Document to either create or replace
2572
- * @param options - Mutation options
2573
- */
2574
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2575
- document: IdentifiedSanityDocumentStub<R>,
2576
- options: AllDocumentsMutationOptions,
2577
- ): Observable<SanityDocument<R>[]>
2578
- /**
2579
- * Create a document if it does not exist, or replace a document with the same document ID
2580
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2581
- *
2582
- * @param document - Document to either create or replace
2583
- * @param options - Mutation options
2584
- */
2585
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2586
- document: IdentifiedSanityDocumentStub<R>,
2587
- options: FirstDocumentIdMutationOptions,
2588
- ): Observable<SingleMutationResult>
2589
- /**
2590
- * Create a document if it does not exist, or replace a document with the same document ID
2591
- * Returns an observable that resolves to a mutation result object containing the created document ID.
2592
- *
2593
- * @param document - Document to either create or replace
2594
- * @param options - Mutation options
2595
- */
2596
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2597
- document: IdentifiedSanityDocumentStub<R>,
2598
- options: AllDocumentIdsMutationOptions,
2599
- ): Observable<MultipleMutationResult>
2600
- /**
2601
- * Create a document if it does not exist, or replace a document with the same document ID
2602
- * Returns an observable that resolves to the created document.
2603
- *
2604
- * @param document - Document to either create or replace
2605
- * @param options - Mutation options
2606
- */
2607
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2608
- document: IdentifiedSanityDocumentStub<R>,
2609
- options?: BaseMutationOptions,
2610
- ): Observable<SanityDocument<R>>
2611
- /**
2612
- * Deletes a document with the given document ID.
2613
- * Returns an observable that resolves to the deleted document.
2614
- *
2615
- * @param id - Document ID to delete
2616
- * @param options - Options for the mutation
2617
- */
2618
- delete<R extends Record<string, Any> = Record<string, Any>>(
2619
- id: string,
2620
- options: FirstDocumentMutationOptions,
2621
- ): Observable<SanityDocument<R>>
2622
- /**
2623
- * Deletes a document with the given document ID.
2624
- * Returns an observable that resolves to an array containing the deleted document.
2625
- *
2626
- * @param id - Document ID to delete
2627
- * @param options - Options for the mutation
2628
- */
2629
- delete<R extends Record<string, Any> = Record<string, Any>>(
2630
- id: string,
2631
- options: AllDocumentsMutationOptions,
2632
- ): Observable<SanityDocument<R>[]>
2633
- /**
2634
- * Deletes a document with the given document ID.
2635
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2636
- *
2637
- * @param id - Document ID to delete
2638
- * @param options - Options for the mutation
2639
- */
2640
- delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2641
- /**
2642
- * Deletes a document with the given document ID.
2643
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2644
- *
2645
- * @param id - Document ID to delete
2646
- * @param options - Options for the mutation
2647
- */
2648
- delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2649
- /**
2650
- * Deletes a document with the given document ID.
2651
- * Returns an observable that resolves to the deleted document.
2652
- *
2653
- * @param id - Document ID to delete
2654
- * @param options - Options for the mutation
2655
- */
2656
- delete<R extends Record<string, Any> = Record<string, Any>>(
2657
- id: string,
2658
- options?: BaseMutationOptions,
2659
- ): Observable<SanityDocument<R>>
2660
- /**
2661
- * Deletes one or more documents matching the given query or document ID.
2662
- * Returns an observable that resolves to first deleted document.
2663
- *
2664
- * @param selection - An object with either an `id` or `query` key defining what to delete
2665
- * @param options - Options for the mutation
2666
- */
2667
- delete<R extends Record<string, Any> = Record<string, Any>>(
2668
- selection: MutationSelection,
2669
- options: FirstDocumentMutationOptions,
2670
- ): Observable<SanityDocument<R>>
2671
- /**
2672
- * Deletes one or more documents matching the given query or document ID.
2673
- * Returns an observable that resolves to an array containing the deleted documents.
2674
- *
2675
- * @param selection - An object with either an `id` or `query` key defining what to delete
2676
- * @param options - Options for the mutation
2677
- */
2678
- delete<R extends Record<string, Any> = Record<string, Any>>(
2679
- selection: MutationSelection,
2680
- options: AllDocumentsMutationOptions,
2681
- ): Observable<SanityDocument<R>[]>
2682
- /**
2683
- * Deletes one or more documents matching the given query or document ID.
2684
- * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
2685
- *
2686
- * @param selection - An object with either an `id` or `query` key defining what to delete
2687
- * @param options - Options for the mutation
2688
- */
2689
- delete(
2690
- selection: MutationSelection,
2691
- options: FirstDocumentIdMutationOptions,
2692
- ): Observable<SingleMutationResult>
2693
- /**
2694
- * Deletes one or more documents matching the given query or document ID.
2695
- * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
2696
- *
2697
- * @param selection - An object with either an `id` or `query` key defining what to delete
2698
- * @param options - Options for the mutation
2699
- */
2700
- delete(
2701
- selection: MutationSelection,
2702
- options: AllDocumentIdsMutationOptions,
2703
- ): Observable<MultipleMutationResult>
2704
- /**
2705
- * Deletes one or more documents matching the given query or document ID.
2706
- * Returns an observable that resolves to first deleted document.
2707
- *
2708
- * @param selection - An object with either an `id` or `query` key defining what to delete
2709
- * @param options - Options for the mutation
2710
- */
2711
- delete<R extends Record<string, Any> = Record<string, Any>>(
2712
- selection: MutationSelection,
2713
- options?: BaseMutationOptions,
2714
- ): Observable<SanityDocument<R>>
2715
- /**
2716
- * Perform mutation operations against the configured dataset
2717
- * Returns an observable that resolves to the first mutated document.
2718
- *
2719
- * @param operations - Mutation operations to execute
2720
- * @param options - Mutation options
2721
- */
2722
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2723
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2724
- options: FirstDocumentMutationOptions,
2725
- ): Observable<SanityDocument<R>>
2726
- /**
2727
- * Perform mutation operations against the configured dataset.
2728
- * Returns an observable that resolves to an array of the mutated documents.
2729
- *
2730
- * @param operations - Mutation operations to execute
2731
- * @param options - Mutation options
2732
- */
2733
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2734
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2735
- options: AllDocumentsMutationOptions,
2736
- ): Observable<SanityDocument<R>[]>
2737
- /**
2738
- * Perform mutation operations against the configured dataset
2739
- * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
2740
- *
2741
- * @param operations - Mutation operations to execute
2742
- * @param options - Mutation options
2743
- */
2744
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2745
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2746
- options: FirstDocumentIdMutationOptions,
2747
- ): Observable<SingleMutationResult>
2748
- /**
2749
- * Perform mutation operations against the configured dataset
2750
- * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
2751
- *
2752
- * @param operations - Mutation operations to execute
2753
- * @param options - Mutation options
2754
- */
2755
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2756
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2757
- options: AllDocumentIdsMutationOptions,
2758
- ): Observable<MultipleMutationResult>
2759
- /**
2760
- * Perform mutation operations against the configured dataset
2761
- * Returns an observable that resolves to the first mutated document.
2762
- *
2763
- * @param operations - Mutation operations to execute
2764
- * @param options - Mutation options
2765
- */
2766
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2767
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2768
- options?: BaseMutationOptions,
2769
- ): Observable<SanityDocument<R>>
2770
- /**
2771
- * Create a new buildable patch of operations to perform
2772
- *
2773
- * @param documentId - Document ID to patch
2774
- * @param operations - Optional object of patch operations to initialize the patch instance with
2775
- * @returns Patch instance - call `.commit()` to perform the operations defined
2776
- */
2777
- patch(documentId: string, operations?: PatchOperations): ObservablePatch
2778
- /**
2779
- * Create a new buildable patch of operations to perform
2780
- *
2781
- * @param documentIds - Array of document IDs to patch
2782
- * @param operations - Optional object of patch operations to initialize the patch instance with
2783
- * @returns Patch instance - call `.commit()` to perform the operations defined
2784
- */
2785
- patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
2786
- /**
2787
- * Create a new buildable patch of operations to perform
2788
- *
2789
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2790
- * @param operations - Optional object of patch operations to initialize the patch instance with
2791
- * @returns Patch instance - call `.commit()` to perform the operations defined
2792
- */
2793
- patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
2794
- /**
2795
- * Create a new buildable patch of operations to perform
2796
- *
2797
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
2798
- * @param operations - Optional object of patch operations to initialize the patch instance with
2799
- * @returns Patch instance - call `.commit()` to perform the operations defined
2800
- */
2801
- patch(selection: PatchSelection, operations?: PatchOperations): ObservablePatch
2802
- /**
2803
- * Create a new transaction of mutations
2804
- *
2805
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2806
- */
2807
- transaction<R extends Record<string, Any> = Record<string, Any>>(
2808
- operations?: Mutation<R>[],
2809
- ): ObservableTransaction
2810
- /**
2811
- * Perform action operations against the configured dataset
2812
- *
2813
- * @param operations - Action operation(s) to execute
2814
- * @param options - Action options
2815
- */
2816
- action(
2817
- operations: Action | Action[],
2818
- options?: BaseActionOptions,
2819
- ): Observable<SingleActionResult | MultipleActionResult>
2820
- /**
2821
- * Perform an HTTP request against the Sanity API
2822
- *
2823
- * @param options - Request options
2824
- */
2825
- request<R = Any>(options: RawRequestOptions): Observable<R>
2826
- }
2827
-
2828
- /**
2829
- * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead
2830
- * @public
2831
- */
2832
- export declare class ObservableSanityStegaClient extends ObservableSanityClient {}
2833
-
2834
- /** @public */
2835
- export declare class ObservableTransaction extends BaseTransaction {
2836
- #private
2837
- constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2838
- /**
2839
- * Clones the transaction
2840
- */
2841
- clone(): ObservableTransaction
2842
- /**
2843
- * Commit the transaction, returning an observable that produces the first mutated document
2844
- *
2845
- * @param options - Options for the mutation operation
2846
- */
2847
- commit<R extends Record<string, Any>>(
2848
- options: TransactionFirstDocumentMutationOptions,
2849
- ): Observable<SanityDocument<R>>
2850
- /**
2851
- * Commit the transaction, returning an observable that produces an array of the mutated documents
2852
- *
2853
- * @param options - Options for the mutation operation
2854
- */
2855
- commit<R extends Record<string, Any>>(
2856
- options: TransactionAllDocumentsMutationOptions,
2857
- ): Observable<SanityDocument<R>[]>
2858
- /**
2859
- * Commit the transaction, returning an observable that produces a mutation result object
2860
- *
2861
- * @param options - Options for the mutation operation
2862
- */
2863
- commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2864
- /**
2865
- * Commit the transaction, returning an observable that produces a mutation result object
2866
- *
2867
- * @param options - Options for the mutation operation
2868
- */
2869
- commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2870
- /**
2871
- * Commit the transaction, returning an observable that produces a mutation result object
2872
- *
2873
- * @param options - Options for the mutation operation
2874
- */
2875
- commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2876
- /**
2877
- * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2878
- * The operation is added to the current transaction, ready to be commited by `commit()`
2879
- *
2880
- * @param documentId - Document ID to perform the patch operation on
2881
- * @param patchOps - Operations to perform, or a builder function
2882
- */
2883
- patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2884
- /**
2885
- * Adds the given patch instance to the transaction.
2886
- * The operation is added to the current transaction, ready to be commited by `commit()`
2887
- *
2888
- * @param patch - ObservablePatch to execute
2889
- */
2890
- patch(patch: ObservablePatch): this
2891
- }
2892
-
2893
- /** @public */
2894
- export declare class ObservableUsersClient implements ObservableUsersClientType {
2895
- #private
2896
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2897
- /**
2898
- * Fetch a user by user ID
2899
- *
2900
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2901
- */
2902
- getById<T extends 'me' | string>(
2903
- id: T,
2904
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2905
- }
2906
-
2907
- /** @internal */
2908
- declare interface ObservableUsersClientType {
2909
- /**
2910
- * Fetch a user by user ID
2911
- *
2912
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2913
- */
2914
- getById<T extends 'me' | string>(
2915
- id: T,
2916
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2917
- }
2918
-
2919
- /**
2920
- * The listener connection has been established
2921
- * note: it's usually a better option to use the 'welcome' event
2922
- * @public
2923
- */
2924
- export declare type OpenEvent = {
2925
- type: 'open'
2926
- }
2927
-
2928
- /** @public */
2929
- export declare class Patch extends BasePatch {
2930
- #private
2931
- constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2932
- /**
2933
- * Clones the patch
2934
- */
2935
- clone(): Patch
2936
- /**
2937
- * Commit the patch, returning a promise that resolves to the first patched document
2938
- *
2939
- * @param options - Options for the mutation operation
2940
- */
2941
- commit<R extends Record<string, Any> = Record<string, Any>>(
2942
- options: FirstDocumentMutationOptions,
2943
- ): Promise<SanityDocument<R>>
2944
- /**
2945
- * Commit the patch, returning a promise that resolves to an array of the mutated documents
2946
- *
2947
- * @param options - Options for the mutation operation
2948
- */
2949
- commit<R extends Record<string, Any> = Record<string, Any>>(
2950
- options: AllDocumentsMutationOptions,
2951
- ): Promise<SanityDocument<R>[]>
2952
- /**
2953
- * Commit the patch, returning a promise that resolves to a mutation result object
2954
- *
2955
- * @param options - Options for the mutation operation
2956
- */
2957
- commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2958
- /**
2959
- * Commit the patch, returning a promise that resolves to a mutation result object
2960
- *
2961
- * @param options - Options for the mutation operation
2962
- */
2963
- commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2964
- /**
2965
- * Commit the patch, returning a promise that resolves to the first patched document
2966
- *
2967
- * @param options - Options for the mutation operation
2968
- */
2969
- commit<R extends Record<string, Any> = Record<string, Any>>(
2970
- options?: BaseMutationOptions,
2971
- ): Promise<SanityDocument<R>>
2972
- }
2973
-
2974
- /** @public */
2975
- export declare type PatchBuilder = (patch: Patch) => Patch
2976
-
2977
- /** @internal */
2978
- export declare type PatchMutationOperation = PatchOperations & MutationSelection
2979
-
2980
- /** @internal */
2981
- export declare interface PatchOperations {
2982
- set?: {
2983
- [key: string]: Any
2984
- }
2985
- setIfMissing?: {
2986
- [key: string]: Any
2987
- }
2988
- diffMatchPatch?: {
2989
- [key: string]: Any
2990
- }
2991
- unset?: string[]
2992
- inc?: {
2993
- [key: string]: number
2994
- }
2995
- dec?: {
2996
- [key: string]: number
2997
- }
2998
- insert?: InsertPatch
2999
- ifRevisionID?: string
3000
- }
3001
-
3002
- /** @internal */
3003
- export declare type PatchSelection = string | string[] | MutationSelection
3004
-
3005
- /** @public */
3006
- declare interface ProgressEvent_2 {
3007
- type: 'progress'
3008
- stage: 'upload' | 'download'
3009
- percent: number
3010
- total?: number
3011
- loaded?: number
3012
- lengthComputable: boolean
3013
- }
3014
- export {ProgressEvent_2 as ProgressEvent}
3015
-
3016
- /** @internal */
3017
- export declare class ProjectsClient implements ProjectsClientType {
3018
- #private
3019
- constructor(client: SanityClient, httpRequest: HttpRequest)
3020
- /**
3021
- * Fetch a list of projects the authenticated user has access to.
3022
- *
3023
- * @param options - Options for the list request
3024
- * @param options.includeMembers - Whether to include members in the response (default: true)
3025
- */
3026
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
3027
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3028
- /**
3029
- * Fetch a project by project ID
3030
- *
3031
- * @param projectId - ID of the project to fetch
3032
- */
3033
- getById(projectId: string): Promise<SanityProject>
3034
- }
3035
-
3036
- /** @internal */
3037
- declare interface ProjectsClientType {
3038
- /**
3039
- * Fetch a list of projects the authenticated user has access to.
3040
- *
3041
- * @param options - Options for the list request
3042
- * @param options.includeMembers - Whether to include members in the response (default: true)
3043
- */
3044
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
3045
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3046
- list(options?: {includeMembers?: boolean}): Promise<SanityProject[]>
3047
- /**
3048
- * Fetch a project by project ID
3049
- *
3050
- * @param projectId - ID of the project to fetch
3051
- */
3052
- getById(projectId: string): Promise<SanityProject>
3053
- }
3054
-
3055
- /**
3056
- * Publishes a draft document.
3057
- * If a published version of the document already exists this is replaced by the current draft document.
3058
- * In either case the draft document is deleted.
3059
- * The optional revision id parameters can be used for optimistic locking to ensure
3060
- * that the draft and/or published versions of the document have not been changed by another client.
3061
- *
3062
- * @public
3063
- */
3064
- export declare type PublishAction = {
3065
- actionType: 'sanity.action.document.publish'
3066
- /**
3067
- * Draft document ID to publish
3068
- */
3069
- draftId: string
3070
- /**
3071
- * Draft revision ID to match
3072
- */
3073
- ifDraftRevisionId?: string
3074
- /**
3075
- * Published document ID to replace
3076
- */
3077
- publishedId: string
3078
- /**
3079
- * Published revision ID to match
3080
- */
3081
- ifPublishedRevisionId?: string
3082
- }
3083
-
3084
- /** @public */
3085
- export declare type QueryOptions =
3086
- | FilteredResponseQueryOptions
3087
- | UnfilteredResponseQueryOptions
3088
- | UnfilteredResponseWithoutQuery
3089
-
3090
- /** @public */
3091
- export declare interface QueryParams {
3092
- [key: string]: any
3093
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3094
- body?: never
3095
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3096
- cache?: 'next' extends keyof RequestInit ? never : any
3097
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3098
- filterResponse?: never
3099
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3100
- headers?: never
3101
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3102
- method?: never
3103
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3104
- next?: 'next' extends keyof RequestInit ? never : any
3105
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3106
- perspective?: never
3107
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3108
- query?: never
3109
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3110
- resultSourceMap?: never
3111
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3112
- returnQuery?: never
3113
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3114
- signal?: never
3115
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3116
- stega?: never
3117
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3118
- tag?: never
3119
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3120
- timeout?: never
3121
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3122
- token?: never
3123
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3124
- useCdn?: never
3125
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3126
- lastLiveEventId?: never
3127
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3128
- cacheMode?: never
3129
- }
3130
-
3131
- /**
3132
- * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3133
- * @public
3134
- */
3135
- export declare type QueryWithoutParams = Record<string, never> | undefined
3136
-
3137
- /** @public */
3138
- export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
3139
-
3140
- /** @public */
3141
- export declare interface RawQueryResponse<R> {
3142
- query: string
3143
- ms: number
3144
- result: R
3145
- resultSourceMap?: ContentSourceMap
3146
- /** Requires `apiVersion` to be `2021-03-25` or later. */
3147
- syncTags?: SyncTag[]
3148
- }
3149
-
3150
- /** @internal */
3151
- export declare interface RawRequestOptions {
3152
- url?: string
3153
- uri?: string
3154
- method?: string
3155
- token?: string
3156
- json?: boolean
3157
- tag?: string
3158
- useGlobalApi?: boolean
3159
- withCredentials?: boolean
3160
- query?: {
3161
- [key: string]: string | string[]
3162
- }
3163
- headers?: {
3164
- [key: string]: string
3165
- }
3166
- timeout?: number
3167
- proxy?: string
3168
- body?: Any
3169
- maxRedirects?: number
3170
- signal?: AbortSignal
3171
- }
3172
-
3173
- /**
3174
- * The listener has been disconnected, and a reconnect attempt is scheduled.
3175
- *
3176
- * @public
3177
- */
3178
- export declare type ReconnectEvent = {
3179
- type: 'reconnect'
3180
- }
3181
-
3182
- /**
3183
- * @public
3184
- * @deprecated – The `r`-prefix is not required, use `string` instead
3185
- */
3186
- export declare type ReleaseId = `r${string}`
3187
-
3188
- /**
3189
- * Replaces an existing draft document.
3190
- * At least one of the draft or published versions of the document must exist.
3191
- *
3192
- * @public
3193
- */
3194
- export declare type ReplaceDraftAction = {
3195
- actionType: 'sanity.action.document.replaceDraft'
3196
- /**
3197
- * Published document ID to create draft from, if draft does not exist
3198
- */
3199
- publishedId: string
3200
- /**
3201
- * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3202
- */
3203
- attributes: IdentifiedSanityDocumentStub
3204
- }
3205
-
3206
- /**
3207
- * @deprecated -- Use `import {requester} from '@sanity/client'` instead
3208
- * @public
3209
- */
3210
- export declare const requester: Requester
3211
-
3212
- /** @internal */
3213
- export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
3214
- url?: string
3215
- uri?: string
3216
- canUseCdn?: boolean
3217
- useCdn?: boolean
3218
- tag?: string
3219
- returnQuery?: boolean
3220
- resultSourceMap?: boolean | 'withKeyArraySelector'
3221
- perspective?: ClientPerspective
3222
- lastLiveEventId?: string
3223
- cacheMode?: 'noStale'
3224
- }
3225
-
3226
- /** @public */
3227
- export declare interface RequestOptions {
3228
- timeout?: number
3229
- token?: string
3230
- tag?: string
3231
- headers?: Record<string, string>
3232
- method?: string
3233
- query?: Any
3234
- body?: Any
3235
- signal?: AbortSignal
3236
- }
3237
-
3238
- /** @alpha */
3239
- export declare type ResolveStudioUrl = (
3240
- sourceDocument: ContentSourceMapDocuments_2[number],
3241
- ) => StudioUrl
3242
-
3243
- /** @public */
3244
- export declare interface ResponseEvent<T = unknown> {
3245
- type: 'response'
3246
- body: T
3247
- url: string
3248
- method: string
3249
- statusCode: number
3250
- statusMessage?: string
3251
- headers: Record<string, string>
3252
- }
3253
-
3254
- /** @public */
3255
- export declare interface ResponseQueryOptions extends RequestOptions {
3256
- perspective?: ClientPerspective
3257
- resultSourceMap?: boolean | 'withKeyArraySelector'
3258
- returnQuery?: boolean
3259
- useCdn?: boolean
3260
- stega?: boolean | StegaConfig
3261
- cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
3262
- next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
3263
- lastLiveEventId?: string | string[] | null
3264
- /**
3265
- * When set to `noStale`, APICDN will not return a cached response if the content is stale.
3266
- * Tradeoff between latency and freshness of content.
3267
- *
3268
- * Only to be used with live content queries and when useCdn is true.
3269
- */
3270
- cacheMode?: 'noStale'
3271
- }
3272
-
3273
- /** @internal */
3274
- export declare interface SanityAssetDocument extends SanityDocument {
3275
- url: string
3276
- path: string
3277
- size: number
3278
- assetId: string
3279
- mimeType: string
3280
- sha1hash: string
3281
- extension: string
3282
- uploadId?: string
3283
- originalFilename?: string
3284
- }
3285
-
3286
- /** @public */
3287
- export declare class SanityClient implements SanityClientType {
3288
- #private
3289
- assets: AssetsClient
3290
- datasets: DatasetsClient
3291
- live: LiveClient
3292
- projects: ProjectsClient
3293
- users: UsersClient
3294
- /**
3295
- * Observable version of the Sanity client, with the same configuration as the promise-based one
3296
- */
3297
- observable: ObservableSanityClient
3298
- listen: typeof _listen
3299
- constructor(httpRequest: HttpRequest, config?: ClientConfig)
3300
- /**
3301
- * Clone the client - returns a new instance
3302
- */
3303
- clone(): SanityClient
3304
- /**
3305
- * Returns the current client configuration
3306
- */
3307
- config(): InitializedClientConfig
3308
- /**
3309
- * Reconfigure the client. Note that this _mutates_ the current client.
3310
- */
3311
- config(newConfig?: Partial<ClientConfig>): this
3312
- /**
3313
- * Clone the client with a new (partial) configuration.
3314
- *
3315
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3316
- */
3317
- withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3318
- /**
3319
- * Perform a GROQ-query against the configured dataset.
3320
- *
3321
- * @param query - GROQ-query to perform
3322
- */
3323
- fetch<
3324
- R = Any,
3325
- Q extends QueryWithoutParams = QueryWithoutParams,
3326
- const G extends string = string,
3327
- >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3328
- /**
3329
- * Perform a GROQ-query against the configured dataset.
3330
- *
3331
- * @param query - GROQ-query to perform
3332
- * @param params - Optional query parameters
3333
- * @param options - Optional request options
3334
- */
3335
- fetch<
3336
- R = Any,
3337
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3338
- const G extends string = string,
3339
- >(
3340
- query: G,
3341
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3342
- options?: FilteredResponseQueryOptions,
3343
- ): Promise<ClientReturn<G, R>>
3344
- /**
3345
- * Perform a GROQ-query against the configured dataset.
3346
- *
3347
- * @param query - GROQ-query to perform
3348
- * @param params - Optional query parameters
3349
- * @param options - Request options
3350
- */
3351
- fetch<
3352
- R = Any,
3353
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3354
- const G extends string = string,
3355
- >(
3356
- query: G,
3357
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3358
- options: UnfilteredResponseQueryOptions,
3359
- ): Promise<RawQueryResponse<ClientReturn<G, R>>>
3360
- /**
3361
- * Perform a GROQ-query against the configured dataset.
3362
- *
3363
- * @param query - GROQ-query to perform
3364
- * @param params - Optional query parameters
3365
- * @param options - Request options
3366
- */
3367
- fetch<
3368
- R = Any,
3369
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3370
- const G extends string = string,
3371
- >(
3372
- query: G,
3373
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3374
- options: UnfilteredResponseWithoutQuery,
3375
- ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
3376
- /**
3377
- * Fetch a single document with the given ID.
3378
- *
3379
- * @param id - Document ID to fetch
3380
- * @param options - Request options
3381
- */
3382
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
3383
- id: string,
3384
- options?: {
3385
- signal?: AbortSignal
3386
- tag?: string
3387
- },
3388
- ): Promise<SanityDocument<R> | undefined>
3389
- /**
3390
- * Fetch multiple documents in one request.
3391
- * Should be used sparingly - performing a query is usually a better option.
3392
- * The order/position of documents is preserved based on the original array of IDs.
3393
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3394
- *
3395
- * @param ids - Document IDs to fetch
3396
- * @param options - Request options
3397
- */
3398
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
3399
- ids: string[],
3400
- options?: {
3401
- signal?: AbortSignal
3402
- tag?: string
3403
- },
3404
- ): Promise<(SanityDocument<R> | null)[]>
3405
- /**
3406
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3407
- * Returns a promise that resolves to the created document.
3408
- *
3409
- * @param document - Document to create
3410
- * @param options - Mutation options
3411
- */
3412
- create<R extends Record<string, Any> = Record<string, Any>>(
3413
- document: SanityDocumentStub<R>,
3414
- options: FirstDocumentMutationOptions,
3415
- ): Promise<SanityDocument<R>>
3416
- /**
3417
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3418
- * Returns a promise that resolves to an array containing the created document.
3419
- *
3420
- * @param document - Document to create
3421
- * @param options - Mutation options
3422
- */
3423
- create<R extends Record<string, Any> = Record<string, Any>>(
3424
- document: SanityDocumentStub<R>,
3425
- options: AllDocumentsMutationOptions,
3426
- ): Promise<SanityDocument<R>[]>
3427
- /**
3428
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3429
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3430
- *
3431
- * @param document - Document to create
3432
- * @param options - Mutation options
3433
- */
3434
- create<R extends Record<string, Any> = Record<string, Any>>(
3435
- document: SanityDocumentStub<R>,
3436
- options: FirstDocumentIdMutationOptions,
3437
- ): Promise<SingleMutationResult>
3438
- /**
3439
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3440
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3441
- *
3442
- * @param document - Document to create
3443
- * @param options - Mutation options
3444
- */
3445
- create<R extends Record<string, Any> = Record<string, Any>>(
3446
- document: SanityDocumentStub<R>,
3447
- options: AllDocumentIdsMutationOptions,
3448
- ): Promise<MultipleMutationResult>
3449
- /**
3450
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3451
- * Returns a promise that resolves to the created document.
3452
- *
3453
- * @param document - Document to create
3454
- * @param options - Mutation options
3455
- */
3456
- create<R extends Record<string, Any> = Record<string, Any>>(
3457
- document: SanityDocumentStub<R>,
3458
- options?: BaseMutationOptions,
3459
- ): Promise<SanityDocument<R>>
3460
- /**
3461
- * Create a document if no document with the same ID already exists.
3462
- * Returns a promise that resolves to the created document.
3463
- *
3464
- * @param document - Document to create
3465
- * @param options - Mutation options
3466
- */
3467
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3468
- document: IdentifiedSanityDocumentStub<R>,
3469
- options: FirstDocumentMutationOptions,
3470
- ): Promise<SanityDocument<R>>
3471
- /**
3472
- * Create a document if no document with the same ID already exists.
3473
- * Returns a promise that resolves to an array containing the created document.
3474
- *
3475
- * @param document - Document to create
3476
- * @param options - Mutation options
3477
- */
3478
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3479
- document: IdentifiedSanityDocumentStub<R>,
3480
- options: AllDocumentsMutationOptions,
3481
- ): Promise<SanityDocument<R>[]>
3482
- /**
3483
- * Create a document if no document with the same ID already exists.
3484
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3485
- *
3486
- * @param document - Document to create
3487
- * @param options - Mutation options
3488
- */
3489
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3490
- document: IdentifiedSanityDocumentStub<R>,
3491
- options: FirstDocumentIdMutationOptions,
3492
- ): Promise<SingleMutationResult>
3493
- /**
3494
- * Create a document if no document with the same ID already exists.
3495
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3496
- *
3497
- * @param document - Document to create
3498
- * @param options - Mutation options
3499
- */
3500
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3501
- document: IdentifiedSanityDocumentStub<R>,
3502
- options: AllDocumentIdsMutationOptions,
3503
- ): Promise<MultipleMutationResult>
3504
- /**
3505
- * Create a document if no document with the same ID already exists.
3506
- * Returns a promise that resolves to the created document.
3507
- *
3508
- * @param document - Document to create
3509
- * @param options - Mutation options
3510
- */
3511
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3512
- document: IdentifiedSanityDocumentStub<R>,
3513
- options?: BaseMutationOptions,
3514
- ): Promise<SanityDocument<R>>
3515
- /**
3516
- * Create a document if it does not exist, or replace a document with the same document ID
3517
- * Returns a promise that resolves to the created document.
3518
- *
3519
- * @param document - Document to either create or replace
3520
- * @param options - Mutation options
3521
- */
3522
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3523
- document: IdentifiedSanityDocumentStub<R>,
3524
- options: FirstDocumentMutationOptions,
3525
- ): Promise<SanityDocument<R>>
3526
- /**
3527
- * Create a document if it does not exist, or replace a document with the same document ID
3528
- * Returns a promise that resolves to an array containing the created document.
3529
- *
3530
- * @param document - Document to either create or replace
3531
- * @param options - Mutation options
3532
- */
3533
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3534
- document: IdentifiedSanityDocumentStub<R>,
3535
- options: AllDocumentsMutationOptions,
3536
- ): Promise<SanityDocument<R>[]>
3537
- /**
3538
- * Create a document if it does not exist, or replace a document with the same document ID
3539
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3540
- *
3541
- * @param document - Document to either create or replace
3542
- * @param options - Mutation options
3543
- */
3544
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3545
- document: IdentifiedSanityDocumentStub<R>,
3546
- options: FirstDocumentIdMutationOptions,
3547
- ): Promise<SingleMutationResult>
3548
- /**
3549
- * Create a document if it does not exist, or replace a document with the same document ID
3550
- * Returns a promise that resolves to a mutation result object containing the created document ID.
3551
- *
3552
- * @param document - Document to either create or replace
3553
- * @param options - Mutation options
3554
- */
3555
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3556
- document: IdentifiedSanityDocumentStub<R>,
3557
- options: AllDocumentIdsMutationOptions,
3558
- ): Promise<MultipleMutationResult>
3559
- /**
3560
- * Create a document if it does not exist, or replace a document with the same document ID
3561
- * Returns a promise that resolves to the created document.
3562
- *
3563
- * @param document - Document to either create or replace
3564
- * @param options - Mutation options
3565
- */
3566
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3567
- document: IdentifiedSanityDocumentStub<R>,
3568
- options?: BaseMutationOptions,
3569
- ): Promise<SanityDocument<R>>
3570
- /**
3571
- * Deletes a document with the given document ID.
3572
- * Returns a promise that resolves to the deleted document.
3573
- *
3574
- * @param id - Document ID to delete
3575
- * @param options - Options for the mutation
3576
- */
3577
- delete<R extends Record<string, Any> = Record<string, Any>>(
3578
- id: string,
3579
- options: FirstDocumentMutationOptions,
3580
- ): Promise<SanityDocument<R>>
3581
- /**
3582
- * Deletes a document with the given document ID.
3583
- * Returns a promise that resolves to an array containing the deleted document.
3584
- *
3585
- * @param id - Document ID to delete
3586
- * @param options - Options for the mutation
3587
- */
3588
- delete<R extends Record<string, Any> = Record<string, Any>>(
3589
- id: string,
3590
- options: AllDocumentsMutationOptions,
3591
- ): Promise<SanityDocument<R>[]>
3592
- /**
3593
- * Deletes a document with the given document ID.
3594
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3595
- *
3596
- * @param id - Document ID to delete
3597
- * @param options - Options for the mutation
3598
- */
3599
- delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3600
- /**
3601
- * Deletes a document with the given document ID.
3602
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3603
- *
3604
- * @param id - Document ID to delete
3605
- * @param options - Options for the mutation
3606
- */
3607
- delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3608
- /**
3609
- * Deletes a document with the given document ID.
3610
- * Returns a promise that resolves to the deleted document.
3611
- *
3612
- * @param id - Document ID to delete
3613
- * @param options - Options for the mutation
3614
- */
3615
- delete<R extends Record<string, Any> = Record<string, Any>>(
3616
- id: string,
3617
- options?: BaseMutationOptions,
3618
- ): Promise<SanityDocument<R>>
3619
- /**
3620
- * Deletes one or more documents matching the given query or document ID.
3621
- * Returns a promise that resolves to first deleted document.
3622
- *
3623
- * @param selection - An object with either an `id` or `query` key defining what to delete
3624
- * @param options - Options for the mutation
3625
- */
3626
- delete<R extends Record<string, Any> = Record<string, Any>>(
3627
- selection: MutationSelection,
3628
- options: FirstDocumentMutationOptions,
3629
- ): Promise<SanityDocument<R>>
3630
- /**
3631
- * Deletes one or more documents matching the given query or document ID.
3632
- * Returns a promise that resolves to an array containing the deleted documents.
3633
- *
3634
- * @param selection - An object with either an `id` or `query` key defining what to delete
3635
- * @param options - Options for the mutation
3636
- */
3637
- delete<R extends Record<string, Any> = Record<string, Any>>(
3638
- selection: MutationSelection,
3639
- options: AllDocumentsMutationOptions,
3640
- ): Promise<SanityDocument<R>[]>
3641
- /**
3642
- * Deletes one or more documents matching the given query or document ID.
3643
- * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
3644
- *
3645
- * @param selection - An object with either an `id` or `query` key defining what to delete
3646
- * @param options - Options for the mutation
3647
- */
3648
- delete(
3649
- selection: MutationSelection,
3650
- options: FirstDocumentIdMutationOptions,
3651
- ): Promise<SingleMutationResult>
3652
- /**
3653
- * Deletes one or more documents matching the given query or document ID.
3654
- * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
3655
- *
3656
- * @param selection - An object with either an `id` or `query` key defining what to delete
3657
- * @param options - Options for the mutation
3658
- */
3659
- delete(
3660
- selection: MutationSelection,
3661
- options: AllDocumentIdsMutationOptions,
3662
- ): Promise<MultipleMutationResult>
3663
- /**
3664
- * Deletes one or more documents matching the given query or document ID.
3665
- * Returns a promise that resolves to first deleted document.
3666
- *
3667
- * @param selection - An object with either an `id` or `query` key defining what to delete
3668
- * @param options - Options for the mutation
3669
- */
3670
- delete<R extends Record<string, Any> = Record<string, Any>>(
3671
- selection: MutationSelection,
3672
- options?: BaseMutationOptions,
3673
- ): Promise<SanityDocument<R>>
3674
- /**
3675
- * Perform mutation operations against the configured dataset
3676
- * Returns a promise that resolves to the first mutated document.
2898
+ * Commit the patch, returning a promise that resolves to the first patched document
3677
2899
  *
3678
- * @param operations - Mutation operations to execute
3679
- * @param options - Mutation options
2900
+ * @param options - Options for the mutation operation
3680
2901
  */
3681
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3682
- operations: Mutation<R>[] | Patch | Transaction,
2902
+ commit<R extends Record<string, Any> = Record<string, Any>>(
3683
2903
  options: FirstDocumentMutationOptions,
3684
2904
  ): Promise<SanityDocument<R>>
3685
2905
  /**
3686
- * Perform mutation operations against the configured dataset.
3687
- * Returns a promise that resolves to an array of the mutated documents.
2906
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
3688
2907
  *
3689
- * @param operations - Mutation operations to execute
3690
- * @param options - Mutation options
2908
+ * @param options - Options for the mutation operation
3691
2909
  */
3692
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3693
- operations: Mutation<R>[] | Patch | Transaction,
2910
+ commit<R extends Record<string, Any> = Record<string, Any>>(
3694
2911
  options: AllDocumentsMutationOptions,
3695
2912
  ): Promise<SanityDocument<R>[]>
3696
2913
  /**
3697
- * Perform mutation operations against the configured dataset
3698
- * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
2914
+ * Commit the patch, returning a promise that resolves to a mutation result object
3699
2915
  *
3700
- * @param operations - Mutation operations to execute
3701
- * @param options - Mutation options
2916
+ * @param options - Options for the mutation operation
3702
2917
  */
3703
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3704
- operations: Mutation<R>[] | Patch | Transaction,
3705
- options: FirstDocumentIdMutationOptions,
3706
- ): Promise<SingleMutationResult>
2918
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3707
2919
  /**
3708
- * Perform mutation operations against the configured dataset
3709
- * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
2920
+ * Commit the patch, returning a promise that resolves to a mutation result object
3710
2921
  *
3711
- * @param operations - Mutation operations to execute
3712
- * @param options - Mutation options
2922
+ * @param options - Options for the mutation operation
3713
2923
  */
3714
- mutate<R extends Record<string, Any>>(
3715
- operations: Mutation<R>[] | Patch | Transaction,
3716
- options: AllDocumentIdsMutationOptions,
3717
- ): Promise<MultipleMutationResult>
2924
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3718
2925
  /**
3719
- * Perform mutation operations against the configured dataset
3720
- * Returns a promise that resolves to the first mutated document.
2926
+ * Commit the patch, returning a promise that resolves to the first patched document
3721
2927
  *
3722
- * @param operations - Mutation operations to execute
3723
- * @param options - Mutation options
2928
+ * @param options - Options for the mutation operation
3724
2929
  */
3725
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3726
- operations: Mutation<R>[] | Patch | Transaction,
2930
+ commit<R extends Record<string, Any> = Record<string, Any>>(
3727
2931
  options?: BaseMutationOptions,
3728
2932
  ): Promise<SanityDocument<R>>
2933
+ }
2934
+
2935
+ /** @public */
2936
+ export declare type PatchBuilder = (patch: Patch) => Patch
2937
+
2938
+ /** @internal */
2939
+ export declare type PatchMutationOperation = PatchOperations & MutationSelection
2940
+
2941
+ /** @internal */
2942
+ export declare interface PatchOperations {
2943
+ set?: {
2944
+ [key: string]: Any
2945
+ }
2946
+ setIfMissing?: {
2947
+ [key: string]: Any
2948
+ }
2949
+ diffMatchPatch?: {
2950
+ [key: string]: Any
2951
+ }
2952
+ unset?: string[]
2953
+ inc?: {
2954
+ [key: string]: number
2955
+ }
2956
+ dec?: {
2957
+ [key: string]: number
2958
+ }
2959
+ insert?: InsertPatch
2960
+ ifRevisionID?: string
2961
+ }
2962
+
2963
+ /** @internal */
2964
+ export declare type PatchSelection = string | string[] | MutationSelection
2965
+
2966
+ /** @public */
2967
+ declare interface ProgressEvent_2 {
2968
+ type: 'progress'
2969
+ stage: 'upload' | 'download'
2970
+ percent: number
2971
+ total?: number
2972
+ loaded?: number
2973
+ lengthComputable: boolean
2974
+ }
2975
+ export {ProgressEvent_2 as ProgressEvent}
2976
+
2977
+ /** @internal */
2978
+ export declare class ProjectsClient {
2979
+ #private
2980
+ constructor(client: SanityClient, httpRequest: HttpRequest)
3729
2981
  /**
3730
- * Create a new buildable patch of operations to perform
3731
- *
3732
- * @param documentId - Document ID to patch
3733
- * @param operations - Optional object of patch operations to initialize the patch instance with
3734
- * @returns Patch instance - call `.commit()` to perform the operations defined
3735
- */
3736
- patch(documentId: string, operations?: PatchOperations): Patch
3737
- /**
3738
- * Create a new buildable patch of operations to perform
3739
- *
3740
- * @param documentIds - Array of document IDs to patch
3741
- * @param operations - Optional object of patch operations to initialize the patch instance with
3742
- * @returns Patch instance - call `.commit()` to perform the operations defined
3743
- */
3744
- patch(documentIds: string[], operations?: PatchOperations): Patch
3745
- /**
3746
- * Create a new buildable patch of operations to perform
3747
- *
3748
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3749
- * @param operations - Optional object of patch operations to initialize the patch instance with
3750
- * @returns Patch instance - call `.commit()` to perform the operations defined
3751
- */
3752
- patch(selection: MutationSelection, operations?: PatchOperations): Patch
3753
- /**
3754
- * Create a new transaction of mutations
2982
+ * Fetch a list of projects the authenticated user has access to.
3755
2983
  *
3756
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2984
+ * @param options - Options for the list request
2985
+ * - `includeMembers` - Whether to include members in the response (default: true)
3757
2986
  */
3758
- transaction<R extends Record<string, Any> = Record<string, Any>>(
3759
- operations?: Mutation<R>[],
3760
- ): Transaction
2987
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2988
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3761
2989
  /**
3762
- * Perform action operations against the configured dataset
3763
- * Returns a promise that resolves to the transaction result
2990
+ * Fetch a project by project ID
3764
2991
  *
3765
- * @param operations - Action operation(s) to execute
3766
- * @param options - Action options
2992
+ * @param projectId - ID of the project to fetch
3767
2993
  */
3768
- action(
3769
- operations: Action | Action[],
3770
- options?: BaseActionOptions,
3771
- ): Promise<SingleActionResult | MultipleActionResult>
2994
+ getById(projectId: string): Promise<SanityProject>
2995
+ }
2996
+
2997
+ /**
2998
+ * Publishes a draft document.
2999
+ * If a published version of the document already exists this is replaced by the current draft document.
3000
+ * In either case the draft document is deleted.
3001
+ * The optional revision id parameters can be used for optimistic locking to ensure
3002
+ * that the draft and/or published versions of the document have not been changed by another client.
3003
+ *
3004
+ * @public
3005
+ */
3006
+ export declare type PublishAction = {
3007
+ actionType: 'sanity.action.document.publish'
3772
3008
  /**
3773
- * Perform a request against the Sanity API
3774
- * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
3775
- *
3776
- * @param options - Request options
3777
- * @returns Promise resolving to the response body
3009
+ * Draft document ID to publish
3778
3010
  */
3779
- request<R = Any>(options: RawRequestOptions): Promise<R>
3011
+ draftId: string
3780
3012
  /**
3781
- * Perform an HTTP request a `/data` sub-endpoint
3782
- * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
3783
- *
3784
- * @deprecated - Use `request()` or your own HTTP library instead
3785
- * @param endpoint - Endpoint to hit (mutate, query etc)
3786
- * @param body - Request body
3787
- * @param options - Request options
3788
- * @internal
3013
+ * Draft revision ID to match
3789
3014
  */
3790
- dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
3015
+ ifDraftRevisionId?: string
3791
3016
  /**
3792
- * Get a Sanity API URL for the URI provided
3793
- *
3794
- * @param uri - URI/path to build URL for
3795
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
3017
+ * Published document ID to replace
3796
3018
  */
3797
- getUrl(uri: string, canUseCdn?: boolean): string
3019
+ publishedId: string
3798
3020
  /**
3799
- * Get a Sanity API URL for the data operation and path provided
3800
- *
3801
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3802
- * @param path - Path to append after the operation
3021
+ * Published revision ID to match
3803
3022
  */
3804
- getDataUrl(operation: string, path?: string): string
3023
+ ifPublishedRevisionId?: string
3024
+ }
3025
+
3026
+ /** @public */
3027
+ export declare type QueryOptions =
3028
+ | FilteredResponseQueryOptions
3029
+ | UnfilteredResponseQueryOptions
3030
+ | UnfilteredResponseWithoutQuery
3031
+
3032
+ /** @public */
3033
+ export declare interface QueryParams {
3034
+ [key: string]: any
3035
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3036
+ body?: never
3037
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3038
+ cache?: 'next' extends keyof RequestInit ? never : any
3039
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3040
+ filterResponse?: never
3041
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3042
+ headers?: never
3043
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3044
+ method?: never
3045
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3046
+ next?: 'next' extends keyof RequestInit ? never : any
3047
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3048
+ perspective?: never
3049
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3050
+ query?: never
3051
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3052
+ resultSourceMap?: never
3053
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3054
+ returnQuery?: never
3055
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3056
+ signal?: never
3057
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3058
+ stega?: never
3059
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3060
+ tag?: never
3061
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3062
+ timeout?: never
3063
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3064
+ token?: never
3065
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3066
+ useCdn?: never
3067
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3068
+ lastLiveEventId?: never
3069
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3070
+ cacheMode?: never
3071
+ }
3072
+
3073
+ /**
3074
+ * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3075
+ * @public
3076
+ */
3077
+ export declare type QueryWithoutParams = Record<string, never> | undefined
3078
+
3079
+ /** @public */
3080
+ export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
3081
+
3082
+ /** @public */
3083
+ export declare interface RawQueryResponse<R> {
3084
+ query: string
3085
+ ms: number
3086
+ result: R
3087
+ resultSourceMap?: ContentSourceMap
3088
+ /** Requires `apiVersion` to be `2021-03-25` or later. */
3089
+ syncTags?: SyncTag[]
3090
+ }
3091
+
3092
+ /** @internal */
3093
+ export declare interface RawRequestOptions {
3094
+ url?: string
3095
+ uri?: string
3096
+ method?: string
3097
+ token?: string
3098
+ json?: boolean
3099
+ tag?: string
3100
+ useGlobalApi?: boolean
3101
+ withCredentials?: boolean
3102
+ query?: {
3103
+ [key: string]: string | string[]
3104
+ }
3105
+ headers?: {
3106
+ [key: string]: string
3107
+ }
3108
+ timeout?: number
3109
+ proxy?: string
3110
+ body?: Any
3111
+ maxRedirects?: number
3112
+ signal?: AbortSignal
3805
3113
  }
3806
3114
 
3807
3115
  /**
3808
- * Shared base type for the `SanityClient` and `ObservableSanityClient` classes.
3809
- * TODO: refactor the Promise and Observable differences to use generics so we no longer suffer from all this duplication in TS docs
3116
+ * The listener has been disconnected, and a reconnect attempt is scheduled.
3117
+ *
3118
+ * @public
3810
3119
  */
3811
- declare interface SanityClientBase {
3812
- live: LiveClient
3813
- listen: typeof _listen
3120
+ export declare type ReconnectEvent = {
3121
+ type: 'reconnect'
3122
+ }
3123
+
3124
+ /**
3125
+ * @public
3126
+ * @deprecated – The `r`-prefix is not required, use `string` instead
3127
+ */
3128
+ export declare type ReleaseId = `r${string}`
3129
+
3130
+ /**
3131
+ * Replaces an existing draft document.
3132
+ * At least one of the draft or published versions of the document must exist.
3133
+ *
3134
+ * @public
3135
+ */
3136
+ export declare type ReplaceDraftAction = {
3137
+ actionType: 'sanity.action.document.replaceDraft'
3814
3138
  /**
3815
- * Get a Sanity API URL for the URI provided
3816
- *
3817
- * @param uri - URI/path to build URL for
3818
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
3139
+ * Published document ID to create draft from, if draft does not exist
3819
3140
  */
3820
- getUrl(uri: string, canUseCdn?: boolean): string
3141
+ publishedId: string
3821
3142
  /**
3822
- * Get a Sanity API URL for the data operation and path provided
3823
- *
3824
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3825
- * @param path - Path to append after the operation
3143
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3826
3144
  */
3827
- getDataUrl(operation: string, path?: string): string
3145
+ attributes: IdentifiedSanityDocumentStub
3828
3146
  }
3829
3147
 
3830
3148
  /**
3831
- * The interface implemented by the `SanityClient` class.
3832
- * When writing code that wants to take an instance of `SanityClient` as input it's better to use this type,
3833
- * as the `SanityClient` class has private properties and thus TypeScrict will consider the type incompatible
3834
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
3149
+ * @deprecated -- Use `import {requester} from '@sanity/client'` instead
3835
3150
  * @public
3836
3151
  */
3837
- export declare interface SanityClientType extends SanityClientBase {
3838
- assets: AssetsClientType
3839
- datasets: DatasetsClientType
3840
- projects: ProjectsClientType
3841
- users: UsersClientType
3152
+ export declare const requester: Requester
3153
+
3154
+ /** @internal */
3155
+ export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
3156
+ url?: string
3157
+ uri?: string
3158
+ canUseCdn?: boolean
3159
+ useCdn?: boolean
3160
+ tag?: string
3161
+ returnQuery?: boolean
3162
+ resultSourceMap?: boolean | 'withKeyArraySelector'
3163
+ perspective?: ClientPerspective
3164
+ lastLiveEventId?: string
3165
+ cacheMode?: 'noStale'
3166
+ }
3167
+
3168
+ /** @public */
3169
+ export declare interface RequestOptions {
3170
+ timeout?: number
3171
+ token?: string
3172
+ tag?: string
3173
+ headers?: Record<string, string>
3174
+ method?: string
3175
+ query?: Any
3176
+ body?: Any
3177
+ signal?: AbortSignal
3178
+ }
3179
+
3180
+ /** @alpha */
3181
+ export declare type ResolveStudioUrl = (
3182
+ sourceDocument: ContentSourceMapDocuments_2[number],
3183
+ ) => StudioUrl
3184
+
3185
+ /** @public */
3186
+ export declare interface ResponseEvent<T = unknown> {
3187
+ type: 'response'
3188
+ body: T
3189
+ url: string
3190
+ method: string
3191
+ statusCode: number
3192
+ statusMessage?: string
3193
+ headers: Record<string, string>
3194
+ }
3195
+
3196
+ /** @public */
3197
+ export declare interface ResponseQueryOptions extends RequestOptions {
3198
+ perspective?: ClientPerspective
3199
+ resultSourceMap?: boolean | 'withKeyArraySelector'
3200
+ returnQuery?: boolean
3201
+ useCdn?: boolean
3202
+ stega?: boolean | StegaConfig
3203
+ cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
3204
+ next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
3205
+ lastLiveEventId?: string | string[] | null
3206
+ /**
3207
+ * When set to `noStale`, APICDN will not return a cached response if the content is stale.
3208
+ * Tradeoff between latency and freshness of content.
3209
+ *
3210
+ * Only to be used with live content queries and when useCdn is true.
3211
+ */
3212
+ cacheMode?: 'noStale'
3213
+ }
3214
+
3215
+ /** @internal */
3216
+ export declare interface SanityAssetDocument extends SanityDocument {
3217
+ url: string
3218
+ path: string
3219
+ size: number
3220
+ assetId: string
3221
+ mimeType: string
3222
+ sha1hash: string
3223
+ extension: string
3224
+ uploadId?: string
3225
+ originalFilename?: string
3226
+ }
3227
+
3228
+ /** @public */
3229
+ export declare class SanityClient {
3230
+ #private
3231
+ assets: AssetsClient
3232
+ datasets: DatasetsClient
3233
+ live: LiveClient
3234
+ projects: ProjectsClient
3235
+ users: UsersClient
3236
+ agent: {
3237
+ action: AgentActionsClient
3238
+ }
3842
3239
  /**
3843
3240
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3844
3241
  */
3845
- observable: ObservableSanityClientType
3242
+ observable: ObservableSanityClient
3243
+ /**
3244
+ * Instance properties
3245
+ */
3246
+ listen: typeof _listen
3247
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
3846
3248
  /**
3847
3249
  * Clone the client - returns a new instance
3848
3250
  */
3849
- clone(): SanityClientType
3251
+ clone(): SanityClient
3850
3252
  /**
3851
3253
  * Returns the current client configuration
3852
3254
  */
@@ -3854,13 +3256,13 @@ export declare interface SanityClientType extends SanityClientBase {
3854
3256
  /**
3855
3257
  * Reconfigure the client. Note that this _mutates_ the current client.
3856
3258
  */
3857
- config(newConfig?: Partial<ClientConfig>): SanityClientType
3259
+ config(newConfig?: Partial<ClientConfig>): this
3858
3260
  /**
3859
3261
  * Clone the client with a new (partial) configuration.
3860
3262
  *
3861
3263
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3862
3264
  */
3863
- withConfig(newConfig?: Partial<ClientConfig>): SanityClientType
3265
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3864
3266
  /**
3865
3267
  * Perform a GROQ-query against the configured dataset.
3866
3268
  *
@@ -3870,10 +3272,7 @@ export declare interface SanityClientType extends SanityClientBase {
3870
3272
  R = Any,
3871
3273
  Q extends QueryWithoutParams = QueryWithoutParams,
3872
3274
  const G extends string = string,
3873
- >(
3874
- query: G,
3875
- params?: Q | QueryWithoutParams,
3876
- ): Promise<ClientReturn<G, R>>
3275
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3877
3276
  /**
3878
3277
  * Perform a GROQ-query against the configured dataset.
3879
3278
  *
@@ -4299,14 +3698,6 @@ export declare interface SanityClientType extends SanityClientBase {
4299
3698
  * @returns Patch instance - call `.commit()` to perform the operations defined
4300
3699
  */
4301
3700
  patch(selection: MutationSelection, operations?: PatchOperations): Patch
4302
- /**
4303
- * Create a new buildable patch of operations to perform
4304
- *
4305
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
4306
- * @param operations - Optional object of patch operations to initialize the patch instance with
4307
- * @returns Patch instance - call `.commit()` to perform the operations defined
4308
- */
4309
- patch(selection: PatchSelection, operations?: PatchOperations): Patch
4310
3701
  /**
4311
3702
  * Create a new transaction of mutations
4312
3703
  *
@@ -4345,6 +3736,20 @@ export declare interface SanityClientType extends SanityClientBase {
4345
3736
  * @internal
4346
3737
  */
4347
3738
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
3739
+ /**
3740
+ * Get a Sanity API URL for the URI provided
3741
+ *
3742
+ * @param uri - URI/path to build URL for
3743
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
3744
+ */
3745
+ getUrl(uri: string, canUseCdn?: boolean): string
3746
+ /**
3747
+ * Get a Sanity API URL for the data operation and path provided
3748
+ *
3749
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3750
+ * @param path - Path to append after the operation
3751
+ */
3752
+ getDataUrl(operation: string, path?: string): string
4348
3753
  }
4349
3754
 
4350
3755
  /** @internal */
@@ -4714,6 +4119,309 @@ export declare type TransactionMutationOptions =
4714
4119
  | TransactionAllDocumentsMutationOptions
4715
4120
  | TransactionAllDocumentIdsMutationOptions
4716
4121
 
4122
+ /** @beta */
4123
+ export declare type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
4124
+ | TransformDocumentSync<T>
4125
+ | TransformDocumentAsync
4126
+
4127
+ /** @beta */
4128
+ declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
4129
+
4130
+ /** @beta */
4131
+ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
4132
+ TransformRequestBase & AgentActionSync
4133
+
4134
+ /** @beta */
4135
+ declare interface TransformRequestBase extends AgentActionRequestBase {
4136
+ /** schemaId as reported by sanity deploy / sanity schema store */
4137
+ schemaId: string
4138
+ /**
4139
+ * The source document the transformation will use as input.
4140
+ */
4141
+ documentId: string
4142
+ /**
4143
+ * The source document's content is first copied to the target,
4144
+ * then it is transformed according to the instruction.
4145
+ *
4146
+ * When omitted, the source document (documentId) is also the target document.
4147
+ */
4148
+ targetDocument?: TransformTargetDocument
4149
+ /**
4150
+ * Instruct the LLM how to transform the input to th output.
4151
+ *
4152
+ * String template using $variable from instructionParams.
4153
+ *
4154
+ * Capped to 2000 characters, after variables has been injected.
4155
+ * */
4156
+ instruction: string
4157
+ /**
4158
+ *
4159
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
4160
+ *
4161
+ * ### Examples
4162
+ *
4163
+ * #### Constant
4164
+ *
4165
+ * ##### Shorthand
4166
+ * ```ts
4167
+ * client.agent.action.generate({
4168
+ * schemaId,
4169
+ * documentId,
4170
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
4171
+ * instructionParams: {
4172
+ * topic: 'Grapefruit'
4173
+ * },
4174
+ * })
4175
+ * ```
4176
+ * ##### Object-form
4177
+ *
4178
+ * ```ts
4179
+ * client.agent.action.transform({
4180
+ * schemaId,
4181
+ * documentId,
4182
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
4183
+ * instructionParams: {
4184
+ * topic: {
4185
+ * type: 'constant',
4186
+ * value: 'Grapefruit'
4187
+ * },
4188
+ * },
4189
+ * })
4190
+ * ```
4191
+ * #### Field
4192
+ * ```ts
4193
+ * client.agent.action.transform({
4194
+ * schemaId,
4195
+ * documentId,
4196
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
4197
+ * instructionParams: {
4198
+ * pte: {
4199
+ * type: 'field',
4200
+ * path: ['pteField'],
4201
+ * },
4202
+ * },
4203
+ * target: {path: 'keywords' }
4204
+ * })
4205
+ * ```
4206
+ * #### Document
4207
+ * ```ts
4208
+ * client.agent.action.transform({
4209
+ * schemaId,
4210
+ * documentId,
4211
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
4212
+ * instructionParams: {
4213
+ * document: {
4214
+ * type: 'document',
4215
+ * },
4216
+ * },
4217
+ * target: {path: 'keywords' }
4218
+ * })
4219
+ * ```
4220
+ *
4221
+ * #### GROQ
4222
+ * ```ts
4223
+ * client.agent.action.transform({
4224
+ * schemaId,
4225
+ * documentId,
4226
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
4227
+ * instructionParams: {
4228
+ * list: {
4229
+ * type: 'groq',
4230
+ * query: '* [_type==$type].title',
4231
+ * params: {type: 'article'}
4232
+ * },
4233
+ * },
4234
+ * target: {path: 'title'}
4235
+ * })
4236
+ * ```
4237
+ * */
4238
+ instructionParams?: AgentActionParams
4239
+ /**
4240
+ * Target defines which parts of the document will be affected by the instruction.
4241
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
4242
+ *
4243
+ * Omitting target implies that the document itself is the root.
4244
+ *
4245
+ * Notes:
4246
+ * - instruction can only affect fields up to `maxPathDepth`
4247
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
4248
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
4249
+ *
4250
+ * Default max depth for transform: 12
4251
+ * @see AgentActionRequestBase#conditionalPaths
4252
+ */
4253
+ target?: TransformTarget | TransformTarget[]
4254
+ }
4255
+
4256
+ /** @beta */
4257
+ export declare interface TransformTarget extends AgentActionTarget {
4258
+ /**
4259
+ * Specifies a tailored instruction of this target.
4260
+ *
4261
+ * string template using $variable from instructionParams.
4262
+ * */
4263
+ instruction?: string
4264
+ /**
4265
+ * By default, all children up to `target.maxPathDepth` are included.
4266
+ *
4267
+ * When `include` is specified, only segments explicitly listed will be included.
4268
+ *
4269
+ * Fields or array items not on the include list, are implicitly excluded.
4270
+ */
4271
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
4272
+ }
4273
+
4274
+ /** @beta */
4275
+ export declare type TransformTargetDocument =
4276
+ | {
4277
+ operation: 'edit'
4278
+ _id: string
4279
+ }
4280
+ | {
4281
+ operation: 'create'
4282
+ _id?: string
4283
+ }
4284
+ | {
4285
+ operation: 'createIfNotExists'
4286
+ _id: string
4287
+ }
4288
+ | {
4289
+ operation: 'createOrReplace'
4290
+ _id: string
4291
+ }
4292
+
4293
+ /** @beta */
4294
+ export declare interface TransformTargetInclude extends AgentActionTargetInclude {
4295
+ /**
4296
+ * Specifies a tailored instruction of this target.
4297
+ *
4298
+ * string template using $variable from instructionParams */
4299
+ instruction?: string
4300
+ /**
4301
+ * By default, all children up to `target.maxPathDepth` are included.
4302
+ *
4303
+ * When `include` is specified, only segments explicitly listed will be included.
4304
+ *
4305
+ * Fields or array items not on the include list, are implicitly excluded.
4306
+ */
4307
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
4308
+ }
4309
+
4310
+ /** @beta */
4311
+ export declare type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
4312
+ | TranslateDocumentSync<T>
4313
+ | TranslateDocumentAsync
4314
+
4315
+ /** @beta */
4316
+ declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
4317
+
4318
+ /** @beta */
4319
+ declare type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
4320
+ TranslateRequestBase & AgentActionSync
4321
+
4322
+ /** @beta */
4323
+ declare interface TranslateLanguage {
4324
+ /**
4325
+ * Language code
4326
+ */
4327
+ id: string
4328
+ /**
4329
+ * While optional, it is recommended to provide a language title
4330
+ */
4331
+ title?: string
4332
+ }
4333
+
4334
+ /** @beta */
4335
+ declare interface TranslateRequestBase extends AgentActionRequestBase {
4336
+ /** schemaId as reported by sanity deploy / sanity schema store */
4337
+ schemaId: string
4338
+ /**
4339
+ * The source document the transformation will use as input.
4340
+ */
4341
+ documentId: string
4342
+ /**
4343
+ * The target document will first get content copied over from the source,
4344
+ * then it is translated according to the instruction.
4345
+ *
4346
+ * When omitted, the source document (documentId) is also the target document.
4347
+ */
4348
+ targetDocument?: TransformTargetDocument
4349
+ /**
4350
+ * While optional, it is recommended
4351
+ */
4352
+ fromLanguage?: TranslateLanguage
4353
+ toLanguage: TranslateLanguage
4354
+ /**
4355
+ * `styleGuide` can be used to tailor how the translation should be preformed.
4356
+ *
4357
+ * String template using $variable from styleGuideParams.
4358
+ *
4359
+ * Capped to 2000 characters, after variables has been injected.
4360
+ *
4361
+ * @see #protectedPhrases
4362
+ */
4363
+ styleGuide?: string
4364
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
4365
+ styleGuideParams?: AgentActionParams
4366
+ /**
4367
+ * When the input string contains any phrase from `protectedPhrases`, the LLM will be instructed not
4368
+ * to translate them.
4369
+ *
4370
+ * It is recommended to use `protectedPhrases` instead of `styleGuide` for deny-list words and phrases,
4371
+ * since it keeps token cost low, resulting in faster responses, and limits how much information the LLM
4372
+ * has to process, since only phrases that are actually in the input string will be included in the final prompt.
4373
+ */
4374
+ protectedPhrases?: string[]
4375
+ /**
4376
+ * When specified, the `toLanguage.id` will be stored in the specified path in the target document.
4377
+ *
4378
+ * The file _can_ be hidden: true (unlike other fields in the target, which will be ignored)
4379
+ */
4380
+ languageFieldPath?: AgentActionPathSegment | AgentActionPath
4381
+ /**
4382
+ * Target defines which parts of the document will be affected by the instruction.
4383
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
4384
+ *
4385
+ * Omitting target implies that the document itself is the root.
4386
+ *
4387
+ * Notes:
4388
+ * - instruction can only affect fields up to `maxPathDepth`
4389
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
4390
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
4391
+ *
4392
+ * @see AgentActionRequestBase#conditionalPaths
4393
+ */
4394
+ target?: TranslateTarget | TranslateTarget[]
4395
+ }
4396
+
4397
+ /** @beta */
4398
+ export declare interface TranslateTarget extends AgentActionTarget {
4399
+ /** string template using $variable from instructionParams */
4400
+ styleGuide?: string
4401
+ /**
4402
+ * By default, all children up to `target.maxPathDepth` are included.
4403
+ *
4404
+ * When `include` is specified, only segments explicitly listed will be included.
4405
+ *
4406
+ * Fields or array items not on the include list, are implicitly excluded.
4407
+ */
4408
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
4409
+ }
4410
+
4411
+ /** @beta */
4412
+ export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
4413
+ /** string template using $variable from instructionParams */
4414
+ styleGuide?: string
4415
+ /**
4416
+ * By default, all children up to `target.maxPathDepth` are included.
4417
+ *
4418
+ * When `include` is specified, only segments explicitly listed will be included.
4419
+ *
4420
+ * Fields or array items not on the include list, are implicitly excluded.
4421
+ */
4422
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
4423
+ }
4424
+
4717
4425
  /** @public */
4718
4426
  export declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
4719
4427
  filterResponse: false
@@ -4824,7 +4532,7 @@ export declare interface UploadClientConfig {
4824
4532
  }
4825
4533
 
4826
4534
  /** @public */
4827
- export declare class UsersClient implements UsersClientType {
4535
+ export declare class UsersClient {
4828
4536
  #private
4829
4537
  constructor(client: SanityClient, httpRequest: HttpRequest)
4830
4538
  /**
@@ -4835,16 +4543,6 @@ export declare class UsersClient implements UsersClientType {
4835
4543
  getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
4836
4544
  }
4837
4545
 
4838
- /** @internal */
4839
- declare interface UsersClientType {
4840
- /**
4841
- * Fetch a user by user ID
4842
- *
4843
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
4844
- */
4845
- getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
4846
- }
4847
-
4848
4546
  /**
4849
4547
  * @internal - it may have breaking changes in any release
4850
4548
  */