@sanity/client 7.0.1-canary.1 → 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,52 +366,6 @@ export declare class AssetsClient implements AssetsClientType {
110
366
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
111
367
  }
112
368
 
113
- /**
114
- * The interface implemented by the `AssetsClient` class.
115
- * When writing code that wants to take an instance of `AssetsClient` as input it's better to use this type,
116
- * as the `AssetsClient` class has private properties and thus TypeScript will consider the type incompatible
117
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
118
- * @public
119
- */
120
- declare interface AssetsClientType {
121
- /**
122
- * Uploads a file asset to the configured dataset
123
- *
124
- * @param assetType - Asset type (file)
125
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
126
- * @param options - Options to use for the upload
127
- */
128
- upload(
129
- assetType: 'file',
130
- body: UploadBody,
131
- options?: UploadClientConfig,
132
- ): Promise<SanityAssetDocument>
133
- /**
134
- * Uploads an image asset to the configured dataset
135
- *
136
- * @param assetType - Asset type (image)
137
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
138
- * @param options - Options to use for the upload
139
- */
140
- upload(
141
- assetType: 'image',
142
- body: UploadBody,
143
- options?: UploadClientConfig,
144
- ): Promise<SanityImageAssetDocument>
145
- /**
146
- * Uploads a file or an image asset to the configured dataset
147
- *
148
- * @param assetType - Asset type (file/image)
149
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
150
- * @param options - Options to use for the upload
151
- */
152
- upload(
153
- assetType: 'file' | 'image',
154
- body: UploadBody,
155
- options?: UploadClientConfig,
156
- ): Promise<SanityAssetDocument | SanityImageAssetDocument>
157
- }
158
-
159
369
  /** @internal */
160
370
  export declare type AttributeSet = {
161
371
  [key: string]: Any
@@ -521,6 +731,43 @@ export declare class ConnectionFailedError extends Error {
521
731
  readonly name = 'ConnectionFailedError'
522
732
  }
523
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
+
524
771
  /** @public */
525
772
  export declare interface ContentSourceMap {
526
773
  mappings: ContentSourceMapMappings
@@ -883,6 +1130,34 @@ export declare type DisconnectEvent = {
883
1130
  reason: string
884
1131
  }
885
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
+
886
1161
  /**
887
1162
  * Modifies an existing draft document.
888
1163
  * It applies the given patch to the document referenced by draftId.
@@ -944,6 +1219,41 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
944
1219
  */
945
1220
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
946
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
+
947
1257
  /** @public */
948
1258
  export declare type FilterDefault = (props: {
949
1259
  /**
@@ -1059,6 +1369,274 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1059
1369
  returnDocuments?: true
1060
1370
  }
1061
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
+
1062
1640
  /** @public */
1063
1641
  export declare type HttpRequest = {
1064
1642
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1198,15 +1776,6 @@ export declare interface ListenOptions {
1198
1776
  * @defaultValue `false`
1199
1777
  */
1200
1778
  includePreviousRevision?: boolean
1201
- /**
1202
- * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
1203
- * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
1204
- * If you need events from drafts and versions, set this to `true`.
1205
- * Note: Keep in mind that additional document variants may be introduced in the future, so it's
1206
- * recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
1207
- * explicitly checking whether the event is for a draft or a version.
1208
- * @defaultValue `false`
1209
- */
1210
1779
  includeAllVersions?: boolean
1211
1780
  /**
1212
1781
  * Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
@@ -1508,8 +2077,53 @@ export declare type MutationSelectionQueryParams = {
1508
2077
  [key: string]: Any
1509
2078
  }
1510
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
+
1511
2125
  /** @internal */
1512
- export declare class ObservableAssetsClient implements ObservableAssetsClientType {
2126
+ export declare class ObservableAssetsClient {
1513
2127
  #private
1514
2128
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1515
2129
  /**
@@ -1562,73 +2176,15 @@ export declare class ObservableAssetsClient implements ObservableAssetsClientTyp
1562
2176
  >
1563
2177
  }
1564
2178
 
1565
- /**
1566
- * The interface implemented by the `ObservableAssetsClient` class.
1567
- * When writing code that wants to take an instance of `ObservableAssetsClient` as input it's better to use this type,
1568
- * as the `ObservableAssetsClient` class has private properties and thus TypeScript will consider the type incompatible
1569
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
1570
- * @public
1571
- */
1572
- declare interface ObservableAssetsClientType {
2179
+ /** @internal */
2180
+ export declare class ObservableDatasetsClient {
2181
+ #private
2182
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1573
2183
  /**
1574
- * Uploads a file asset to the configured dataset
2184
+ * Create a new dataset with the given name
1575
2185
  *
1576
- * @param assetType - Asset type (file)
1577
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1578
- * @param options - Options to use for the upload
1579
- */
1580
- upload(
1581
- assetType: 'file',
1582
- body: UploadBody,
1583
- options?: UploadClientConfig,
1584
- ): Observable<
1585
- HttpRequestEvent<{
1586
- document: SanityAssetDocument
1587
- }>
1588
- >
1589
- /**
1590
- * Uploads an image asset to the configured dataset
1591
- *
1592
- * @param assetType - Asset type (image)
1593
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1594
- * @param options - Options to use for the upload
1595
- */
1596
- upload(
1597
- assetType: 'image',
1598
- body: UploadBody,
1599
- options?: UploadClientConfig,
1600
- ): Observable<
1601
- HttpRequestEvent<{
1602
- document: SanityImageAssetDocument
1603
- }>
1604
- >
1605
- /**
1606
- * Uploads a file or an image asset to the configured dataset
1607
- *
1608
- * @param assetType - Asset type (file/image)
1609
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1610
- * @param options - Options to use for the upload
1611
- */
1612
- upload(
1613
- assetType: 'file' | 'image',
1614
- body: UploadBody,
1615
- options?: UploadClientConfig,
1616
- ): Observable<
1617
- HttpRequestEvent<{
1618
- document: SanityAssetDocument | SanityImageAssetDocument
1619
- }>
1620
- >
1621
- }
1622
-
1623
- /** @internal */
1624
- export declare class ObservableDatasetsClient {
1625
- #private
1626
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1627
- /**
1628
- * Create a new dataset with the given name
1629
- *
1630
- * @param name - Name of the dataset to create
1631
- * @param options - Options for the dataset
2186
+ * @param name - Name of the dataset to create
2187
+ * @param options - Options for the dataset
1632
2188
  */
1633
2189
  create(
1634
2190
  name: string,
@@ -1723,7 +2279,7 @@ export declare class ObservableProjectsClient {
1723
2279
  * Fetch a list of projects the authenticated user has access to.
1724
2280
  *
1725
2281
  * @param options - Options for the list request
1726
- * @param options.includeMembers - Whether to include members in the response (default: true)
2282
+ * - `includeMembers` - Whether to include members in the response (default: true)
1727
2283
  */
1728
2284
  list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1729
2285
  list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
@@ -1736,13 +2292,19 @@ export declare class ObservableProjectsClient {
1736
2292
  }
1737
2293
 
1738
2294
  /** @public */
1739
- export declare class ObservableSanityClient implements ObservableSanityClientType {
2295
+ export declare class ObservableSanityClient {
1740
2296
  #private
1741
2297
  assets: ObservableAssetsClient
1742
2298
  datasets: ObservableDatasetsClient
1743
2299
  live: LiveClient
1744
2300
  projects: ObservableProjectsClient
1745
2301
  users: ObservableUsersClient
2302
+ agent: {
2303
+ action: ObservableAgentsActionClient
2304
+ }
2305
+ /**
2306
+ * Instance properties
2307
+ */
1746
2308
  listen: typeof _listen
1747
2309
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1748
2310
  /**
@@ -1801,7 +2363,7 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
1801
2363
  Q extends QueryWithoutParams | QueryParams = QueryParams,
1802
2364
  const G extends string = string,
1803
2365
  >(
1804
- query: G,
2366
+ query: string,
1805
2367
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1806
2368
  options: UnfilteredResponseQueryOptions,
1807
2369
  ): Observable<RawQueryResponse<ClientReturn<G, R>>>
@@ -2237,1496 +2799,456 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
2237
2799
  }
2238
2800
 
2239
2801
  /**
2240
- * The interface implemented by the `ObservableSanityClient` class.
2241
- * When writing code that wants to take an instance of `ObservableSanityClient` as input it's better to use this type,
2242
- * as the `ObservableSanityClient` class has private properties and thus TypeScrict will consider the type incompatible
2243
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
2802
+ * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead
2244
2803
  * @public
2245
2804
  */
2246
- export declare interface ObservableSanityClientType extends SanityClientBase {
2247
- assets: ObservableAssetsClient
2248
- datasets: ObservableDatasetsClient
2249
- projects: ObservableProjectsClient
2250
- users: ObservableUsersClient
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)
2251
2811
  /**
2252
- * Clone the client - returns a new instance
2812
+ * Clones the transaction
2253
2813
  */
2254
- clone(): ObservableSanityClientType
2814
+ clone(): ObservableTransaction
2255
2815
  /**
2256
- * 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
2257
2819
  */
2258
- config(): InitializedClientConfig
2820
+ commit<R extends Record<string, Any>>(
2821
+ options: TransactionFirstDocumentMutationOptions,
2822
+ ): Observable<SanityDocument<R>>
2259
2823
  /**
2260
- * 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
2261
2827
  */
2262
- config(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2828
+ commit<R extends Record<string, Any>>(
2829
+ options: TransactionAllDocumentsMutationOptions,
2830
+ ): Observable<SanityDocument<R>[]>
2263
2831
  /**
2264
- * Clone the client with a new (partial) configuration.
2832
+ * Commit the transaction, returning an observable that produces a mutation result object
2265
2833
  *
2266
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
2834
+ * @param options - Options for the mutation operation
2267
2835
  */
2268
- withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2836
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2269
2837
  /**
2270
- * Perform a GROQ-query against the configured dataset.
2838
+ * Commit the transaction, returning an observable that produces a mutation result object
2271
2839
  *
2272
- * @param query - GROQ-query to perform
2840
+ * @param options - Options for the mutation operation
2273
2841
  */
2274
- fetch<
2275
- R = Any,
2276
- Q extends QueryWithoutParams = QueryWithoutParams,
2277
- const G extends string = string,
2278
- >(
2279
- query: G,
2280
- params?: Q | QueryWithoutParams,
2281
- ): Observable<ClientReturn<G, R>>
2842
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2282
2843
  /**
2283
- * Perform a GROQ-query against the configured dataset.
2844
+ * Commit the transaction, returning an observable that produces a mutation result object
2284
2845
  *
2285
- * @param query - GROQ-query to perform
2286
- * @param params - Optional query parameters
2287
- * @param options - Optional request options
2846
+ * @param options - Options for the mutation operation
2288
2847
  */
2289
- fetch<
2290
- R = Any,
2291
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2292
- const G extends string = string,
2293
- >(
2294
- query: G,
2295
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2296
- options?: FilteredResponseQueryOptions,
2297
- ): Observable<ClientReturn<G, R>>
2848
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2298
2849
  /**
2299
- * 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()`
2300
2852
  *
2301
- * @param query - GROQ-query to perform
2302
- * @param params - Optional query parameters
2303
- * @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
2304
2855
  */
2305
- fetch<
2306
- R = Any,
2307
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2308
- const G extends string = string,
2309
- >(
2310
- query: G,
2311
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2312
- options: UnfilteredResponseQueryOptions,
2313
- ): Observable<RawQueryResponse<ClientReturn<G, R>>>
2856
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2314
2857
  /**
2315
- * 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()`
2316
2860
  *
2317
- * @param query - GROQ-query to perform
2318
- * @param params - Optional query parameters
2319
- * @param options - Request options
2861
+ * @param patch - ObservablePatch to execute
2320
2862
  */
2321
- fetch<
2322
- R = Any,
2323
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2324
- const G extends string = string,
2325
- >(
2326
- query: G,
2327
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2328
- options: UnfilteredResponseWithoutQuery,
2329
- ): 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)
2330
2870
  /**
2331
- * Fetch a single document with the given ID.
2871
+ * Fetch a user by user ID
2332
2872
  *
2333
- * @param id - Document ID to fetch
2334
- * @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.
2335
2874
  */
2336
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
2337
- id: string,
2338
- options?: {
2339
- tag?: string
2340
- },
2341
- ): 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)
2342
2893
  /**
2343
- * Fetch multiple documents in one request.
2344
- * Should be used sparingly - performing a query is usually a better option.
2345
- * The order/position of documents is preserved based on the original array of IDs.
2346
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2347
- *
2348
- * @param ids - Document IDs to fetch
2349
- * @param options - Request options
2894
+ * Clones the patch
2350
2895
  */
2351
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2352
- ids: string[],
2353
- options?: {
2354
- tag?: string
2355
- },
2356
- ): Observable<(SanityDocument<R> | null)[]>
2896
+ clone(): Patch
2357
2897
  /**
2358
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2359
- * Returns an observable that resolves to the created document.
2898
+ * Commit the patch, returning a promise that resolves to the first patched document
2360
2899
  *
2361
- * @param document - Document to create
2362
- * @param options - Mutation options
2900
+ * @param options - Options for the mutation operation
2363
2901
  */
2364
- create<R extends Record<string, Any> = Record<string, Any>>(
2365
- document: SanityDocumentStub<R>,
2902
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2366
2903
  options: FirstDocumentMutationOptions,
2367
- ): Observable<SanityDocument<R>>
2904
+ ): Promise<SanityDocument<R>>
2368
2905
  /**
2369
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2370
- * Returns an observable that resolves to an array containing the created document.
2906
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
2371
2907
  *
2372
- * @param document - Document to create
2373
- * @param options - Mutation options
2908
+ * @param options - Options for the mutation operation
2374
2909
  */
2375
- create<R extends Record<string, Any> = Record<string, Any>>(
2376
- document: SanityDocumentStub<R>,
2910
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2377
2911
  options: AllDocumentsMutationOptions,
2378
- ): Observable<SanityDocument<R>[]>
2912
+ ): Promise<SanityDocument<R>[]>
2379
2913
  /**
2380
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2381
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2914
+ * Commit the patch, returning a promise that resolves to a mutation result object
2382
2915
  *
2383
- * @param document - Document to create
2384
- * @param options - Mutation options
2916
+ * @param options - Options for the mutation operation
2385
2917
  */
2386
- create<R extends Record<string, Any> = Record<string, Any>>(
2387
- document: SanityDocumentStub<R>,
2388
- options: FirstDocumentIdMutationOptions,
2389
- ): Observable<SingleMutationResult>
2918
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2390
2919
  /**
2391
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2392
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2920
+ * Commit the patch, returning a promise that resolves to a mutation result object
2393
2921
  *
2394
- * @param document - Document to create
2395
- * @param options - Mutation options
2922
+ * @param options - Options for the mutation operation
2396
2923
  */
2397
- create<R extends Record<string, Any> = Record<string, Any>>(
2398
- document: SanityDocumentStub<R>,
2399
- options: AllDocumentIdsMutationOptions,
2400
- ): Observable<MultipleMutationResult>
2924
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2401
2925
  /**
2402
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2403
- * Returns an observable that resolves to the created document.
2926
+ * Commit the patch, returning a promise that resolves to the first patched document
2404
2927
  *
2405
- * @param document - Document to create
2406
- * @param options - Mutation options
2928
+ * @param options - Options for the mutation operation
2407
2929
  */
2408
- create<R extends Record<string, Any> = Record<string, Any>>(
2409
- document: SanityDocumentStub<R>,
2410
- options?: BaseMutationOptions,
2411
- ): Observable<SanityDocument<R>>
2412
- /**
2413
- * Create a document if no document with the same ID already exists.
2414
- * Returns an observable that resolves to the created document.
2415
- *
2416
- * @param document - Document to create
2417
- * @param options - Mutation options
2418
- */
2419
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2420
- document: IdentifiedSanityDocumentStub<R>,
2421
- options: FirstDocumentMutationOptions,
2422
- ): Observable<SanityDocument<R>>
2423
- /**
2424
- * Create a document if no document with the same ID already exists.
2425
- * Returns an observable that resolves to an array containing the created document.
2426
- *
2427
- * @param document - Document to create
2428
- * @param options - Mutation options
2429
- */
2430
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2431
- document: IdentifiedSanityDocumentStub<R>,
2432
- options: AllDocumentsMutationOptions,
2433
- ): Observable<SanityDocument<R>[]>
2434
- /**
2435
- * Create a document if no document with the same ID already exists.
2436
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2437
- *
2438
- * @param document - Document to create
2439
- * @param options - Mutation options
2440
- */
2441
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2442
- document: IdentifiedSanityDocumentStub<R>,
2443
- options: FirstDocumentIdMutationOptions,
2444
- ): Observable<SingleMutationResult>
2445
- /**
2446
- * Create a document if no document with the same ID already exists.
2447
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2448
- *
2449
- * @param document - Document to create
2450
- * @param options - Mutation options
2451
- */
2452
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2453
- document: IdentifiedSanityDocumentStub<R>,
2454
- options: AllDocumentIdsMutationOptions,
2455
- ): Observable<MultipleMutationResult>
2456
- /**
2457
- * Create a document if no document with the same ID already exists.
2458
- * Returns an observable that resolves to the created document.
2459
- *
2460
- * @param document - Document to create
2461
- * @param options - Mutation options
2462
- */
2463
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2464
- document: IdentifiedSanityDocumentStub<R>,
2465
- options?: BaseMutationOptions,
2466
- ): Observable<SanityDocument<R>>
2467
- /**
2468
- * Create a document if it does not exist, or replace a document with the same document ID
2469
- * Returns an observable that resolves to the created document.
2470
- *
2471
- * @param document - Document to either create or replace
2472
- * @param options - Mutation options
2473
- */
2474
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2475
- document: IdentifiedSanityDocumentStub<R>,
2476
- options: FirstDocumentMutationOptions,
2477
- ): Observable<SanityDocument<R>>
2478
- /**
2479
- * Create a document if it does not exist, or replace a document with the same document ID
2480
- * Returns an observable that resolves to an array containing the created document.
2481
- *
2482
- * @param document - Document to either create or replace
2483
- * @param options - Mutation options
2484
- */
2485
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2486
- document: IdentifiedSanityDocumentStub<R>,
2487
- options: AllDocumentsMutationOptions,
2488
- ): Observable<SanityDocument<R>[]>
2489
- /**
2490
- * Create a document if it does not exist, or replace a document with the same document ID
2491
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2492
- *
2493
- * @param document - Document to either create or replace
2494
- * @param options - Mutation options
2495
- */
2496
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2497
- document: IdentifiedSanityDocumentStub<R>,
2498
- options: FirstDocumentIdMutationOptions,
2499
- ): Observable<SingleMutationResult>
2500
- /**
2501
- * Create a document if it does not exist, or replace a document with the same document ID
2502
- * Returns an observable that resolves to a mutation result object containing the created document ID.
2503
- *
2504
- * @param document - Document to either create or replace
2505
- * @param options - Mutation options
2506
- */
2507
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2508
- document: IdentifiedSanityDocumentStub<R>,
2509
- options: AllDocumentIdsMutationOptions,
2510
- ): Observable<MultipleMutationResult>
2511
- /**
2512
- * Create a document if it does not exist, or replace a document with the same document ID
2513
- * Returns an observable that resolves to the created document.
2514
- *
2515
- * @param document - Document to either create or replace
2516
- * @param options - Mutation options
2517
- */
2518
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2519
- document: IdentifiedSanityDocumentStub<R>,
2520
- options?: BaseMutationOptions,
2521
- ): Observable<SanityDocument<R>>
2522
- /**
2523
- * Deletes a document with the given document ID.
2524
- * Returns an observable that resolves to the deleted document.
2525
- *
2526
- * @param id - Document ID to delete
2527
- * @param options - Options for the mutation
2528
- */
2529
- delete<R extends Record<string, Any> = Record<string, Any>>(
2530
- id: string,
2531
- options: FirstDocumentMutationOptions,
2532
- ): Observable<SanityDocument<R>>
2533
- /**
2534
- * Deletes a document with the given document ID.
2535
- * Returns an observable that resolves to an array containing the deleted document.
2536
- *
2537
- * @param id - Document ID to delete
2538
- * @param options - Options for the mutation
2539
- */
2540
- delete<R extends Record<string, Any> = Record<string, Any>>(
2541
- id: string,
2542
- options: AllDocumentsMutationOptions,
2543
- ): Observable<SanityDocument<R>[]>
2544
- /**
2545
- * Deletes a document with the given document ID.
2546
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2547
- *
2548
- * @param id - Document ID to delete
2549
- * @param options - Options for the mutation
2550
- */
2551
- delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2552
- /**
2553
- * Deletes a document with the given document ID.
2554
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2555
- *
2556
- * @param id - Document ID to delete
2557
- * @param options - Options for the mutation
2558
- */
2559
- delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2560
- /**
2561
- * Deletes a document with the given document ID.
2562
- * Returns an observable that resolves to the deleted document.
2563
- *
2564
- * @param id - Document ID to delete
2565
- * @param options - Options for the mutation
2566
- */
2567
- delete<R extends Record<string, Any> = Record<string, Any>>(
2568
- id: string,
2569
- options?: BaseMutationOptions,
2570
- ): Observable<SanityDocument<R>>
2571
- /**
2572
- * Deletes one or more documents matching the given query or document ID.
2573
- * Returns an observable that resolves to first deleted document.
2574
- *
2575
- * @param selection - An object with either an `id` or `query` key defining what to delete
2576
- * @param options - Options for the mutation
2577
- */
2578
- delete<R extends Record<string, Any> = Record<string, Any>>(
2579
- selection: MutationSelection,
2580
- options: FirstDocumentMutationOptions,
2581
- ): Observable<SanityDocument<R>>
2582
- /**
2583
- * Deletes one or more documents matching the given query or document ID.
2584
- * Returns an observable that resolves to an array containing the deleted documents.
2585
- *
2586
- * @param selection - An object with either an `id` or `query` key defining what to delete
2587
- * @param options - Options for the mutation
2588
- */
2589
- delete<R extends Record<string, Any> = Record<string, Any>>(
2590
- selection: MutationSelection,
2591
- options: AllDocumentsMutationOptions,
2592
- ): Observable<SanityDocument<R>[]>
2593
- /**
2594
- * Deletes one or more documents matching the given query or document ID.
2595
- * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
2596
- *
2597
- * @param selection - An object with either an `id` or `query` key defining what to delete
2598
- * @param options - Options for the mutation
2599
- */
2600
- delete(
2601
- selection: MutationSelection,
2602
- options: FirstDocumentIdMutationOptions,
2603
- ): Observable<SingleMutationResult>
2604
- /**
2605
- * Deletes one or more documents matching the given query or document ID.
2606
- * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
2607
- *
2608
- * @param selection - An object with either an `id` or `query` key defining what to delete
2609
- * @param options - Options for the mutation
2610
- */
2611
- delete(
2612
- selection: MutationSelection,
2613
- options: AllDocumentIdsMutationOptions,
2614
- ): Observable<MultipleMutationResult>
2615
- /**
2616
- * Deletes one or more documents matching the given query or document ID.
2617
- * Returns an observable that resolves to first deleted document.
2618
- *
2619
- * @param selection - An object with either an `id` or `query` key defining what to delete
2620
- * @param options - Options for the mutation
2621
- */
2622
- delete<R extends Record<string, Any> = Record<string, Any>>(
2623
- selection: MutationSelection,
2624
- options?: BaseMutationOptions,
2625
- ): Observable<SanityDocument<R>>
2626
- /**
2627
- * Perform mutation operations against the configured dataset
2628
- * Returns an observable that resolves to the first mutated document.
2629
- *
2630
- * @param operations - Mutation operations to execute
2631
- * @param options - Mutation options
2632
- */
2633
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2634
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2635
- options: FirstDocumentMutationOptions,
2636
- ): Observable<SanityDocument<R>>
2637
- /**
2638
- * Perform mutation operations against the configured dataset.
2639
- * Returns an observable that resolves to an array of the mutated documents.
2640
- *
2641
- * @param operations - Mutation operations to execute
2642
- * @param options - Mutation options
2643
- */
2644
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2645
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2646
- options: AllDocumentsMutationOptions,
2647
- ): Observable<SanityDocument<R>[]>
2648
- /**
2649
- * Perform mutation operations against the configured dataset
2650
- * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
2651
- *
2652
- * @param operations - Mutation operations to execute
2653
- * @param options - Mutation options
2654
- */
2655
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2656
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2657
- options: FirstDocumentIdMutationOptions,
2658
- ): Observable<SingleMutationResult>
2659
- /**
2660
- * Perform mutation operations against the configured dataset
2661
- * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
2662
- *
2663
- * @param operations - Mutation operations to execute
2664
- * @param options - Mutation options
2665
- */
2666
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2667
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2668
- options: AllDocumentIdsMutationOptions,
2669
- ): Observable<MultipleMutationResult>
2670
- /**
2671
- * Perform mutation operations against the configured dataset
2672
- * Returns an observable that resolves to the first mutated document.
2673
- *
2674
- * @param operations - Mutation operations to execute
2675
- * @param options - Mutation options
2676
- */
2677
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2678
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2679
- options?: BaseMutationOptions,
2680
- ): Observable<SanityDocument<R>>
2681
- /**
2682
- * Create a new buildable patch of operations to perform
2683
- *
2684
- * @param documentId - Document ID to patch
2685
- * @param operations - Optional object of patch operations to initialize the patch instance with
2686
- * @returns Patch instance - call `.commit()` to perform the operations defined
2687
- */
2688
- patch(documentId: string, operations?: PatchOperations): ObservablePatch
2689
- /**
2690
- * Create a new buildable patch of operations to perform
2691
- *
2692
- * @param documentIds - Array of document IDs to patch
2693
- * @param operations - Optional object of patch operations to initialize the patch instance with
2694
- * @returns Patch instance - call `.commit()` to perform the operations defined
2695
- */
2696
- patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
2697
- /**
2698
- * Create a new buildable patch of operations to perform
2699
- *
2700
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2701
- * @param operations - Optional object of patch operations to initialize the patch instance with
2702
- * @returns Patch instance - call `.commit()` to perform the operations defined
2703
- */
2704
- patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
2705
- /**
2706
- * Create a new buildable patch of operations to perform
2707
- *
2708
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
2709
- * @param operations - Optional object of patch operations to initialize the patch instance with
2710
- * @returns Patch instance - call `.commit()` to perform the operations defined
2711
- */
2712
- patch(selection: PatchSelection, operations?: PatchOperations): ObservablePatch
2713
- /**
2714
- * Create a new transaction of mutations
2715
- *
2716
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2717
- */
2718
- transaction<R extends Record<string, Any> = Record<string, Any>>(
2719
- operations?: Mutation<R>[],
2720
- ): ObservableTransaction
2721
- /**
2722
- * Perform action operations against the configured dataset
2723
- *
2724
- * @param operations - Action operation(s) to execute
2725
- * @param options - Action options
2726
- */
2727
- action(
2728
- operations: Action | Action[],
2729
- options?: BaseActionOptions,
2730
- ): Observable<SingleActionResult | MultipleActionResult>
2731
- /**
2732
- * Perform an HTTP request against the Sanity API
2733
- *
2734
- * @param options - Request options
2735
- */
2736
- request<R = Any>(options: RawRequestOptions): Observable<R>
2737
- }
2738
-
2739
- /**
2740
- * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead
2741
- * @public
2742
- */
2743
- export declare class ObservableSanityStegaClient extends ObservableSanityClient {}
2744
-
2745
- /** @public */
2746
- export declare class ObservableTransaction extends BaseTransaction {
2747
- #private
2748
- constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2749
- /**
2750
- * Clones the transaction
2751
- */
2752
- clone(): ObservableTransaction
2753
- /**
2754
- * Commit the transaction, returning an observable that produces the first mutated document
2755
- *
2756
- * @param options - Options for the mutation operation
2757
- */
2758
- commit<R extends Record<string, Any>>(
2759
- options: TransactionFirstDocumentMutationOptions,
2760
- ): Observable<SanityDocument<R>>
2761
- /**
2762
- * Commit the transaction, returning an observable that produces an array of the mutated documents
2763
- *
2764
- * @param options - Options for the mutation operation
2765
- */
2766
- commit<R extends Record<string, Any>>(
2767
- options: TransactionAllDocumentsMutationOptions,
2768
- ): Observable<SanityDocument<R>[]>
2769
- /**
2770
- * Commit the transaction, returning an observable that produces a mutation result object
2771
- *
2772
- * @param options - Options for the mutation operation
2773
- */
2774
- commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2775
- /**
2776
- * Commit the transaction, returning an observable that produces a mutation result object
2777
- *
2778
- * @param options - Options for the mutation operation
2779
- */
2780
- commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2781
- /**
2782
- * Commit the transaction, returning an observable that produces a mutation result object
2783
- *
2784
- * @param options - Options for the mutation operation
2785
- */
2786
- commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2787
- /**
2788
- * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2789
- * The operation is added to the current transaction, ready to be commited by `commit()`
2790
- *
2791
- * @param documentId - Document ID to perform the patch operation on
2792
- * @param patchOps - Operations to perform, or a builder function
2793
- */
2794
- patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2795
- /**
2796
- * Adds the given patch instance to the transaction.
2797
- * The operation is added to the current transaction, ready to be commited by `commit()`
2798
- *
2799
- * @param patch - ObservablePatch to execute
2800
- */
2801
- patch(patch: ObservablePatch): this
2802
- }
2803
-
2804
- /** @public */
2805
- export declare class ObservableUsersClient {
2806
- #private
2807
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2808
- /**
2809
- * Fetch a user by user ID
2810
- *
2811
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2812
- */
2813
- getById<T extends 'me' | string>(
2814
- id: T,
2815
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2816
- }
2817
-
2818
- /**
2819
- * The listener connection has been established
2820
- * note: it's usually a better option to use the 'welcome' event
2821
- * @public
2822
- */
2823
- export declare type OpenEvent = {
2824
- type: 'open'
2825
- }
2826
-
2827
- /** @public */
2828
- export declare class Patch extends BasePatch {
2829
- #private
2830
- constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2831
- /**
2832
- * Clones the patch
2833
- */
2834
- clone(): Patch
2835
- /**
2836
- * Commit the patch, returning a promise that resolves to the first patched document
2837
- *
2838
- * @param options - Options for the mutation operation
2839
- */
2840
- commit<R extends Record<string, Any> = Record<string, Any>>(
2841
- options: FirstDocumentMutationOptions,
2842
- ): Promise<SanityDocument<R>>
2843
- /**
2844
- * Commit the patch, returning a promise that resolves to an array of the mutated documents
2845
- *
2846
- * @param options - Options for the mutation operation
2847
- */
2848
- commit<R extends Record<string, Any> = Record<string, Any>>(
2849
- options: AllDocumentsMutationOptions,
2850
- ): Promise<SanityDocument<R>[]>
2851
- /**
2852
- * Commit the patch, returning a promise that resolves to a mutation result object
2853
- *
2854
- * @param options - Options for the mutation operation
2855
- */
2856
- commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2857
- /**
2858
- * Commit the patch, returning a promise that resolves to a mutation result object
2859
- *
2860
- * @param options - Options for the mutation operation
2861
- */
2862
- commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2863
- /**
2864
- * Commit the patch, returning a promise that resolves to the first patched document
2865
- *
2866
- * @param options - Options for the mutation operation
2867
- */
2868
- commit<R extends Record<string, Any> = Record<string, Any>>(
2869
- options?: BaseMutationOptions,
2870
- ): Promise<SanityDocument<R>>
2871
- }
2872
-
2873
- /** @public */
2874
- export declare type PatchBuilder = (patch: Patch) => Patch
2875
-
2876
- /** @internal */
2877
- export declare type PatchMutationOperation = PatchOperations & MutationSelection
2878
-
2879
- /** @internal */
2880
- export declare interface PatchOperations {
2881
- set?: {
2882
- [key: string]: Any
2883
- }
2884
- setIfMissing?: {
2885
- [key: string]: Any
2886
- }
2887
- diffMatchPatch?: {
2888
- [key: string]: Any
2889
- }
2890
- unset?: string[]
2891
- inc?: {
2892
- [key: string]: number
2893
- }
2894
- dec?: {
2895
- [key: string]: number
2896
- }
2897
- insert?: InsertPatch
2898
- ifRevisionID?: string
2899
- }
2900
-
2901
- /** @internal */
2902
- export declare type PatchSelection = string | string[] | MutationSelection
2903
-
2904
- /** @public */
2905
- declare interface ProgressEvent_2 {
2906
- type: 'progress'
2907
- stage: 'upload' | 'download'
2908
- percent: number
2909
- total?: number
2910
- loaded?: number
2911
- lengthComputable: boolean
2912
- }
2913
- export {ProgressEvent_2 as ProgressEvent}
2914
-
2915
- /** @internal */
2916
- export declare class ProjectsClient {
2917
- #private
2918
- constructor(client: SanityClient, httpRequest: HttpRequest)
2919
- /**
2920
- * Fetch a list of projects the authenticated user has access to.
2921
- *
2922
- * @param options - Options for the list request
2923
- * @param options.includeMembers - Whether to include members in the response (default: true)
2924
- */
2925
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2926
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
2927
- /**
2928
- * Fetch a project by project ID
2929
- *
2930
- * @param projectId - ID of the project to fetch
2931
- */
2932
- getById(projectId: string): Promise<SanityProject>
2933
- }
2934
-
2935
- /**
2936
- * Publishes a draft document.
2937
- * If a published version of the document already exists this is replaced by the current draft document.
2938
- * In either case the draft document is deleted.
2939
- * The optional revision id parameters can be used for optimistic locking to ensure
2940
- * that the draft and/or published versions of the document have not been changed by another client.
2941
- *
2942
- * @public
2943
- */
2944
- export declare type PublishAction = {
2945
- actionType: 'sanity.action.document.publish'
2946
- /**
2947
- * Draft document ID to publish
2948
- */
2949
- draftId: string
2950
- /**
2951
- * Draft revision ID to match
2952
- */
2953
- ifDraftRevisionId?: string
2954
- /**
2955
- * Published document ID to replace
2956
- */
2957
- publishedId: string
2958
- /**
2959
- * Published revision ID to match
2960
- */
2961
- ifPublishedRevisionId?: string
2962
- }
2963
-
2964
- /** @public */
2965
- export declare type QueryOptions =
2966
- | FilteredResponseQueryOptions
2967
- | UnfilteredResponseQueryOptions
2968
- | UnfilteredResponseWithoutQuery
2969
-
2970
- /** @public */
2971
- export declare interface QueryParams {
2972
- [key: string]: any
2973
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2974
- body?: never
2975
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2976
- cache?: 'next' extends keyof RequestInit ? never : any
2977
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2978
- filterResponse?: never
2979
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2980
- headers?: never
2981
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2982
- method?: never
2983
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2984
- next?: 'next' extends keyof RequestInit ? never : any
2985
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2986
- perspective?: never
2987
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2988
- query?: never
2989
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2990
- resultSourceMap?: never
2991
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2992
- returnQuery?: never
2993
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2994
- signal?: never
2995
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2996
- stega?: never
2997
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2998
- tag?: never
2999
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3000
- timeout?: never
3001
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3002
- token?: never
3003
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3004
- useCdn?: never
3005
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3006
- lastLiveEventId?: never
3007
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3008
- cacheMode?: never
3009
- }
3010
-
3011
- /**
3012
- * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3013
- * @public
3014
- */
3015
- export declare type QueryWithoutParams = Record<string, never> | undefined
3016
-
3017
- /** @public */
3018
- export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
3019
-
3020
- /** @public */
3021
- export declare interface RawQueryResponse<R> {
3022
- query: string
3023
- ms: number
3024
- result: R
3025
- resultSourceMap?: ContentSourceMap
3026
- /** Requires `apiVersion` to be `2021-03-25` or later. */
3027
- syncTags?: SyncTag[]
3028
- }
3029
-
3030
- /** @internal */
3031
- export declare interface RawRequestOptions {
3032
- url?: string
3033
- uri?: string
3034
- method?: string
3035
- token?: string
3036
- json?: boolean
3037
- tag?: string
3038
- useGlobalApi?: boolean
3039
- withCredentials?: boolean
3040
- query?: {
3041
- [key: string]: string | string[]
3042
- }
3043
- headers?: {
3044
- [key: string]: string
3045
- }
3046
- timeout?: number
3047
- proxy?: string
3048
- body?: Any
3049
- maxRedirects?: number
3050
- signal?: AbortSignal
3051
- }
3052
-
3053
- /**
3054
- * The listener has been disconnected, and a reconnect attempt is scheduled.
3055
- *
3056
- * @public
3057
- */
3058
- export declare type ReconnectEvent = {
3059
- type: 'reconnect'
3060
- }
3061
-
3062
- /**
3063
- * @public
3064
- * @deprecated – The `r`-prefix is not required, use `string` instead
3065
- */
3066
- export declare type ReleaseId = `r${string}`
3067
-
3068
- /**
3069
- * Replaces an existing draft document.
3070
- * At least one of the draft or published versions of the document must exist.
3071
- *
3072
- * @public
3073
- */
3074
- export declare type ReplaceDraftAction = {
3075
- actionType: 'sanity.action.document.replaceDraft'
3076
- /**
3077
- * Published document ID to create draft from, if draft does not exist
3078
- */
3079
- publishedId: string
3080
- /**
3081
- * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3082
- */
3083
- attributes: IdentifiedSanityDocumentStub
3084
- }
3085
-
3086
- /**
3087
- * @deprecated -- Use `import {requester} from '@sanity/client'` instead
3088
- * @public
3089
- */
3090
- export declare const requester: Requester
3091
-
3092
- /** @internal */
3093
- export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
3094
- url?: string
3095
- uri?: string
3096
- canUseCdn?: boolean
3097
- useCdn?: boolean
3098
- tag?: string
3099
- returnQuery?: boolean
3100
- resultSourceMap?: boolean | 'withKeyArraySelector'
3101
- perspective?: ClientPerspective
3102
- lastLiveEventId?: string
3103
- cacheMode?: 'noStale'
3104
- }
3105
-
3106
- /** @public */
3107
- export declare interface RequestOptions {
3108
- timeout?: number
3109
- token?: string
3110
- tag?: string
3111
- headers?: Record<string, string>
3112
- method?: string
3113
- query?: Any
3114
- body?: Any
3115
- signal?: AbortSignal
3116
- }
3117
-
3118
- /** @alpha */
3119
- export declare type ResolveStudioUrl = (
3120
- sourceDocument: ContentSourceMapDocuments_2[number],
3121
- ) => StudioUrl
3122
-
3123
- /** @public */
3124
- export declare interface ResponseEvent<T = unknown> {
3125
- type: 'response'
3126
- body: T
3127
- url: string
3128
- method: string
3129
- statusCode: number
3130
- statusMessage?: string
3131
- headers: Record<string, string>
3132
- }
3133
-
3134
- /** @public */
3135
- export declare interface ResponseQueryOptions extends RequestOptions {
3136
- perspective?: ClientPerspective
3137
- resultSourceMap?: boolean | 'withKeyArraySelector'
3138
- returnQuery?: boolean
3139
- useCdn?: boolean
3140
- stega?: boolean | StegaConfig
3141
- cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
3142
- next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
3143
- lastLiveEventId?: string | string[] | null
3144
- /**
3145
- * When set to `noStale`, APICDN will not return a cached response if the content is stale.
3146
- * Tradeoff between latency and freshness of content.
3147
- *
3148
- * Only to be used with live content queries and when useCdn is true.
3149
- */
3150
- cacheMode?: 'noStale'
3151
- }
3152
-
3153
- /** @internal */
3154
- export declare interface SanityAssetDocument extends SanityDocument {
3155
- url: string
3156
- path: string
3157
- size: number
3158
- assetId: string
3159
- mimeType: string
3160
- sha1hash: string
3161
- extension: string
3162
- uploadId?: string
3163
- originalFilename?: string
3164
- }
3165
-
3166
- /** @public */
3167
- export declare class SanityClient implements SanityClientType {
3168
- #private
3169
- assets: AssetsClient
3170
- datasets: DatasetsClient
3171
- live: LiveClient
3172
- projects: ProjectsClient
3173
- users: UsersClient
3174
- /**
3175
- * Observable version of the Sanity client, with the same configuration as the promise-based one
3176
- */
3177
- observable: ObservableSanityClient
3178
- listen: typeof _listen
3179
- constructor(httpRequest: HttpRequest, config?: ClientConfig)
3180
- /**
3181
- * Clone the client - returns a new instance
3182
- */
3183
- clone(): SanityClient
3184
- /**
3185
- * Returns the current client configuration
3186
- */
3187
- config(): InitializedClientConfig
3188
- /**
3189
- * Reconfigure the client. Note that this _mutates_ the current client.
3190
- */
3191
- config(newConfig?: Partial<ClientConfig>): this
3192
- /**
3193
- * Clone the client with a new (partial) configuration.
3194
- *
3195
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3196
- */
3197
- withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3198
- /**
3199
- * Perform a GROQ-query against the configured dataset.
3200
- *
3201
- * @param query - GROQ-query to perform
3202
- */
3203
- fetch<
3204
- R = Any,
3205
- Q extends QueryWithoutParams = QueryWithoutParams,
3206
- const G extends string = string,
3207
- >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3208
- /**
3209
- * Perform a GROQ-query against the configured dataset.
3210
- *
3211
- * @param query - GROQ-query to perform
3212
- * @param params - Optional query parameters
3213
- * @param options - Optional request options
3214
- */
3215
- fetch<
3216
- R = Any,
3217
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3218
- const G extends string = string,
3219
- >(
3220
- query: G,
3221
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3222
- options?: FilteredResponseQueryOptions,
3223
- ): Promise<ClientReturn<G, R>>
3224
- /**
3225
- * Perform a GROQ-query against the configured dataset.
3226
- *
3227
- * @param query - GROQ-query to perform
3228
- * @param params - Optional query parameters
3229
- * @param options - Request options
3230
- */
3231
- fetch<
3232
- R = Any,
3233
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3234
- const G extends string = string,
3235
- >(
3236
- query: G,
3237
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3238
- options: UnfilteredResponseQueryOptions,
3239
- ): Promise<RawQueryResponse<ClientReturn<G, R>>>
3240
- /**
3241
- * Perform a GROQ-query against the configured dataset.
3242
- *
3243
- * @param query - GROQ-query to perform
3244
- * @param params - Optional query parameters
3245
- * @param options - Request options
3246
- */
3247
- fetch<
3248
- R = Any,
3249
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3250
- const G extends string = string,
3251
- >(
3252
- query: G,
3253
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3254
- options: UnfilteredResponseWithoutQuery,
3255
- ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
3256
- /**
3257
- * Fetch a single document with the given ID.
3258
- *
3259
- * @param id - Document ID to fetch
3260
- * @param options - Request options
3261
- */
3262
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
3263
- id: string,
3264
- options?: {
3265
- signal?: AbortSignal
3266
- tag?: string
3267
- },
3268
- ): Promise<SanityDocument<R> | undefined>
3269
- /**
3270
- * Fetch multiple documents in one request.
3271
- * Should be used sparingly - performing a query is usually a better option.
3272
- * The order/position of documents is preserved based on the original array of IDs.
3273
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3274
- *
3275
- * @param ids - Document IDs to fetch
3276
- * @param options - Request options
3277
- */
3278
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
3279
- ids: string[],
3280
- options?: {
3281
- signal?: AbortSignal
3282
- tag?: string
3283
- },
3284
- ): Promise<(SanityDocument<R> | null)[]>
3285
- /**
3286
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3287
- * Returns a promise that resolves to the created document.
3288
- *
3289
- * @param document - Document to create
3290
- * @param options - Mutation options
3291
- */
3292
- create<R extends Record<string, Any> = Record<string, Any>>(
3293
- document: SanityDocumentStub<R>,
3294
- options: FirstDocumentMutationOptions,
3295
- ): Promise<SanityDocument<R>>
3296
- /**
3297
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3298
- * Returns a promise that resolves to an array containing the created document.
3299
- *
3300
- * @param document - Document to create
3301
- * @param options - Mutation options
3302
- */
3303
- create<R extends Record<string, Any> = Record<string, Any>>(
3304
- document: SanityDocumentStub<R>,
3305
- options: AllDocumentsMutationOptions,
3306
- ): Promise<SanityDocument<R>[]>
3307
- /**
3308
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3309
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3310
- *
3311
- * @param document - Document to create
3312
- * @param options - Mutation options
3313
- */
3314
- create<R extends Record<string, Any> = Record<string, Any>>(
3315
- document: SanityDocumentStub<R>,
3316
- options: FirstDocumentIdMutationOptions,
3317
- ): Promise<SingleMutationResult>
3318
- /**
3319
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3320
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3321
- *
3322
- * @param document - Document to create
3323
- * @param options - Mutation options
3324
- */
3325
- create<R extends Record<string, Any> = Record<string, Any>>(
3326
- document: SanityDocumentStub<R>,
3327
- options: AllDocumentIdsMutationOptions,
3328
- ): Promise<MultipleMutationResult>
3329
- /**
3330
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3331
- * Returns a promise that resolves to the created document.
3332
- *
3333
- * @param document - Document to create
3334
- * @param options - Mutation options
3335
- */
3336
- create<R extends Record<string, Any> = Record<string, Any>>(
3337
- document: SanityDocumentStub<R>,
3338
- options?: BaseMutationOptions,
3339
- ): Promise<SanityDocument<R>>
3340
- /**
3341
- * Create a document if no document with the same ID already exists.
3342
- * Returns a promise that resolves to the created document.
3343
- *
3344
- * @param document - Document to create
3345
- * @param options - Mutation options
3346
- */
3347
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3348
- document: IdentifiedSanityDocumentStub<R>,
3349
- options: FirstDocumentMutationOptions,
3350
- ): Promise<SanityDocument<R>>
3351
- /**
3352
- * Create a document if no document with the same ID already exists.
3353
- * Returns a promise that resolves to an array containing the created document.
3354
- *
3355
- * @param document - Document to create
3356
- * @param options - Mutation options
3357
- */
3358
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3359
- document: IdentifiedSanityDocumentStub<R>,
3360
- options: AllDocumentsMutationOptions,
3361
- ): Promise<SanityDocument<R>[]>
3362
- /**
3363
- * Create a document if no document with the same ID already exists.
3364
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3365
- *
3366
- * @param document - Document to create
3367
- * @param options - Mutation options
3368
- */
3369
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3370
- document: IdentifiedSanityDocumentStub<R>,
3371
- options: FirstDocumentIdMutationOptions,
3372
- ): Promise<SingleMutationResult>
3373
- /**
3374
- * Create a document if no document with the same ID already exists.
3375
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3376
- *
3377
- * @param document - Document to create
3378
- * @param options - Mutation options
3379
- */
3380
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3381
- document: IdentifiedSanityDocumentStub<R>,
3382
- options: AllDocumentIdsMutationOptions,
3383
- ): Promise<MultipleMutationResult>
3384
- /**
3385
- * Create a document if no document with the same ID already exists.
3386
- * Returns a promise that resolves to the created document.
3387
- *
3388
- * @param document - Document to create
3389
- * @param options - Mutation options
3390
- */
3391
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3392
- document: IdentifiedSanityDocumentStub<R>,
3393
- options?: BaseMutationOptions,
3394
- ): Promise<SanityDocument<R>>
3395
- /**
3396
- * Create a document if it does not exist, or replace a document with the same document ID
3397
- * Returns a promise that resolves to the created document.
3398
- *
3399
- * @param document - Document to either create or replace
3400
- * @param options - Mutation options
3401
- */
3402
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3403
- document: IdentifiedSanityDocumentStub<R>,
3404
- options: FirstDocumentMutationOptions,
3405
- ): Promise<SanityDocument<R>>
3406
- /**
3407
- * Create a document if it does not exist, or replace a document with the same document ID
3408
- * Returns a promise that resolves to an array containing the created document.
3409
- *
3410
- * @param document - Document to either create or replace
3411
- * @param options - Mutation options
3412
- */
3413
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3414
- document: IdentifiedSanityDocumentStub<R>,
3415
- options: AllDocumentsMutationOptions,
3416
- ): Promise<SanityDocument<R>[]>
3417
- /**
3418
- * Create a document if it does not exist, or replace a document with the same document ID
3419
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3420
- *
3421
- * @param document - Document to either create or replace
3422
- * @param options - Mutation options
3423
- */
3424
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3425
- document: IdentifiedSanityDocumentStub<R>,
3426
- options: FirstDocumentIdMutationOptions,
3427
- ): Promise<SingleMutationResult>
3428
- /**
3429
- * Create a document if it does not exist, or replace a document with the same document ID
3430
- * Returns a promise that resolves to a mutation result object containing the created document ID.
3431
- *
3432
- * @param document - Document to either create or replace
3433
- * @param options - Mutation options
3434
- */
3435
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3436
- document: IdentifiedSanityDocumentStub<R>,
3437
- options: AllDocumentIdsMutationOptions,
3438
- ): Promise<MultipleMutationResult>
3439
- /**
3440
- * Create a document if it does not exist, or replace a document with the same document ID
3441
- * Returns a promise that resolves to the created document.
3442
- *
3443
- * @param document - Document to either create or replace
3444
- * @param options - Mutation options
3445
- */
3446
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3447
- document: IdentifiedSanityDocumentStub<R>,
3448
- options?: BaseMutationOptions,
3449
- ): Promise<SanityDocument<R>>
3450
- /**
3451
- * Deletes a document with the given document ID.
3452
- * Returns a promise that resolves to the deleted document.
3453
- *
3454
- * @param id - Document ID to delete
3455
- * @param options - Options for the mutation
3456
- */
3457
- delete<R extends Record<string, Any> = Record<string, Any>>(
3458
- id: string,
3459
- options: FirstDocumentMutationOptions,
3460
- ): Promise<SanityDocument<R>>
3461
- /**
3462
- * Deletes a document with the given document ID.
3463
- * Returns a promise that resolves to an array containing the deleted document.
3464
- *
3465
- * @param id - Document ID to delete
3466
- * @param options - Options for the mutation
3467
- */
3468
- delete<R extends Record<string, Any> = Record<string, Any>>(
3469
- id: string,
3470
- options: AllDocumentsMutationOptions,
3471
- ): Promise<SanityDocument<R>[]>
3472
- /**
3473
- * Deletes a document with the given document ID.
3474
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3475
- *
3476
- * @param id - Document ID to delete
3477
- * @param options - Options for the mutation
3478
- */
3479
- delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3480
- /**
3481
- * Deletes a document with the given document ID.
3482
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3483
- *
3484
- * @param id - Document ID to delete
3485
- * @param options - Options for the mutation
3486
- */
3487
- delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3488
- /**
3489
- * Deletes a document with the given document ID.
3490
- * Returns a promise that resolves to the deleted document.
3491
- *
3492
- * @param id - Document ID to delete
3493
- * @param options - Options for the mutation
3494
- */
3495
- delete<R extends Record<string, Any> = Record<string, Any>>(
3496
- id: string,
3497
- options?: BaseMutationOptions,
3498
- ): Promise<SanityDocument<R>>
3499
- /**
3500
- * Deletes one or more documents matching the given query or document ID.
3501
- * Returns a promise that resolves to first deleted document.
3502
- *
3503
- * @param selection - An object with either an `id` or `query` key defining what to delete
3504
- * @param options - Options for the mutation
3505
- */
3506
- delete<R extends Record<string, Any> = Record<string, Any>>(
3507
- selection: MutationSelection,
3508
- options: FirstDocumentMutationOptions,
3509
- ): Promise<SanityDocument<R>>
3510
- /**
3511
- * Deletes one or more documents matching the given query or document ID.
3512
- * Returns a promise that resolves to an array containing the deleted documents.
3513
- *
3514
- * @param selection - An object with either an `id` or `query` key defining what to delete
3515
- * @param options - Options for the mutation
3516
- */
3517
- delete<R extends Record<string, Any> = Record<string, Any>>(
3518
- selection: MutationSelection,
3519
- options: AllDocumentsMutationOptions,
3520
- ): Promise<SanityDocument<R>[]>
3521
- /**
3522
- * Deletes one or more documents matching the given query or document ID.
3523
- * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
3524
- *
3525
- * @param selection - An object with either an `id` or `query` key defining what to delete
3526
- * @param options - Options for the mutation
3527
- */
3528
- delete(
3529
- selection: MutationSelection,
3530
- options: FirstDocumentIdMutationOptions,
3531
- ): Promise<SingleMutationResult>
3532
- /**
3533
- * Deletes one or more documents matching the given query or document ID.
3534
- * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
3535
- *
3536
- * @param selection - An object with either an `id` or `query` key defining what to delete
3537
- * @param options - Options for the mutation
3538
- */
3539
- delete(
3540
- selection: MutationSelection,
3541
- options: AllDocumentIdsMutationOptions,
3542
- ): Promise<MultipleMutationResult>
3543
- /**
3544
- * Deletes one or more documents matching the given query or document ID.
3545
- * Returns a promise that resolves to first deleted document.
3546
- *
3547
- * @param selection - An object with either an `id` or `query` key defining what to delete
3548
- * @param options - Options for the mutation
3549
- */
3550
- delete<R extends Record<string, Any> = Record<string, Any>>(
3551
- selection: MutationSelection,
3552
- options?: BaseMutationOptions,
3553
- ): Promise<SanityDocument<R>>
3554
- /**
3555
- * Perform mutation operations against the configured dataset
3556
- * Returns a promise that resolves to the first mutated document.
3557
- *
3558
- * @param operations - Mutation operations to execute
3559
- * @param options - Mutation options
3560
- */
3561
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3562
- operations: Mutation<R>[] | Patch | Transaction,
3563
- options: FirstDocumentMutationOptions,
3564
- ): Promise<SanityDocument<R>>
3565
- /**
3566
- * Perform mutation operations against the configured dataset.
3567
- * Returns a promise that resolves to an array of the mutated documents.
3568
- *
3569
- * @param operations - Mutation operations to execute
3570
- * @param options - Mutation options
3571
- */
3572
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3573
- operations: Mutation<R>[] | Patch | Transaction,
3574
- options: AllDocumentsMutationOptions,
3575
- ): Promise<SanityDocument<R>[]>
3576
- /**
3577
- * Perform mutation operations against the configured dataset
3578
- * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
3579
- *
3580
- * @param operations - Mutation operations to execute
3581
- * @param options - Mutation options
3582
- */
3583
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3584
- operations: Mutation<R>[] | Patch | Transaction,
3585
- options: FirstDocumentIdMutationOptions,
3586
- ): Promise<SingleMutationResult>
3587
- /**
3588
- * Perform mutation operations against the configured dataset
3589
- * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
3590
- *
3591
- * @param operations - Mutation operations to execute
3592
- * @param options - Mutation options
3593
- */
3594
- mutate<R extends Record<string, Any>>(
3595
- operations: Mutation<R>[] | Patch | Transaction,
3596
- options: AllDocumentIdsMutationOptions,
3597
- ): Promise<MultipleMutationResult>
3598
- /**
3599
- * Perform mutation operations against the configured dataset
3600
- * Returns a promise that resolves to the first mutated document.
3601
- *
3602
- * @param operations - Mutation operations to execute
3603
- * @param options - Mutation options
3604
- */
3605
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3606
- operations: Mutation<R>[] | Patch | Transaction,
2930
+ commit<R extends Record<string, Any> = Record<string, Any>>(
3607
2931
  options?: BaseMutationOptions,
3608
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)
3609
2981
  /**
3610
- * Create a new buildable patch of operations to perform
3611
- *
3612
- * @param documentId - Document ID to patch
3613
- * @param operations - Optional object of patch operations to initialize the patch instance with
3614
- * @returns Patch instance - call `.commit()` to perform the operations defined
3615
- */
3616
- patch(documentId: string, operations?: PatchOperations): Patch
3617
- /**
3618
- * Create a new buildable patch of operations to perform
3619
- *
3620
- * @param documentIds - Array of document IDs to patch
3621
- * @param operations - Optional object of patch operations to initialize the patch instance with
3622
- * @returns Patch instance - call `.commit()` to perform the operations defined
3623
- */
3624
- patch(documentIds: string[], operations?: PatchOperations): Patch
3625
- /**
3626
- * Create a new buildable patch of operations to perform
3627
- *
3628
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3629
- * @param operations - Optional object of patch operations to initialize the patch instance with
3630
- * @returns Patch instance - call `.commit()` to perform the operations defined
3631
- */
3632
- patch(selection: MutationSelection, operations?: PatchOperations): Patch
3633
- /**
3634
- * Create a new transaction of mutations
2982
+ * Fetch a list of projects the authenticated user has access to.
3635
2983
  *
3636
- * @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)
3637
2986
  */
3638
- transaction<R extends Record<string, Any> = Record<string, Any>>(
3639
- operations?: Mutation<R>[],
3640
- ): Transaction
2987
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2988
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3641
2989
  /**
3642
- * Perform action operations against the configured dataset
3643
- * Returns a promise that resolves to the transaction result
2990
+ * Fetch a project by project ID
3644
2991
  *
3645
- * @param operations - Action operation(s) to execute
3646
- * @param options - Action options
2992
+ * @param projectId - ID of the project to fetch
3647
2993
  */
3648
- action(
3649
- operations: Action | Action[],
3650
- options?: BaseActionOptions,
3651
- ): 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'
3652
3008
  /**
3653
- * Perform a request against the Sanity API
3654
- * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
3655
- *
3656
- * @param options - Request options
3657
- * @returns Promise resolving to the response body
3009
+ * Draft document ID to publish
3658
3010
  */
3659
- request<R = Any>(options: RawRequestOptions): Promise<R>
3011
+ draftId: string
3660
3012
  /**
3661
- * Perform an HTTP request a `/data` sub-endpoint
3662
- * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
3663
- *
3664
- * @deprecated - Use `request()` or your own HTTP library instead
3665
- * @param endpoint - Endpoint to hit (mutate, query etc)
3666
- * @param body - Request body
3667
- * @param options - Request options
3668
- * @internal
3013
+ * Draft revision ID to match
3669
3014
  */
3670
- dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
3015
+ ifDraftRevisionId?: string
3671
3016
  /**
3672
- * Get a Sanity API URL for the URI provided
3673
- *
3674
- * @param uri - URI/path to build URL for
3675
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
3017
+ * Published document ID to replace
3676
3018
  */
3677
- getUrl(uri: string, canUseCdn?: boolean): string
3019
+ publishedId: string
3678
3020
  /**
3679
- * Get a Sanity API URL for the data operation and path provided
3680
- *
3681
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3682
- * @param path - Path to append after the operation
3021
+ * Published revision ID to match
3683
3022
  */
3684
- 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
3685
3113
  }
3686
3114
 
3687
3115
  /**
3688
- * Shared base type for the `SanityClient` and `ObservableSanityClient` classes.
3689
- * 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
3690
3119
  */
3691
- declare interface SanityClientBase {
3692
- live: LiveClient
3693
- 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'
3694
3138
  /**
3695
- * Get a Sanity API URL for the URI provided
3696
- *
3697
- * @param uri - URI/path to build URL for
3698
- * @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
3699
3140
  */
3700
- getUrl(uri: string, canUseCdn?: boolean): string
3141
+ publishedId: string
3701
3142
  /**
3702
- * Get a Sanity API URL for the data operation and path provided
3703
- *
3704
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3705
- * @param path - Path to append after the operation
3143
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3706
3144
  */
3707
- getDataUrl(operation: string, path?: string): string
3145
+ attributes: IdentifiedSanityDocumentStub
3708
3146
  }
3709
3147
 
3710
3148
  /**
3711
- * The interface implemented by the `SanityClient` class.
3712
- * When writing code that wants to take an instance of `SanityClient` as input it's better to use this type,
3713
- * as the `SanityClient` class has private properties and thus TypeScrict will consider the type incompatible
3714
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
3149
+ * @deprecated -- Use `import {requester} from '@sanity/client'` instead
3715
3150
  * @public
3716
3151
  */
3717
- export declare interface SanityClientType extends SanityClientBase {
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
3718
3231
  assets: AssetsClient
3719
3232
  datasets: DatasetsClient
3233
+ live: LiveClient
3720
3234
  projects: ProjectsClient
3721
3235
  users: UsersClient
3236
+ agent: {
3237
+ action: AgentActionsClient
3238
+ }
3722
3239
  /**
3723
3240
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3724
3241
  */
3725
- observable: ObservableSanityClientType
3242
+ observable: ObservableSanityClient
3243
+ /**
3244
+ * Instance properties
3245
+ */
3246
+ listen: typeof _listen
3247
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
3726
3248
  /**
3727
3249
  * Clone the client - returns a new instance
3728
3250
  */
3729
- clone(): SanityClientType
3251
+ clone(): SanityClient
3730
3252
  /**
3731
3253
  * Returns the current client configuration
3732
3254
  */
@@ -3734,13 +3256,13 @@ export declare interface SanityClientType extends SanityClientBase {
3734
3256
  /**
3735
3257
  * Reconfigure the client. Note that this _mutates_ the current client.
3736
3258
  */
3737
- config(newConfig?: Partial<ClientConfig>): SanityClientType
3259
+ config(newConfig?: Partial<ClientConfig>): this
3738
3260
  /**
3739
3261
  * Clone the client with a new (partial) configuration.
3740
3262
  *
3741
3263
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3742
3264
  */
3743
- withConfig(newConfig?: Partial<ClientConfig>): SanityClientType
3265
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3744
3266
  /**
3745
3267
  * Perform a GROQ-query against the configured dataset.
3746
3268
  *
@@ -3750,10 +3272,7 @@ export declare interface SanityClientType extends SanityClientBase {
3750
3272
  R = Any,
3751
3273
  Q extends QueryWithoutParams = QueryWithoutParams,
3752
3274
  const G extends string = string,
3753
- >(
3754
- query: G,
3755
- params?: Q | QueryWithoutParams,
3756
- ): Promise<ClientReturn<G, R>>
3275
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3757
3276
  /**
3758
3277
  * Perform a GROQ-query against the configured dataset.
3759
3278
  *
@@ -4179,14 +3698,6 @@ export declare interface SanityClientType extends SanityClientBase {
4179
3698
  * @returns Patch instance - call `.commit()` to perform the operations defined
4180
3699
  */
4181
3700
  patch(selection: MutationSelection, operations?: PatchOperations): Patch
4182
- /**
4183
- * Create a new buildable patch of operations to perform
4184
- *
4185
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
4186
- * @param operations - Optional object of patch operations to initialize the patch instance with
4187
- * @returns Patch instance - call `.commit()` to perform the operations defined
4188
- */
4189
- patch(selection: PatchSelection, operations?: PatchOperations): Patch
4190
3701
  /**
4191
3702
  * Create a new transaction of mutations
4192
3703
  *
@@ -4225,6 +3736,20 @@ export declare interface SanityClientType extends SanityClientBase {
4225
3736
  * @internal
4226
3737
  */
4227
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
4228
3753
  }
4229
3754
 
4230
3755
  /** @internal */
@@ -4594,6 +4119,309 @@ export declare type TransactionMutationOptions =
4594
4119
  | TransactionAllDocumentsMutationOptions
4595
4120
  | TransactionAllDocumentIdsMutationOptions
4596
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
+
4597
4425
  /** @public */
4598
4426
  export declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
4599
4427
  filterResponse: false