@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.
package/dist/index.d.cts CHANGED
@@ -39,6 +39,262 @@ export declare interface ActionErrorItem {
39
39
  index: number
40
40
  }
41
41
 
42
+ /** @beta */
43
+ declare interface AgentActionAsync {
44
+ /**
45
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
46
+ * The instruction operation will carry on in the background.
47
+ *
48
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
49
+ *
50
+ * async: true is incompatible with noWrite, as async: true does not return the resulting document
51
+ */
52
+ async: true
53
+ }
54
+
55
+ /** @beta */
56
+ export declare type AgentActionParam =
57
+ | string
58
+ | ConstantAgentActionParam
59
+ | FieldAgentActionParam
60
+ | DocumentAgentActionParam
61
+ | GroqAgentActionParam
62
+
63
+ /** @beta */
64
+ export declare type AgentActionParams = Record<string, AgentActionParam>
65
+
66
+ /** @beta */
67
+ export declare type AgentActionPath = AgentActionPathSegment[]
68
+
69
+ /** @beta */
70
+ export declare type AgentActionPathSegment =
71
+ | string
72
+ | {
73
+ _key: string
74
+ }
75
+
76
+ /** @beta */
77
+ declare interface AgentActionRequestBase {
78
+ /** schemaId as reported by sanity deploy / sanity schema store */
79
+ schemaId: string
80
+ /**
81
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
82
+ *
83
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
84
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
85
+ *
86
+ * `conditionalPaths` param allows setting the default conditional value for
87
+ * `hidden` and `readOnly` to false,
88
+ * or individually set `hidden` and `readOnly` state for individual document paths.
89
+ *
90
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
91
+ * and cannot be changed via conditionalPaths
92
+ *
93
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
94
+ *
95
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
96
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
97
+ *
98
+ * @see GenerateRequestBase#target
99
+ */
100
+ conditionalPaths?: {
101
+ defaultReadOnly?: boolean
102
+ defaultHidden?: boolean
103
+ paths?: {
104
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
105
+ path: AgentActionPath
106
+ readOnly: boolean
107
+ hidden: boolean
108
+ }[]
109
+ }
110
+ /**
111
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
112
+ * Otherwise, such fields will be ignored.
113
+ */
114
+ localeSettings?: {
115
+ /**
116
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
117
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
118
+ *
119
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
120
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
121
+ *
122
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
123
+ */
124
+ locale: string
125
+ /**
126
+ * A valid IANA time zone identifier used to resolve relative and absolute
127
+ * date expressions to a specific point in time. Examples include
128
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
129
+ *
130
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
131
+ * based on the user's local time.
132
+ *
133
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
134
+ */
135
+ timeZone: string
136
+ }
137
+ /**
138
+ * Controls how much variance the instructions will run with.
139
+ *
140
+ * Value must be in the range [0, 1] (inclusive).
141
+ *
142
+ * Defaults:
143
+ * - generate: 0.3
144
+ * - translate: 0
145
+ * - transform: 0
146
+ */
147
+ temperature?: number
148
+ }
149
+
150
+ /** @public */
151
+ declare class AgentActionsClient {
152
+ #private
153
+ constructor(client: SanityClient, httpRequest: HttpRequest)
154
+ /**
155
+ * Run an instruction to generate content in a target document.
156
+ * @param request - instruction request
157
+ */
158
+ generate<DocumentShape extends Record<string, Any>>(
159
+ request: GenerateInstruction<DocumentShape>,
160
+ ): Promise<
161
+ (typeof request)['async'] extends true
162
+ ? {
163
+ _id: string
164
+ }
165
+ : IdentifiedSanityDocumentStub & DocumentShape
166
+ >
167
+ /**
168
+ * Transform a target document based on a source.
169
+ * @param request - translation request
170
+ */
171
+ transform<DocumentShape extends Record<string, Any>>(
172
+ request: TransformDocument<DocumentShape>,
173
+ ): Promise<
174
+ (typeof request)['async'] extends true
175
+ ? {
176
+ _id: string
177
+ }
178
+ : IdentifiedSanityDocumentStub & DocumentShape
179
+ >
180
+ /**
181
+ * Translate a target document based on a source.
182
+ * @param request - translation request
183
+ */
184
+ translate<DocumentShape extends Record<string, Any>>(
185
+ request: TranslateDocument<DocumentShape>,
186
+ ): Promise<
187
+ (typeof request)['async'] extends true
188
+ ? {
189
+ _id: string
190
+ }
191
+ : IdentifiedSanityDocumentStub & DocumentShape
192
+ >
193
+ }
194
+
195
+ /** @beta */
196
+ declare interface AgentActionSync {
197
+ /**
198
+ * By default, noWrite: false.
199
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
200
+ *
201
+ * When noWrite: true, the api will not mutate any documents nor emit presence.
202
+ * Ie, when true, no changes will be made to content-lake
203
+ *
204
+ * noWrite: true is incompatible with async: true,
205
+ * as noWrite implies that you will use the return value of the operation
206
+ */
207
+ noWrite?: boolean
208
+ /**
209
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
210
+ * The instruction operation will carry on in the background.
211
+ *
212
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
213
+ *
214
+ * async: true is incompatible with noWrite: true, as async: true does not return the resulting document
215
+ */
216
+ async?: false
217
+ }
218
+
219
+ /**
220
+ * @beta
221
+ */
222
+ export declare interface AgentActionTarget {
223
+ /**
224
+ * Root target path.
225
+ *
226
+ * Use this to have the instruction only affect a part of the document.
227
+ *
228
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
229
+ * and `types.exclude`.
230
+ *
231
+ * Example:
232
+ *
233
+ * `path: ['body', {_key: 'someKey'}, 'nestedObject']`
234
+ *
235
+ * Here, the instruction will only write to fields under the nestedObject.
236
+ *
237
+ * Default: [] = the document itself
238
+ *
239
+ * @see #AgentActionPathSegment
240
+ * @see #AgentActionPath
241
+ * */
242
+ path?: AgentActionPathSegment | AgentActionPath
243
+ /**
244
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
245
+ *
246
+ * Depth is based on path segments:
247
+ * - `title` has depth 1
248
+ * - `array[_key="no"].title` has depth 3
249
+ *
250
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
251
+ * negative impact on performance; both for runtime and quality of responses.
252
+ *
253
+ * Default: 4
254
+ */
255
+ maxPathDepth?: number
256
+ /**
257
+ * By default, all children up to `target.maxPathDepth` are included.
258
+ * Fields or array items not on the exclude list, are implicitly included.
259
+ */
260
+ exclude?: AgentActionPathSegment[]
261
+ /**
262
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
263
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
264
+ *
265
+ * `types.include` and `types.exclude` are mutually exclusive.
266
+ */
267
+ types?: AgentActionTypeConfig
268
+ }
269
+
270
+ /** @beta */
271
+ declare interface AgentActionTargetInclude {
272
+ path: AgentActionPathSegment | AgentActionPath
273
+ /**
274
+ * By default, all children up to `target.maxPathDepth` are included.
275
+ * Fields or array items not on the exclude list, are implicitly included.
276
+ */
277
+ exclude?: AgentActionPathSegment[]
278
+ /**
279
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
280
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
281
+ *
282
+ * `types.include` and `types.exclude` are mutually exclusive.
283
+ */
284
+ types?: AgentActionTypeConfig
285
+ }
286
+
287
+ /** @beta */
288
+ declare type AgentActionTypeConfig =
289
+ | {
290
+ include: string[]
291
+ exclude?: never
292
+ }
293
+ | {
294
+ exclude: string[]
295
+ include?: never
296
+ }
297
+
42
298
  /** @internal */
43
299
  export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
44
300
  returnFirst: false
@@ -75,7 +331,7 @@ export declare type AssetMetadataType =
75
331
  | 'none'
76
332
 
77
333
  /** @internal */
78
- export declare class AssetsClient implements AssetsClientType {
334
+ export declare class AssetsClient {
79
335
  #private
80
336
  constructor(client: SanityClient, httpRequest: HttpRequest)
81
337
  /**
@@ -116,52 +372,6 @@ export declare class AssetsClient implements AssetsClientType {
116
372
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
117
373
  }
118
374
 
119
- /**
120
- * The interface implemented by the `AssetsClient` class.
121
- * When writing code that wants to take an instance of `AssetsClient` as input it's better to use this type,
122
- * as the `AssetsClient` class has private properties and thus TypeScript will consider the type incompatible
123
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
124
- * @public
125
- */
126
- declare interface AssetsClientType {
127
- /**
128
- * Uploads a file asset to the configured dataset
129
- *
130
- * @param assetType - Asset type (file)
131
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
132
- * @param options - Options to use for the upload
133
- */
134
- upload(
135
- assetType: 'file',
136
- body: UploadBody,
137
- options?: UploadClientConfig,
138
- ): Promise<SanityAssetDocument>
139
- /**
140
- * Uploads an image asset to the configured dataset
141
- *
142
- * @param assetType - Asset type (image)
143
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
144
- * @param options - Options to use for the upload
145
- */
146
- upload(
147
- assetType: 'image',
148
- body: UploadBody,
149
- options?: UploadClientConfig,
150
- ): Promise<SanityImageAssetDocument>
151
- /**
152
- * Uploads a file or an image asset to the configured dataset
153
- *
154
- * @param assetType - Asset type (file/image)
155
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
156
- * @param options - Options to use for the upload
157
- */
158
- upload(
159
- assetType: 'file' | 'image',
160
- body: UploadBody,
161
- options?: UploadClientConfig,
162
- ): Promise<SanityAssetDocument | SanityImageAssetDocument>
163
- }
164
-
165
375
  /** @internal */
166
376
  export declare type AttributeSet = {
167
377
  [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
@@ -795,6 +1042,34 @@ export declare type DisconnectEvent = {
795
1042
  reason: string
796
1043
  }
797
1044
 
1045
+ /**
1046
+ *
1047
+ * Includes a LLM-friendly version of the document in the instruction
1048
+ *
1049
+ * ```ts
1050
+ * client.agent.action.generate({
1051
+ * schemaId,
1052
+ * documentId,
1053
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1054
+ * instructionParams: {
1055
+ * document: {
1056
+ * type: 'document',
1057
+ * },
1058
+ * },
1059
+ * target: {path: 'keywords' }
1060
+ * })
1061
+ * ```
1062
+ *
1063
+ * @beta
1064
+ * */
1065
+ export declare interface DocumentAgentActionParam {
1066
+ type: 'document'
1067
+ /**
1068
+ * If omitted, implicitly uses the documentId of the instruction target
1069
+ */
1070
+ documentId?: string
1071
+ }
1072
+
798
1073
  /**
799
1074
  * Modifies an existing draft document.
800
1075
  * It applies the given patch to the document referenced by draftId.
@@ -837,6 +1112,41 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
837
1112
  */
838
1113
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
839
1114
 
1115
+ /**
1116
+ *
1117
+ *
1118
+ * Includes a LLM-friendly version of the field value in the instruction
1119
+ *
1120
+ * ```ts
1121
+ * client.agent.action.generate({
1122
+ * schemaId,
1123
+ * documentId,
1124
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1125
+ * instructionParams: {
1126
+ * pte: {
1127
+ * type: 'field',
1128
+ * path: ['pteField'],
1129
+ * },
1130
+ * },
1131
+ * target: {path: 'keywords' }
1132
+ * })
1133
+ *
1134
+ * ```
1135
+ *
1136
+ * @beta
1137
+ * */
1138
+ export declare interface FieldAgentActionParam {
1139
+ type: 'field'
1140
+ /**
1141
+ * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1142
+ */
1143
+ path: AgentActionPathSegment | AgentActionPath
1144
+ /**
1145
+ * If omitted, implicitly uses the documentId of the instruction target
1146
+ */
1147
+ documentId?: string
1148
+ }
1149
+
840
1150
  /** @public */
841
1151
  export declare type FilterDefault = (props: {
842
1152
  /**
@@ -903,6 +1213,274 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
903
1213
  returnDocuments?: true
904
1214
  }
905
1215
 
1216
+ /** @beta */
1217
+ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1218
+ | GenerateExistingDocumentRequest
1219
+ | GenerateTargetDocumentRequest<T>
1220
+ ) &
1221
+ GenerateRequestBase &
1222
+ AgentActionAsync
1223
+
1224
+ /**
1225
+ * Instruction for an existing document.
1226
+ * @beta
1227
+ */
1228
+ declare interface GenerateExistingDocumentRequest {
1229
+ documentId: string
1230
+ createDocument?: never
1231
+ }
1232
+
1233
+ /** @beta */
1234
+ export declare type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> =
1235
+ | GenerateSyncInstruction<T>
1236
+ | GenerateAsyncInstruction<T>
1237
+
1238
+ /** @beta */
1239
+ export declare type GenerateOperation = 'set' | 'append' | 'mixed'
1240
+
1241
+ /** @beta */
1242
+ declare interface GenerateRequestBase extends AgentActionRequestBase {
1243
+ /** schemaId as reported by sanity deploy / sanity schema store */
1244
+ schemaId: string
1245
+ /**
1246
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
1247
+ *
1248
+ * The LLM only has access to information in the instruction, plus the target schema.
1249
+ *
1250
+ * string template using $variable
1251
+ * */
1252
+ instruction: string
1253
+ /**
1254
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
1255
+ *
1256
+ * ### Examples
1257
+ *
1258
+ * #### Constant
1259
+ *
1260
+ * ##### Shorthand
1261
+ * ```ts
1262
+ * client.agent.action.generate({
1263
+ * schemaId,
1264
+ * documentId,
1265
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1266
+ * instructionParams: {
1267
+ * topic: 'Grapefruit'
1268
+ * },
1269
+ * })
1270
+ * ```
1271
+ * ##### Object-form
1272
+ *
1273
+ * ```ts
1274
+ * client.agent.action.generate({
1275
+ * schemaId,
1276
+ * documentId,
1277
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1278
+ * instructionParams: {
1279
+ * topic: {
1280
+ * type: 'constant',
1281
+ * value: 'Grapefruit'
1282
+ * },
1283
+ * },
1284
+ * })
1285
+ * ```
1286
+ * #### Field
1287
+ * ```ts
1288
+ * client.agent.action.generate({
1289
+ * schemaId,
1290
+ * documentId,
1291
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1292
+ * instructionParams: {
1293
+ * pte: {
1294
+ * type: 'field',
1295
+ * path: ['pteField'],
1296
+ * },
1297
+ * },
1298
+ * target: {path: 'keywords' }
1299
+ * })
1300
+ * ```
1301
+ * #### Document
1302
+ * ```ts
1303
+ * client.agent.action.generate({
1304
+ * schemaId,
1305
+ * documentId,
1306
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1307
+ * instructionParams: {
1308
+ * document: {
1309
+ * type: 'document',
1310
+ * },
1311
+ * },
1312
+ * target: {path: 'keywords' }
1313
+ * })
1314
+ * ```
1315
+ *
1316
+ * #### GROQ
1317
+ * ```ts
1318
+ * client.agent.action.generate({
1319
+ * schemaId,
1320
+ * documentId,
1321
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1322
+ * instructionParams: {
1323
+ * list: {
1324
+ * type: 'groq',
1325
+ * query: '* [_type==$type].title',
1326
+ * params: {type: 'article'}
1327
+ * },
1328
+ * },
1329
+ * target: {path: 'title' }
1330
+ * })
1331
+ * ```
1332
+ * */
1333
+ instructionParams?: AgentActionParams
1334
+ /**
1335
+ * Target defines which parts of the document will be affected by the instruction.
1336
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
1337
+ *
1338
+ * Omitting target implies that the document itself is the root.
1339
+ *
1340
+ * Notes:
1341
+ * - instruction can only affect fields up to `maxPathDepth`
1342
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1343
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1344
+ *
1345
+ * @see AgentActionRequestBase#conditionalPaths
1346
+ */
1347
+ target?: GenerateTarget | GenerateTarget[]
1348
+ }
1349
+
1350
+ /** @beta */
1351
+ declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1352
+ | GenerateExistingDocumentRequest
1353
+ | GenerateTargetDocumentRequest<T>
1354
+ ) &
1355
+ GenerateRequestBase &
1356
+ AgentActionSync
1357
+
1358
+ /** @beta */
1359
+ export declare interface GenerateTarget extends AgentActionTarget {
1360
+ /**
1361
+ * Sets the default operation for all paths in the target.
1362
+ * Generate runs in `'mixed'` operation mode by default:
1363
+ * Changes are set in all non-array fields, and append to all array fields.
1364
+ *
1365
+ * ### Operation types
1366
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1367
+ * - `'append'`:
1368
+ * – array fields: appends new items to the end of the array,
1369
+ * - string fields: '"existing content" "new content"'
1370
+ * - text fields: '"existing content"\\n"new content"'
1371
+ * - number fields: existing + new
1372
+ * - other field types not mentioned will set instead (dates, url)
1373
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1374
+ *
1375
+ * The default operation can be overridden on a per-path basis using `include`.
1376
+ *
1377
+ * Nested fields inherit the operation specified by their parent and falls back to the
1378
+ * top level target operation if not otherwise specified.
1379
+ *
1380
+ * Use `include` to change the `operation` of individual fields or items.
1381
+ *
1382
+ * #### Appending in the middle of arrays
1383
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1384
+ *
1385
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1386
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1387
+ *
1388
+ * @see #AgentActionTargetInclude.operation
1389
+ * @see #include
1390
+ * @see #AgentActionTargetInclude.include
1391
+ */
1392
+ operation?: GenerateOperation
1393
+ /**
1394
+ * By default, all children up to `target.maxPathDepth` are included.
1395
+ *
1396
+ * When `include` is specified, only segments explicitly listed will be included.
1397
+ *
1398
+ * Fields or array items not on the include list, are implicitly excluded.
1399
+ */
1400
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1401
+ }
1402
+
1403
+ /** @beta */
1404
+ export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1405
+ | {
1406
+ operation: 'edit'
1407
+ _id: string
1408
+ }
1409
+ | {
1410
+ operation: 'create'
1411
+ _id?: string
1412
+ _type: string
1413
+ initialValues?: T
1414
+ }
1415
+ | {
1416
+ operation: 'createIfNotExists'
1417
+ _id: string
1418
+ _type: string
1419
+ initialValues?: T
1420
+ }
1421
+ | {
1422
+ operation: 'createOrReplace'
1423
+ _id: string
1424
+ _type: string
1425
+ initialValues?: T
1426
+ }
1427
+
1428
+ /**
1429
+ * Instruction to create a new document
1430
+ * @beta
1431
+ */
1432
+ declare interface GenerateTargetDocumentRequest<
1433
+ T extends Record<string, Any> = Record<string, Any>,
1434
+ > {
1435
+ targetDocument: GenerateTargetDocument<T>
1436
+ documentId?: never
1437
+ }
1438
+
1439
+ /** @beta */
1440
+ export declare interface GenerateTargetInclude extends AgentActionTargetInclude {
1441
+ /**
1442
+ * Sets the operation for this path, and all its children.
1443
+ * This overrides any operation set parents or the root target.
1444
+ * @see #GenerateTarget.operation
1445
+ * @see #include
1446
+ */
1447
+ operation?: GenerateOperation
1448
+ /**
1449
+ * By default, all children up to `target.maxPathDepth` are included.
1450
+ *
1451
+ * When `include` is specified, only segments explicitly listed will be included.
1452
+ *
1453
+ * Fields or array items not on the include list, are implicitly excluded.
1454
+ */
1455
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1456
+ }
1457
+
1458
+ /**
1459
+ * Includes a LLM-friendly version of GROQ query result in the instruction
1460
+ *
1461
+ * ```ts
1462
+ * client.agent.action.generate({
1463
+ * schemaId,
1464
+ * documentId,
1465
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1466
+ * instructionParams: {
1467
+ * list: {
1468
+ * type: 'groq',
1469
+ * query: '* [_type==$type].title',
1470
+ * params: {type: 'article'}
1471
+ * },
1472
+ * },
1473
+ * target: {path: 'title' }
1474
+ * })
1475
+ * ```
1476
+ * @beta
1477
+ * */
1478
+ export declare interface GroqAgentActionParam {
1479
+ type: 'groq'
1480
+ query: string
1481
+ params?: Record<string, string>
1482
+ }
1483
+
906
1484
  /** @public */
907
1485
  export declare type HttpRequest = {
908
1486
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1032,15 +1610,6 @@ export declare interface ListenOptions {
1032
1610
  * @defaultValue `false`
1033
1611
  */
1034
1612
  includePreviousRevision?: boolean
1035
- /**
1036
- * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
1037
- * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
1038
- * If you need events from drafts and versions, set this to `true`.
1039
- * Note: Keep in mind that additional document variants may be introduced in the future, so it's
1040
- * recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
1041
- * explicitly checking whether the event is for a draft or a version.
1042
- * @defaultValue `false`
1043
- */
1044
1613
  includeAllVersions?: boolean
1045
1614
  /**
1046
1615
  * Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
@@ -1335,8 +1904,53 @@ export declare type MutationSelectionQueryParams = {
1335
1904
  [key: string]: Any
1336
1905
  }
1337
1906
 
1907
+ /** @public */
1908
+ declare class ObservableAgentsActionClient {
1909
+ #private
1910
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1911
+ /**
1912
+ * Run an instruction to generate content in a target document.
1913
+ * @param request - instruction request
1914
+ */
1915
+ generate<DocumentShape extends Record<string, Any>>(
1916
+ request: GenerateInstruction<DocumentShape>,
1917
+ ): Observable<
1918
+ (typeof request)['async'] extends true
1919
+ ? {
1920
+ _id: string
1921
+ }
1922
+ : IdentifiedSanityDocumentStub & DocumentShape
1923
+ >
1924
+ /**
1925
+ * Transform a target document based on a source.
1926
+ * @param request - translation request
1927
+ */
1928
+ transform<DocumentShape extends Record<string, Any>>(
1929
+ request: TransformDocument<DocumentShape>,
1930
+ ): Observable<
1931
+ (typeof request)['async'] extends true
1932
+ ? {
1933
+ _id: string
1934
+ }
1935
+ : IdentifiedSanityDocumentStub & DocumentShape
1936
+ >
1937
+ /**
1938
+ * Translate a target document based on a source.
1939
+ * @param request - translation request
1940
+ */
1941
+ translate<DocumentShape extends Record<string, Any>>(
1942
+ request: TranslateDocument<DocumentShape>,
1943
+ ): Observable<
1944
+ (typeof request)['async'] extends true
1945
+ ? {
1946
+ _id: string
1947
+ }
1948
+ : IdentifiedSanityDocumentStub & DocumentShape
1949
+ >
1950
+ }
1951
+
1338
1952
  /** @internal */
1339
- export declare class ObservableAssetsClient implements ObservableAssetsClientType {
1953
+ export declare class ObservableAssetsClient {
1340
1954
  #private
1341
1955
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1342
1956
  /**
@@ -1389,73 +2003,15 @@ export declare class ObservableAssetsClient implements ObservableAssetsClientTyp
1389
2003
  >
1390
2004
  }
1391
2005
 
1392
- /**
1393
- * The interface implemented by the `ObservableAssetsClient` class.
1394
- * When writing code that wants to take an instance of `ObservableAssetsClient` as input it's better to use this type,
1395
- * as the `ObservableAssetsClient` class has private properties and thus TypeScript will consider the type incompatible
1396
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
1397
- * @public
1398
- */
1399
- declare interface ObservableAssetsClientType {
2006
+ /** @internal */
2007
+ export declare class ObservableDatasetsClient {
2008
+ #private
2009
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1400
2010
  /**
1401
- * Uploads a file asset to the configured dataset
2011
+ * Create a new dataset with the given name
1402
2012
  *
1403
- * @param assetType - Asset type (file)
1404
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1405
- * @param options - Options to use for the upload
1406
- */
1407
- upload(
1408
- assetType: 'file',
1409
- body: UploadBody,
1410
- options?: UploadClientConfig,
1411
- ): Observable<
1412
- HttpRequestEvent<{
1413
- document: SanityAssetDocument
1414
- }>
1415
- >
1416
- /**
1417
- * Uploads an image asset to the configured dataset
1418
- *
1419
- * @param assetType - Asset type (image)
1420
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1421
- * @param options - Options to use for the upload
1422
- */
1423
- upload(
1424
- assetType: 'image',
1425
- body: UploadBody,
1426
- options?: UploadClientConfig,
1427
- ): Observable<
1428
- HttpRequestEvent<{
1429
- document: SanityImageAssetDocument
1430
- }>
1431
- >
1432
- /**
1433
- * Uploads a file or an image asset to the configured dataset
1434
- *
1435
- * @param assetType - Asset type (file/image)
1436
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1437
- * @param options - Options to use for the upload
1438
- */
1439
- upload(
1440
- assetType: 'file' | 'image',
1441
- body: UploadBody,
1442
- options?: UploadClientConfig,
1443
- ): Observable<
1444
- HttpRequestEvent<{
1445
- document: SanityAssetDocument | SanityImageAssetDocument
1446
- }>
1447
- >
1448
- }
1449
-
1450
- /** @internal */
1451
- export declare class ObservableDatasetsClient {
1452
- #private
1453
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1454
- /**
1455
- * Create a new dataset with the given name
1456
- *
1457
- * @param name - Name of the dataset to create
1458
- * @param options - Options for the dataset
2013
+ * @param name - Name of the dataset to create
2014
+ * @param options - Options for the dataset
1459
2015
  */
1460
2016
  create(
1461
2017
  name: string,
@@ -1550,7 +2106,7 @@ export declare class ObservableProjectsClient {
1550
2106
  * Fetch a list of projects the authenticated user has access to.
1551
2107
  *
1552
2108
  * @param options - Options for the list request
1553
- * @param options.includeMembers - Whether to include members in the response (default: true)
2109
+ * - `includeMembers` - Whether to include members in the response (default: true)
1554
2110
  */
1555
2111
  list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1556
2112
  list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
@@ -1563,13 +2119,19 @@ export declare class ObservableProjectsClient {
1563
2119
  }
1564
2120
 
1565
2121
  /** @public */
1566
- export declare class ObservableSanityClient implements ObservableSanityClientType {
2122
+ export declare class ObservableSanityClient {
1567
2123
  #private
1568
2124
  assets: ObservableAssetsClient
1569
2125
  datasets: ObservableDatasetsClient
1570
2126
  live: LiveClient
1571
2127
  projects: ObservableProjectsClient
1572
2128
  users: ObservableUsersClient
2129
+ agent: {
2130
+ action: ObservableAgentsActionClient
2131
+ }
2132
+ /**
2133
+ * Instance properties
2134
+ */
1573
2135
  listen: typeof _listen
1574
2136
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1575
2137
  /**
@@ -1628,7 +2190,7 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
1628
2190
  Q extends QueryWithoutParams | QueryParams = QueryParams,
1629
2191
  const G extends string = string,
1630
2192
  >(
1631
- query: G,
2193
+ query: string,
1632
2194
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1633
2195
  options: UnfilteredResponseQueryOptions,
1634
2196
  ): Observable<RawQueryResponse<ClientReturn<G, R>>>
@@ -2063,1485 +2625,445 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
2063
2625
  getDataUrl(operation: string, path?: string): string
2064
2626
  }
2065
2627
 
2066
- /**
2067
- * The interface implemented by the `ObservableSanityClient` class.
2068
- * When writing code that wants to take an instance of `ObservableSanityClient` as input it's better to use this type,
2069
- * as the `ObservableSanityClient` class has private properties and thus TypeScrict will consider the type incompatible
2070
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
2071
- * @public
2072
- */
2073
- export declare interface ObservableSanityClientType extends SanityClientBase {
2074
- assets: ObservableAssetsClient
2075
- datasets: ObservableDatasetsClient
2076
- projects: ObservableProjectsClient
2077
- users: ObservableUsersClient
2628
+ /** @public */
2629
+ export declare class ObservableTransaction extends BaseTransaction {
2630
+ #private
2631
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2078
2632
  /**
2079
- * Clone the client - returns a new instance
2633
+ * Clones the transaction
2080
2634
  */
2081
- clone(): ObservableSanityClientType
2635
+ clone(): ObservableTransaction
2082
2636
  /**
2083
- * Returns the current client configuration
2637
+ * Commit the transaction, returning an observable that produces the first mutated document
2638
+ *
2639
+ * @param options - Options for the mutation operation
2084
2640
  */
2085
- config(): InitializedClientConfig
2641
+ commit<R extends Record<string, Any>>(
2642
+ options: TransactionFirstDocumentMutationOptions,
2643
+ ): Observable<SanityDocument<R>>
2086
2644
  /**
2087
- * Reconfigure the client. Note that this _mutates_ the current client.
2645
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
2646
+ *
2647
+ * @param options - Options for the mutation operation
2088
2648
  */
2089
- config(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2649
+ commit<R extends Record<string, Any>>(
2650
+ options: TransactionAllDocumentsMutationOptions,
2651
+ ): Observable<SanityDocument<R>[]>
2090
2652
  /**
2091
- * Clone the client with a new (partial) configuration.
2653
+ * Commit the transaction, returning an observable that produces a mutation result object
2092
2654
  *
2093
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
2655
+ * @param options - Options for the mutation operation
2094
2656
  */
2095
- withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2657
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2096
2658
  /**
2097
- * Perform a GROQ-query against the configured dataset.
2659
+ * Commit the transaction, returning an observable that produces a mutation result object
2098
2660
  *
2099
- * @param query - GROQ-query to perform
2661
+ * @param options - Options for the mutation operation
2100
2662
  */
2101
- fetch<
2102
- R = Any,
2103
- Q extends QueryWithoutParams = QueryWithoutParams,
2104
- const G extends string = string,
2105
- >(
2106
- query: G,
2107
- params?: Q | QueryWithoutParams,
2108
- ): Observable<ClientReturn<G, R>>
2663
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2109
2664
  /**
2110
- * Perform a GROQ-query against the configured dataset.
2665
+ * Commit the transaction, returning an observable that produces a mutation result object
2111
2666
  *
2112
- * @param query - GROQ-query to perform
2113
- * @param params - Optional query parameters
2114
- * @param options - Optional request options
2667
+ * @param options - Options for the mutation operation
2115
2668
  */
2116
- fetch<
2117
- R = Any,
2118
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2119
- const G extends string = string,
2120
- >(
2121
- query: G,
2122
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2123
- options?: FilteredResponseQueryOptions,
2124
- ): Observable<ClientReturn<G, R>>
2669
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2125
2670
  /**
2126
- * Perform a GROQ-query against the configured dataset.
2671
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2672
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2127
2673
  *
2128
- * @param query - GROQ-query to perform
2129
- * @param params - Optional query parameters
2130
- * @param options - Request options
2674
+ * @param documentId - Document ID to perform the patch operation on
2675
+ * @param patchOps - Operations to perform, or a builder function
2131
2676
  */
2132
- fetch<
2133
- R = Any,
2134
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2135
- const G extends string = string,
2136
- >(
2137
- query: G,
2138
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2139
- options: UnfilteredResponseQueryOptions,
2140
- ): Observable<RawQueryResponse<ClientReturn<G, R>>>
2677
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2141
2678
  /**
2142
- * Perform a GROQ-query against the configured dataset.
2679
+ * Adds the given patch instance to the transaction.
2680
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2143
2681
  *
2144
- * @param query - GROQ-query to perform
2145
- * @param params - Optional query parameters
2146
- * @param options - Request options
2682
+ * @param patch - ObservablePatch to execute
2147
2683
  */
2148
- fetch<
2149
- R = Any,
2150
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2151
- const G extends string = string,
2152
- >(
2153
- query: G,
2154
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2155
- options: UnfilteredResponseWithoutQuery,
2156
- ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2684
+ patch(patch: ObservablePatch): this
2685
+ }
2686
+
2687
+ /** @public */
2688
+ export declare class ObservableUsersClient {
2689
+ #private
2690
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2157
2691
  /**
2158
- * Fetch a single document with the given ID.
2692
+ * Fetch a user by user ID
2159
2693
  *
2160
- * @param id - Document ID to fetch
2161
- * @param options - Request options
2694
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2162
2695
  */
2163
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
2164
- id: string,
2165
- options?: {
2166
- tag?: string
2167
- },
2168
- ): Observable<SanityDocument<R> | undefined>
2696
+ getById<T extends 'me' | string>(
2697
+ id: T,
2698
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2699
+ }
2700
+
2701
+ /**
2702
+ * The listener connection has been established
2703
+ * note: it's usually a better option to use the 'welcome' event
2704
+ * @public
2705
+ */
2706
+ export declare type OpenEvent = {
2707
+ type: 'open'
2708
+ }
2709
+
2710
+ /** @public */
2711
+ export declare class Patch extends BasePatch {
2712
+ #private
2713
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2169
2714
  /**
2170
- * Fetch multiple documents in one request.
2171
- * Should be used sparingly - performing a query is usually a better option.
2172
- * The order/position of documents is preserved based on the original array of IDs.
2173
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2174
- *
2175
- * @param ids - Document IDs to fetch
2176
- * @param options - Request options
2715
+ * Clones the patch
2177
2716
  */
2178
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2179
- ids: string[],
2180
- options?: {
2181
- tag?: string
2182
- },
2183
- ): Observable<(SanityDocument<R> | null)[]>
2717
+ clone(): Patch
2184
2718
  /**
2185
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2186
- * Returns an observable that resolves to the created document.
2719
+ * Commit the patch, returning a promise that resolves to the first patched document
2187
2720
  *
2188
- * @param document - Document to create
2189
- * @param options - Mutation options
2721
+ * @param options - Options for the mutation operation
2190
2722
  */
2191
- create<R extends Record<string, Any> = Record<string, Any>>(
2192
- document: SanityDocumentStub<R>,
2723
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2193
2724
  options: FirstDocumentMutationOptions,
2194
- ): Observable<SanityDocument<R>>
2725
+ ): Promise<SanityDocument<R>>
2195
2726
  /**
2196
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2197
- * Returns an observable that resolves to an array containing the created document.
2727
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
2198
2728
  *
2199
- * @param document - Document to create
2200
- * @param options - Mutation options
2729
+ * @param options - Options for the mutation operation
2201
2730
  */
2202
- create<R extends Record<string, Any> = Record<string, Any>>(
2203
- document: SanityDocumentStub<R>,
2731
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2204
2732
  options: AllDocumentsMutationOptions,
2205
- ): Observable<SanityDocument<R>[]>
2733
+ ): Promise<SanityDocument<R>[]>
2206
2734
  /**
2207
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2208
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2735
+ * Commit the patch, returning a promise that resolves to a mutation result object
2209
2736
  *
2210
- * @param document - Document to create
2211
- * @param options - Mutation options
2737
+ * @param options - Options for the mutation operation
2212
2738
  */
2213
- create<R extends Record<string, Any> = Record<string, Any>>(
2214
- document: SanityDocumentStub<R>,
2215
- options: FirstDocumentIdMutationOptions,
2216
- ): Observable<SingleMutationResult>
2739
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2217
2740
  /**
2218
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2219
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2741
+ * Commit the patch, returning a promise that resolves to a mutation result object
2220
2742
  *
2221
- * @param document - Document to create
2222
- * @param options - Mutation options
2743
+ * @param options - Options for the mutation operation
2223
2744
  */
2224
- create<R extends Record<string, Any> = Record<string, Any>>(
2225
- document: SanityDocumentStub<R>,
2226
- options: AllDocumentIdsMutationOptions,
2227
- ): Observable<MultipleMutationResult>
2745
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2228
2746
  /**
2229
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2230
- * Returns an observable that resolves to the created document.
2747
+ * Commit the patch, returning a promise that resolves to the first patched document
2231
2748
  *
2232
- * @param document - Document to create
2233
- * @param options - Mutation options
2749
+ * @param options - Options for the mutation operation
2234
2750
  */
2235
- create<R extends Record<string, Any> = Record<string, Any>>(
2236
- document: SanityDocumentStub<R>,
2237
- options?: BaseMutationOptions,
2238
- ): Observable<SanityDocument<R>>
2239
- /**
2240
- * Create a document if no document with the same ID already exists.
2241
- * Returns an observable that resolves to the created document.
2242
- *
2243
- * @param document - Document to create
2244
- * @param options - Mutation options
2245
- */
2246
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2247
- document: IdentifiedSanityDocumentStub<R>,
2248
- options: FirstDocumentMutationOptions,
2249
- ): Observable<SanityDocument<R>>
2250
- /**
2251
- * Create a document if no document with the same ID already exists.
2252
- * Returns an observable that resolves to an array containing the created document.
2253
- *
2254
- * @param document - Document to create
2255
- * @param options - Mutation options
2256
- */
2257
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2258
- document: IdentifiedSanityDocumentStub<R>,
2259
- options: AllDocumentsMutationOptions,
2260
- ): Observable<SanityDocument<R>[]>
2261
- /**
2262
- * Create a document if no document with the same ID already exists.
2263
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2264
- *
2265
- * @param document - Document to create
2266
- * @param options - Mutation options
2267
- */
2268
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2269
- document: IdentifiedSanityDocumentStub<R>,
2270
- options: FirstDocumentIdMutationOptions,
2271
- ): Observable<SingleMutationResult>
2272
- /**
2273
- * Create a document if no document with the same ID already exists.
2274
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2275
- *
2276
- * @param document - Document to create
2277
- * @param options - Mutation options
2278
- */
2279
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2280
- document: IdentifiedSanityDocumentStub<R>,
2281
- options: AllDocumentIdsMutationOptions,
2282
- ): Observable<MultipleMutationResult>
2283
- /**
2284
- * Create a document if no document with the same ID already exists.
2285
- * Returns an observable that resolves to the created document.
2286
- *
2287
- * @param document - Document to create
2288
- * @param options - Mutation options
2289
- */
2290
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2291
- document: IdentifiedSanityDocumentStub<R>,
2292
- options?: BaseMutationOptions,
2293
- ): Observable<SanityDocument<R>>
2294
- /**
2295
- * Create a document if it does not exist, or replace a document with the same document ID
2296
- * Returns an observable that resolves to the created document.
2297
- *
2298
- * @param document - Document to either create or replace
2299
- * @param options - Mutation options
2300
- */
2301
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2302
- document: IdentifiedSanityDocumentStub<R>,
2303
- options: FirstDocumentMutationOptions,
2304
- ): Observable<SanityDocument<R>>
2305
- /**
2306
- * Create a document if it does not exist, or replace a document with the same document ID
2307
- * Returns an observable that resolves to an array containing the created document.
2308
- *
2309
- * @param document - Document to either create or replace
2310
- * @param options - Mutation options
2311
- */
2312
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2313
- document: IdentifiedSanityDocumentStub<R>,
2314
- options: AllDocumentsMutationOptions,
2315
- ): Observable<SanityDocument<R>[]>
2316
- /**
2317
- * Create a document if it does not exist, or replace a document with the same document ID
2318
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2319
- *
2320
- * @param document - Document to either create or replace
2321
- * @param options - Mutation options
2322
- */
2323
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2324
- document: IdentifiedSanityDocumentStub<R>,
2325
- options: FirstDocumentIdMutationOptions,
2326
- ): Observable<SingleMutationResult>
2327
- /**
2328
- * Create a document if it does not exist, or replace a document with the same document ID
2329
- * Returns an observable that resolves to a mutation result object containing the created document ID.
2330
- *
2331
- * @param document - Document to either create or replace
2332
- * @param options - Mutation options
2333
- */
2334
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2335
- document: IdentifiedSanityDocumentStub<R>,
2336
- options: AllDocumentIdsMutationOptions,
2337
- ): Observable<MultipleMutationResult>
2338
- /**
2339
- * Create a document if it does not exist, or replace a document with the same document ID
2340
- * Returns an observable that resolves to the created document.
2341
- *
2342
- * @param document - Document to either create or replace
2343
- * @param options - Mutation options
2344
- */
2345
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2346
- document: IdentifiedSanityDocumentStub<R>,
2347
- options?: BaseMutationOptions,
2348
- ): Observable<SanityDocument<R>>
2349
- /**
2350
- * Deletes a document with the given document ID.
2351
- * Returns an observable that resolves to the deleted document.
2352
- *
2353
- * @param id - Document ID to delete
2354
- * @param options - Options for the mutation
2355
- */
2356
- delete<R extends Record<string, Any> = Record<string, Any>>(
2357
- id: string,
2358
- options: FirstDocumentMutationOptions,
2359
- ): Observable<SanityDocument<R>>
2360
- /**
2361
- * Deletes a document with the given document ID.
2362
- * Returns an observable that resolves to an array containing the deleted document.
2363
- *
2364
- * @param id - Document ID to delete
2365
- * @param options - Options for the mutation
2366
- */
2367
- delete<R extends Record<string, Any> = Record<string, Any>>(
2368
- id: string,
2369
- options: AllDocumentsMutationOptions,
2370
- ): Observable<SanityDocument<R>[]>
2371
- /**
2372
- * Deletes a document with the given document ID.
2373
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2374
- *
2375
- * @param id - Document ID to delete
2376
- * @param options - Options for the mutation
2377
- */
2378
- delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2379
- /**
2380
- * Deletes a document with the given document ID.
2381
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2382
- *
2383
- * @param id - Document ID to delete
2384
- * @param options - Options for the mutation
2385
- */
2386
- delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2387
- /**
2388
- * Deletes a document with the given document ID.
2389
- * Returns an observable that resolves to the deleted document.
2390
- *
2391
- * @param id - Document ID to delete
2392
- * @param options - Options for the mutation
2393
- */
2394
- delete<R extends Record<string, Any> = Record<string, Any>>(
2395
- id: string,
2396
- options?: BaseMutationOptions,
2397
- ): Observable<SanityDocument<R>>
2398
- /**
2399
- * Deletes one or more documents matching the given query or document ID.
2400
- * Returns an observable that resolves to first deleted document.
2401
- *
2402
- * @param selection - An object with either an `id` or `query` key defining what to delete
2403
- * @param options - Options for the mutation
2404
- */
2405
- delete<R extends Record<string, Any> = Record<string, Any>>(
2406
- selection: MutationSelection,
2407
- options: FirstDocumentMutationOptions,
2408
- ): Observable<SanityDocument<R>>
2409
- /**
2410
- * Deletes one or more documents matching the given query or document ID.
2411
- * Returns an observable that resolves to an array containing the deleted documents.
2412
- *
2413
- * @param selection - An object with either an `id` or `query` key defining what to delete
2414
- * @param options - Options for the mutation
2415
- */
2416
- delete<R extends Record<string, Any> = Record<string, Any>>(
2417
- selection: MutationSelection,
2418
- options: AllDocumentsMutationOptions,
2419
- ): Observable<SanityDocument<R>[]>
2420
- /**
2421
- * Deletes one or more documents matching the given query or document ID.
2422
- * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
2423
- *
2424
- * @param selection - An object with either an `id` or `query` key defining what to delete
2425
- * @param options - Options for the mutation
2426
- */
2427
- delete(
2428
- selection: MutationSelection,
2429
- options: FirstDocumentIdMutationOptions,
2430
- ): Observable<SingleMutationResult>
2431
- /**
2432
- * Deletes one or more documents matching the given query or document ID.
2433
- * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
2434
- *
2435
- * @param selection - An object with either an `id` or `query` key defining what to delete
2436
- * @param options - Options for the mutation
2437
- */
2438
- delete(
2439
- selection: MutationSelection,
2440
- options: AllDocumentIdsMutationOptions,
2441
- ): Observable<MultipleMutationResult>
2442
- /**
2443
- * Deletes one or more documents matching the given query or document ID.
2444
- * Returns an observable that resolves to first deleted document.
2445
- *
2446
- * @param selection - An object with either an `id` or `query` key defining what to delete
2447
- * @param options - Options for the mutation
2448
- */
2449
- delete<R extends Record<string, Any> = Record<string, Any>>(
2450
- selection: MutationSelection,
2451
- options?: BaseMutationOptions,
2452
- ): Observable<SanityDocument<R>>
2453
- /**
2454
- * Perform mutation operations against the configured dataset
2455
- * Returns an observable that resolves to the first mutated document.
2456
- *
2457
- * @param operations - Mutation operations to execute
2458
- * @param options - Mutation options
2459
- */
2460
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2461
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2462
- options: FirstDocumentMutationOptions,
2463
- ): Observable<SanityDocument<R>>
2464
- /**
2465
- * Perform mutation operations against the configured dataset.
2466
- * Returns an observable that resolves to an array of the mutated documents.
2467
- *
2468
- * @param operations - Mutation operations to execute
2469
- * @param options - Mutation options
2470
- */
2471
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2472
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2473
- options: AllDocumentsMutationOptions,
2474
- ): Observable<SanityDocument<R>[]>
2475
- /**
2476
- * Perform mutation operations against the configured dataset
2477
- * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
2478
- *
2479
- * @param operations - Mutation operations to execute
2480
- * @param options - Mutation options
2481
- */
2482
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2483
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2484
- options: FirstDocumentIdMutationOptions,
2485
- ): Observable<SingleMutationResult>
2486
- /**
2487
- * Perform mutation operations against the configured dataset
2488
- * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
2489
- *
2490
- * @param operations - Mutation operations to execute
2491
- * @param options - Mutation options
2492
- */
2493
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2494
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2495
- options: AllDocumentIdsMutationOptions,
2496
- ): Observable<MultipleMutationResult>
2497
- /**
2498
- * Perform mutation operations against the configured dataset
2499
- * Returns an observable that resolves to the first mutated document.
2500
- *
2501
- * @param operations - Mutation operations to execute
2502
- * @param options - Mutation options
2503
- */
2504
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2505
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2506
- options?: BaseMutationOptions,
2507
- ): Observable<SanityDocument<R>>
2508
- /**
2509
- * Create a new buildable patch of operations to perform
2510
- *
2511
- * @param documentId - Document ID to patch
2512
- * @param operations - Optional object of patch operations to initialize the patch instance with
2513
- * @returns Patch instance - call `.commit()` to perform the operations defined
2514
- */
2515
- patch(documentId: string, operations?: PatchOperations): ObservablePatch
2516
- /**
2517
- * Create a new buildable patch of operations to perform
2518
- *
2519
- * @param documentIds - Array of document IDs to patch
2520
- * @param operations - Optional object of patch operations to initialize the patch instance with
2521
- * @returns Patch instance - call `.commit()` to perform the operations defined
2522
- */
2523
- patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
2524
- /**
2525
- * Create a new buildable patch of operations to perform
2526
- *
2527
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2528
- * @param operations - Optional object of patch operations to initialize the patch instance with
2529
- * @returns Patch instance - call `.commit()` to perform the operations defined
2530
- */
2531
- patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
2532
- /**
2533
- * Create a new buildable patch of operations to perform
2534
- *
2535
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
2536
- * @param operations - Optional object of patch operations to initialize the patch instance with
2537
- * @returns Patch instance - call `.commit()` to perform the operations defined
2538
- */
2539
- patch(selection: PatchSelection, operations?: PatchOperations): ObservablePatch
2540
- /**
2541
- * Create a new transaction of mutations
2542
- *
2543
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2544
- */
2545
- transaction<R extends Record<string, Any> = Record<string, Any>>(
2546
- operations?: Mutation<R>[],
2547
- ): ObservableTransaction
2548
- /**
2549
- * Perform action operations against the configured dataset
2550
- *
2551
- * @param operations - Action operation(s) to execute
2552
- * @param options - Action options
2553
- */
2554
- action(
2555
- operations: Action | Action[],
2556
- options?: BaseActionOptions,
2557
- ): Observable<SingleActionResult | MultipleActionResult>
2558
- /**
2559
- * Perform an HTTP request against the Sanity API
2560
- *
2561
- * @param options - Request options
2562
- */
2563
- request<R = Any>(options: RawRequestOptions): Observable<R>
2564
- }
2565
-
2566
- /** @public */
2567
- export declare class ObservableTransaction extends BaseTransaction {
2568
- #private
2569
- constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2570
- /**
2571
- * Clones the transaction
2572
- */
2573
- clone(): ObservableTransaction
2574
- /**
2575
- * Commit the transaction, returning an observable that produces the first mutated document
2576
- *
2577
- * @param options - Options for the mutation operation
2578
- */
2579
- commit<R extends Record<string, Any>>(
2580
- options: TransactionFirstDocumentMutationOptions,
2581
- ): Observable<SanityDocument<R>>
2582
- /**
2583
- * Commit the transaction, returning an observable that produces an array of the mutated documents
2584
- *
2585
- * @param options - Options for the mutation operation
2586
- */
2587
- commit<R extends Record<string, Any>>(
2588
- options: TransactionAllDocumentsMutationOptions,
2589
- ): Observable<SanityDocument<R>[]>
2590
- /**
2591
- * Commit the transaction, returning an observable that produces a mutation result object
2592
- *
2593
- * @param options - Options for the mutation operation
2594
- */
2595
- commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2596
- /**
2597
- * Commit the transaction, returning an observable that produces a mutation result object
2598
- *
2599
- * @param options - Options for the mutation operation
2600
- */
2601
- commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2602
- /**
2603
- * Commit the transaction, returning an observable that produces a mutation result object
2604
- *
2605
- * @param options - Options for the mutation operation
2606
- */
2607
- commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2608
- /**
2609
- * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2610
- * The operation is added to the current transaction, ready to be commited by `commit()`
2611
- *
2612
- * @param documentId - Document ID to perform the patch operation on
2613
- * @param patchOps - Operations to perform, or a builder function
2614
- */
2615
- patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2616
- /**
2617
- * Adds the given patch instance to the transaction.
2618
- * The operation is added to the current transaction, ready to be commited by `commit()`
2619
- *
2620
- * @param patch - ObservablePatch to execute
2621
- */
2622
- patch(patch: ObservablePatch): this
2623
- }
2624
-
2625
- /** @public */
2626
- export declare class ObservableUsersClient {
2627
- #private
2628
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2629
- /**
2630
- * Fetch a user by user ID
2631
- *
2632
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2633
- */
2634
- getById<T extends 'me' | string>(
2635
- id: T,
2636
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2637
- }
2638
-
2639
- /**
2640
- * The listener connection has been established
2641
- * note: it's usually a better option to use the 'welcome' event
2642
- * @public
2643
- */
2644
- export declare type OpenEvent = {
2645
- type: 'open'
2646
- }
2647
-
2648
- /** @public */
2649
- export declare class Patch extends BasePatch {
2650
- #private
2651
- constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2652
- /**
2653
- * Clones the patch
2654
- */
2655
- clone(): Patch
2656
- /**
2657
- * Commit the patch, returning a promise that resolves to the first patched document
2658
- *
2659
- * @param options - Options for the mutation operation
2660
- */
2661
- commit<R extends Record<string, Any> = Record<string, Any>>(
2662
- options: FirstDocumentMutationOptions,
2663
- ): Promise<SanityDocument<R>>
2664
- /**
2665
- * Commit the patch, returning a promise that resolves to an array of the mutated documents
2666
- *
2667
- * @param options - Options for the mutation operation
2668
- */
2669
- commit<R extends Record<string, Any> = Record<string, Any>>(
2670
- options: AllDocumentsMutationOptions,
2671
- ): Promise<SanityDocument<R>[]>
2672
- /**
2673
- * Commit the patch, returning a promise that resolves to a mutation result object
2674
- *
2675
- * @param options - Options for the mutation operation
2676
- */
2677
- commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2678
- /**
2679
- * Commit the patch, returning a promise that resolves to a mutation result object
2680
- *
2681
- * @param options - Options for the mutation operation
2682
- */
2683
- commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2684
- /**
2685
- * Commit the patch, returning a promise that resolves to the first patched document
2686
- *
2687
- * @param options - Options for the mutation operation
2688
- */
2689
- commit<R extends Record<string, Any> = Record<string, Any>>(
2690
- options?: BaseMutationOptions,
2691
- ): Promise<SanityDocument<R>>
2692
- }
2693
-
2694
- /** @public */
2695
- export declare type PatchBuilder = (patch: Patch) => Patch
2696
-
2697
- /** @internal */
2698
- export declare type PatchMutationOperation = PatchOperations & MutationSelection
2699
-
2700
- /** @internal */
2701
- export declare interface PatchOperations {
2702
- set?: {
2703
- [key: string]: Any
2704
- }
2705
- setIfMissing?: {
2706
- [key: string]: Any
2707
- }
2708
- diffMatchPatch?: {
2709
- [key: string]: Any
2710
- }
2711
- unset?: string[]
2712
- inc?: {
2713
- [key: string]: number
2714
- }
2715
- dec?: {
2716
- [key: string]: number
2717
- }
2718
- insert?: InsertPatch
2719
- ifRevisionID?: string
2720
- }
2721
-
2722
- /** @internal */
2723
- export declare type PatchSelection = string | string[] | MutationSelection
2724
-
2725
- /** @public */
2726
- declare interface ProgressEvent_2 {
2727
- type: 'progress'
2728
- stage: 'upload' | 'download'
2729
- percent: number
2730
- total?: number
2731
- loaded?: number
2732
- lengthComputable: boolean
2733
- }
2734
- export {ProgressEvent_2 as ProgressEvent}
2735
-
2736
- /** @internal */
2737
- export declare class ProjectsClient {
2738
- #private
2739
- constructor(client: SanityClient, httpRequest: HttpRequest)
2740
- /**
2741
- * Fetch a list of projects the authenticated user has access to.
2742
- *
2743
- * @param options - Options for the list request
2744
- * @param options.includeMembers - Whether to include members in the response (default: true)
2745
- */
2746
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2747
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
2748
- /**
2749
- * Fetch a project by project ID
2750
- *
2751
- * @param projectId - ID of the project to fetch
2752
- */
2753
- getById(projectId: string): Promise<SanityProject>
2754
- }
2755
-
2756
- /**
2757
- * Publishes a draft document.
2758
- * If a published version of the document already exists this is replaced by the current draft document.
2759
- * In either case the draft document is deleted.
2760
- * The optional revision id parameters can be used for optimistic locking to ensure
2761
- * that the draft and/or published versions of the document have not been changed by another client.
2762
- *
2763
- * @public
2764
- */
2765
- export declare type PublishAction = {
2766
- actionType: 'sanity.action.document.publish'
2767
- /**
2768
- * Draft document ID to publish
2769
- */
2770
- draftId: string
2771
- /**
2772
- * Draft revision ID to match
2773
- */
2774
- ifDraftRevisionId?: string
2775
- /**
2776
- * Published document ID to replace
2777
- */
2778
- publishedId: string
2779
- /**
2780
- * Published revision ID to match
2781
- */
2782
- ifPublishedRevisionId?: string
2783
- }
2784
-
2785
- /** @public */
2786
- export declare type QueryOptions =
2787
- | FilteredResponseQueryOptions
2788
- | UnfilteredResponseQueryOptions
2789
- | UnfilteredResponseWithoutQuery
2790
-
2791
- /** @public */
2792
- export declare interface QueryParams {
2793
- [key: string]: any
2794
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2795
- body?: never
2796
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2797
- cache?: 'next' extends keyof RequestInit ? never : any
2798
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2799
- filterResponse?: never
2800
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2801
- headers?: never
2802
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2803
- method?: never
2804
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2805
- next?: 'next' extends keyof RequestInit ? never : any
2806
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2807
- perspective?: never
2808
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2809
- query?: never
2810
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2811
- resultSourceMap?: never
2812
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2813
- returnQuery?: never
2814
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2815
- signal?: never
2816
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2817
- stega?: never
2818
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2819
- tag?: never
2820
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2821
- timeout?: never
2822
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2823
- token?: never
2824
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2825
- useCdn?: never
2826
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2827
- lastLiveEventId?: never
2828
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2829
- cacheMode?: never
2830
- }
2831
-
2832
- /**
2833
- * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2834
- * @public
2835
- */
2836
- export declare type QueryWithoutParams = Record<string, never> | undefined
2837
-
2838
- /** @public */
2839
- export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2840
-
2841
- /** @public */
2842
- export declare interface RawQueryResponse<R> {
2843
- query: string
2844
- ms: number
2845
- result: R
2846
- resultSourceMap?: ContentSourceMap
2847
- /** Requires `apiVersion` to be `2021-03-25` or later. */
2848
- syncTags?: SyncTag[]
2849
- }
2850
-
2851
- /** @internal */
2852
- export declare interface RawRequestOptions {
2853
- url?: string
2854
- uri?: string
2855
- method?: string
2856
- token?: string
2857
- json?: boolean
2858
- tag?: string
2859
- useGlobalApi?: boolean
2860
- withCredentials?: boolean
2861
- query?: {
2862
- [key: string]: string | string[]
2863
- }
2864
- headers?: {
2865
- [key: string]: string
2866
- }
2867
- timeout?: number
2868
- proxy?: string
2869
- body?: Any
2870
- maxRedirects?: number
2871
- signal?: AbortSignal
2872
- }
2873
-
2874
- /**
2875
- * The listener has been disconnected, and a reconnect attempt is scheduled.
2876
- *
2877
- * @public
2878
- */
2879
- export declare type ReconnectEvent = {
2880
- type: 'reconnect'
2881
- }
2882
-
2883
- /**
2884
- * @public
2885
- * @deprecated – The `r`-prefix is not required, use `string` instead
2886
- */
2887
- export declare type ReleaseId = `r${string}`
2888
-
2889
- /**
2890
- * Replaces an existing draft document.
2891
- * At least one of the draft or published versions of the document must exist.
2892
- *
2893
- * @public
2894
- */
2895
- export declare type ReplaceDraftAction = {
2896
- actionType: 'sanity.action.document.replaceDraft'
2897
- /**
2898
- * Published document ID to create draft from, if draft does not exist
2899
- */
2900
- publishedId: string
2901
- /**
2902
- * Document to create if it does not already exist. Requires `_id` and `_type` properties.
2903
- */
2904
- attributes: IdentifiedSanityDocumentStub
2905
- }
2906
-
2907
- /** @public */
2908
- export declare const requester: Requester
2909
-
2910
- /** @internal */
2911
- export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
2912
- url?: string
2913
- uri?: string
2914
- canUseCdn?: boolean
2915
- useCdn?: boolean
2916
- tag?: string
2917
- returnQuery?: boolean
2918
- resultSourceMap?: boolean | 'withKeyArraySelector'
2919
- perspective?: ClientPerspective
2920
- lastLiveEventId?: string
2921
- cacheMode?: 'noStale'
2922
- }
2923
-
2924
- /** @public */
2925
- export declare interface RequestOptions {
2926
- timeout?: number
2927
- token?: string
2928
- tag?: string
2929
- headers?: Record<string, string>
2930
- method?: string
2931
- query?: Any
2932
- body?: Any
2933
- signal?: AbortSignal
2934
- }
2935
-
2936
- export {ResolveStudioUrl}
2937
-
2938
- /** @public */
2939
- export declare interface ResponseEvent<T = unknown> {
2940
- type: 'response'
2941
- body: T
2942
- url: string
2943
- method: string
2944
- statusCode: number
2945
- statusMessage?: string
2946
- headers: Record<string, string>
2947
- }
2948
-
2949
- /** @public */
2950
- export declare interface ResponseQueryOptions extends RequestOptions {
2951
- perspective?: ClientPerspective
2952
- resultSourceMap?: boolean | 'withKeyArraySelector'
2953
- returnQuery?: boolean
2954
- useCdn?: boolean
2955
- stega?: boolean | StegaConfig
2956
- cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
2957
- next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
2958
- lastLiveEventId?: string | string[] | null
2959
- /**
2960
- * When set to `noStale`, APICDN will not return a cached response if the content is stale.
2961
- * Tradeoff between latency and freshness of content.
2962
- *
2963
- * Only to be used with live content queries and when useCdn is true.
2964
- */
2965
- cacheMode?: 'noStale'
2966
- }
2967
-
2968
- /** @internal */
2969
- export declare interface SanityAssetDocument extends SanityDocument {
2970
- url: string
2971
- path: string
2972
- size: number
2973
- assetId: string
2974
- mimeType: string
2975
- sha1hash: string
2976
- extension: string
2977
- uploadId?: string
2978
- originalFilename?: string
2979
- }
2980
-
2981
- /** @public */
2982
- export declare class SanityClient implements SanityClientType {
2983
- #private
2984
- assets: AssetsClient
2985
- datasets: DatasetsClient
2986
- live: LiveClient
2987
- projects: ProjectsClient
2988
- users: UsersClient
2989
- /**
2990
- * Observable version of the Sanity client, with the same configuration as the promise-based one
2991
- */
2992
- observable: ObservableSanityClient
2993
- listen: typeof _listen
2994
- constructor(httpRequest: HttpRequest, config?: ClientConfig)
2995
- /**
2996
- * Clone the client - returns a new instance
2997
- */
2998
- clone(): SanityClient
2999
- /**
3000
- * Returns the current client configuration
3001
- */
3002
- config(): InitializedClientConfig
3003
- /**
3004
- * Reconfigure the client. Note that this _mutates_ the current client.
3005
- */
3006
- config(newConfig?: Partial<ClientConfig>): this
3007
- /**
3008
- * Clone the client with a new (partial) configuration.
3009
- *
3010
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3011
- */
3012
- withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3013
- /**
3014
- * Perform a GROQ-query against the configured dataset.
3015
- *
3016
- * @param query - GROQ-query to perform
3017
- */
3018
- fetch<
3019
- R = Any,
3020
- Q extends QueryWithoutParams = QueryWithoutParams,
3021
- const G extends string = string,
3022
- >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3023
- /**
3024
- * Perform a GROQ-query against the configured dataset.
3025
- *
3026
- * @param query - GROQ-query to perform
3027
- * @param params - Optional query parameters
3028
- * @param options - Optional request options
3029
- */
3030
- fetch<
3031
- R = Any,
3032
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3033
- const G extends string = string,
3034
- >(
3035
- query: G,
3036
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3037
- options?: FilteredResponseQueryOptions,
3038
- ): Promise<ClientReturn<G, R>>
3039
- /**
3040
- * Perform a GROQ-query against the configured dataset.
3041
- *
3042
- * @param query - GROQ-query to perform
3043
- * @param params - Optional query parameters
3044
- * @param options - Request options
3045
- */
3046
- fetch<
3047
- R = Any,
3048
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3049
- const G extends string = string,
3050
- >(
3051
- query: G,
3052
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3053
- options: UnfilteredResponseQueryOptions,
3054
- ): Promise<RawQueryResponse<ClientReturn<G, R>>>
3055
- /**
3056
- * Perform a GROQ-query against the configured dataset.
3057
- *
3058
- * @param query - GROQ-query to perform
3059
- * @param params - Optional query parameters
3060
- * @param options - Request options
3061
- */
3062
- fetch<
3063
- R = Any,
3064
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3065
- const G extends string = string,
3066
- >(
3067
- query: G,
3068
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3069
- options: UnfilteredResponseWithoutQuery,
3070
- ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
3071
- /**
3072
- * Fetch a single document with the given ID.
3073
- *
3074
- * @param id - Document ID to fetch
3075
- * @param options - Request options
3076
- */
3077
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
3078
- id: string,
3079
- options?: {
3080
- signal?: AbortSignal
3081
- tag?: string
3082
- },
3083
- ): Promise<SanityDocument<R> | undefined>
3084
- /**
3085
- * Fetch multiple documents in one request.
3086
- * Should be used sparingly - performing a query is usually a better option.
3087
- * The order/position of documents is preserved based on the original array of IDs.
3088
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3089
- *
3090
- * @param ids - Document IDs to fetch
3091
- * @param options - Request options
3092
- */
3093
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
3094
- ids: string[],
3095
- options?: {
3096
- signal?: AbortSignal
3097
- tag?: string
3098
- },
3099
- ): Promise<(SanityDocument<R> | null)[]>
3100
- /**
3101
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3102
- * Returns a promise that resolves to the created document.
3103
- *
3104
- * @param document - Document to create
3105
- * @param options - Mutation options
3106
- */
3107
- create<R extends Record<string, Any> = Record<string, Any>>(
3108
- document: SanityDocumentStub<R>,
3109
- options: FirstDocumentMutationOptions,
3110
- ): Promise<SanityDocument<R>>
3111
- /**
3112
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3113
- * Returns a promise that resolves to an array containing the created document.
3114
- *
3115
- * @param document - Document to create
3116
- * @param options - Mutation options
3117
- */
3118
- create<R extends Record<string, Any> = Record<string, Any>>(
3119
- document: SanityDocumentStub<R>,
3120
- options: AllDocumentsMutationOptions,
3121
- ): Promise<SanityDocument<R>[]>
3122
- /**
3123
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3124
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3125
- *
3126
- * @param document - Document to create
3127
- * @param options - Mutation options
3128
- */
3129
- create<R extends Record<string, Any> = Record<string, Any>>(
3130
- document: SanityDocumentStub<R>,
3131
- options: FirstDocumentIdMutationOptions,
3132
- ): Promise<SingleMutationResult>
3133
- /**
3134
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3135
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3136
- *
3137
- * @param document - Document to create
3138
- * @param options - Mutation options
3139
- */
3140
- create<R extends Record<string, Any> = Record<string, Any>>(
3141
- document: SanityDocumentStub<R>,
3142
- options: AllDocumentIdsMutationOptions,
3143
- ): Promise<MultipleMutationResult>
3144
- /**
3145
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3146
- * Returns a promise that resolves to the created document.
3147
- *
3148
- * @param document - Document to create
3149
- * @param options - Mutation options
3150
- */
3151
- create<R extends Record<string, Any> = Record<string, Any>>(
3152
- document: SanityDocumentStub<R>,
3153
- options?: BaseMutationOptions,
3154
- ): Promise<SanityDocument<R>>
3155
- /**
3156
- * Create a document if no document with the same ID already exists.
3157
- * Returns a promise that resolves to the created document.
3158
- *
3159
- * @param document - Document to create
3160
- * @param options - Mutation options
3161
- */
3162
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3163
- document: IdentifiedSanityDocumentStub<R>,
3164
- options: FirstDocumentMutationOptions,
3165
- ): Promise<SanityDocument<R>>
3166
- /**
3167
- * Create a document if no document with the same ID already exists.
3168
- * Returns a promise that resolves to an array containing the created document.
3169
- *
3170
- * @param document - Document to create
3171
- * @param options - Mutation options
3172
- */
3173
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3174
- document: IdentifiedSanityDocumentStub<R>,
3175
- options: AllDocumentsMutationOptions,
3176
- ): Promise<SanityDocument<R>[]>
3177
- /**
3178
- * Create a document if no document with the same ID already exists.
3179
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3180
- *
3181
- * @param document - Document to create
3182
- * @param options - Mutation options
3183
- */
3184
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3185
- document: IdentifiedSanityDocumentStub<R>,
3186
- options: FirstDocumentIdMutationOptions,
3187
- ): Promise<SingleMutationResult>
3188
- /**
3189
- * Create a document if no document with the same ID already exists.
3190
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3191
- *
3192
- * @param document - Document to create
3193
- * @param options - Mutation options
3194
- */
3195
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3196
- document: IdentifiedSanityDocumentStub<R>,
3197
- options: AllDocumentIdsMutationOptions,
3198
- ): Promise<MultipleMutationResult>
3199
- /**
3200
- * Create a document if no document with the same ID already exists.
3201
- * Returns a promise that resolves to the created document.
3202
- *
3203
- * @param document - Document to create
3204
- * @param options - Mutation options
3205
- */
3206
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3207
- document: IdentifiedSanityDocumentStub<R>,
3208
- options?: BaseMutationOptions,
3209
- ): Promise<SanityDocument<R>>
3210
- /**
3211
- * Create a document if it does not exist, or replace a document with the same document ID
3212
- * Returns a promise that resolves to the created document.
3213
- *
3214
- * @param document - Document to either create or replace
3215
- * @param options - Mutation options
3216
- */
3217
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3218
- document: IdentifiedSanityDocumentStub<R>,
3219
- options: FirstDocumentMutationOptions,
3220
- ): Promise<SanityDocument<R>>
3221
- /**
3222
- * Create a document if it does not exist, or replace a document with the same document ID
3223
- * Returns a promise that resolves to an array containing the created document.
3224
- *
3225
- * @param document - Document to either create or replace
3226
- * @param options - Mutation options
3227
- */
3228
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3229
- document: IdentifiedSanityDocumentStub<R>,
3230
- options: AllDocumentsMutationOptions,
3231
- ): Promise<SanityDocument<R>[]>
3232
- /**
3233
- * Create a document if it does not exist, or replace a document with the same document ID
3234
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3235
- *
3236
- * @param document - Document to either create or replace
3237
- * @param options - Mutation options
3238
- */
3239
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3240
- document: IdentifiedSanityDocumentStub<R>,
3241
- options: FirstDocumentIdMutationOptions,
3242
- ): Promise<SingleMutationResult>
3243
- /**
3244
- * Create a document if it does not exist, or replace a document with the same document ID
3245
- * Returns a promise that resolves to a mutation result object containing the created document ID.
3246
- *
3247
- * @param document - Document to either create or replace
3248
- * @param options - Mutation options
3249
- */
3250
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3251
- document: IdentifiedSanityDocumentStub<R>,
3252
- options: AllDocumentIdsMutationOptions,
3253
- ): Promise<MultipleMutationResult>
3254
- /**
3255
- * Create a document if it does not exist, or replace a document with the same document ID
3256
- * Returns a promise that resolves to the created document.
3257
- *
3258
- * @param document - Document to either create or replace
3259
- * @param options - Mutation options
3260
- */
3261
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3262
- document: IdentifiedSanityDocumentStub<R>,
3263
- options?: BaseMutationOptions,
3264
- ): Promise<SanityDocument<R>>
3265
- /**
3266
- * Deletes a document with the given document ID.
3267
- * Returns a promise that resolves to the deleted document.
3268
- *
3269
- * @param id - Document ID to delete
3270
- * @param options - Options for the mutation
3271
- */
3272
- delete<R extends Record<string, Any> = Record<string, Any>>(
3273
- id: string,
3274
- options: FirstDocumentMutationOptions,
3275
- ): Promise<SanityDocument<R>>
3276
- /**
3277
- * Deletes a document with the given document ID.
3278
- * Returns a promise that resolves to an array containing the deleted document.
3279
- *
3280
- * @param id - Document ID to delete
3281
- * @param options - Options for the mutation
3282
- */
3283
- delete<R extends Record<string, Any> = Record<string, Any>>(
3284
- id: string,
3285
- options: AllDocumentsMutationOptions,
3286
- ): Promise<SanityDocument<R>[]>
3287
- /**
3288
- * Deletes a document with the given document ID.
3289
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3290
- *
3291
- * @param id - Document ID to delete
3292
- * @param options - Options for the mutation
3293
- */
3294
- delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3295
- /**
3296
- * Deletes a document with the given document ID.
3297
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3298
- *
3299
- * @param id - Document ID to delete
3300
- * @param options - Options for the mutation
3301
- */
3302
- delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3303
- /**
3304
- * Deletes a document with the given document ID.
3305
- * Returns a promise that resolves to the deleted document.
3306
- *
3307
- * @param id - Document ID to delete
3308
- * @param options - Options for the mutation
3309
- */
3310
- delete<R extends Record<string, Any> = Record<string, Any>>(
3311
- id: string,
3312
- options?: BaseMutationOptions,
3313
- ): Promise<SanityDocument<R>>
3314
- /**
3315
- * Deletes one or more documents matching the given query or document ID.
3316
- * Returns a promise that resolves to first deleted document.
3317
- *
3318
- * @param selection - An object with either an `id` or `query` key defining what to delete
3319
- * @param options - Options for the mutation
3320
- */
3321
- delete<R extends Record<string, Any> = Record<string, Any>>(
3322
- selection: MutationSelection,
3323
- options: FirstDocumentMutationOptions,
3324
- ): Promise<SanityDocument<R>>
3325
- /**
3326
- * Deletes one or more documents matching the given query or document ID.
3327
- * Returns a promise that resolves to an array containing the deleted documents.
3328
- *
3329
- * @param selection - An object with either an `id` or `query` key defining what to delete
3330
- * @param options - Options for the mutation
3331
- */
3332
- delete<R extends Record<string, Any> = Record<string, Any>>(
3333
- selection: MutationSelection,
3334
- options: AllDocumentsMutationOptions,
3335
- ): Promise<SanityDocument<R>[]>
3336
- /**
3337
- * Deletes one or more documents matching the given query or document ID.
3338
- * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
3339
- *
3340
- * @param selection - An object with either an `id` or `query` key defining what to delete
3341
- * @param options - Options for the mutation
3342
- */
3343
- delete(
3344
- selection: MutationSelection,
3345
- options: FirstDocumentIdMutationOptions,
3346
- ): Promise<SingleMutationResult>
3347
- /**
3348
- * Deletes one or more documents matching the given query or document ID.
3349
- * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
3350
- *
3351
- * @param selection - An object with either an `id` or `query` key defining what to delete
3352
- * @param options - Options for the mutation
3353
- */
3354
- delete(
3355
- selection: MutationSelection,
3356
- options: AllDocumentIdsMutationOptions,
3357
- ): Promise<MultipleMutationResult>
3358
- /**
3359
- * Deletes one or more documents matching the given query or document ID.
3360
- * Returns a promise that resolves to first deleted document.
3361
- *
3362
- * @param selection - An object with either an `id` or `query` key defining what to delete
3363
- * @param options - Options for the mutation
3364
- */
3365
- delete<R extends Record<string, Any> = Record<string, Any>>(
3366
- selection: MutationSelection,
3367
- options?: BaseMutationOptions,
3368
- ): Promise<SanityDocument<R>>
3369
- /**
3370
- * Perform mutation operations against the configured dataset
3371
- * Returns a promise that resolves to the first mutated document.
3372
- *
3373
- * @param operations - Mutation operations to execute
3374
- * @param options - Mutation options
3375
- */
3376
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3377
- operations: Mutation<R>[] | Patch | Transaction,
3378
- options: FirstDocumentMutationOptions,
3379
- ): Promise<SanityDocument<R>>
3380
- /**
3381
- * Perform mutation operations against the configured dataset.
3382
- * Returns a promise that resolves to an array of the mutated documents.
3383
- *
3384
- * @param operations - Mutation operations to execute
3385
- * @param options - Mutation options
3386
- */
3387
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3388
- operations: Mutation<R>[] | Patch | Transaction,
3389
- options: AllDocumentsMutationOptions,
3390
- ): Promise<SanityDocument<R>[]>
3391
- /**
3392
- * Perform mutation operations against the configured dataset
3393
- * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
3394
- *
3395
- * @param operations - Mutation operations to execute
3396
- * @param options - Mutation options
3397
- */
3398
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3399
- operations: Mutation<R>[] | Patch | Transaction,
3400
- options: FirstDocumentIdMutationOptions,
3401
- ): Promise<SingleMutationResult>
3402
- /**
3403
- * Perform mutation operations against the configured dataset
3404
- * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
3405
- *
3406
- * @param operations - Mutation operations to execute
3407
- * @param options - Mutation options
3408
- */
3409
- mutate<R extends Record<string, Any>>(
3410
- operations: Mutation<R>[] | Patch | Transaction,
3411
- options: AllDocumentIdsMutationOptions,
3412
- ): Promise<MultipleMutationResult>
3413
- /**
3414
- * Perform mutation operations against the configured dataset
3415
- * Returns a promise that resolves to the first mutated document.
3416
- *
3417
- * @param operations - Mutation operations to execute
3418
- * @param options - Mutation options
3419
- */
3420
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3421
- operations: Mutation<R>[] | Patch | Transaction,
2751
+ commit<R extends Record<string, Any> = Record<string, Any>>(
3422
2752
  options?: BaseMutationOptions,
3423
2753
  ): Promise<SanityDocument<R>>
2754
+ }
2755
+
2756
+ /** @public */
2757
+ export declare type PatchBuilder = (patch: Patch) => Patch
2758
+
2759
+ /** @internal */
2760
+ export declare type PatchMutationOperation = PatchOperations & MutationSelection
2761
+
2762
+ /** @internal */
2763
+ export declare interface PatchOperations {
2764
+ set?: {
2765
+ [key: string]: Any
2766
+ }
2767
+ setIfMissing?: {
2768
+ [key: string]: Any
2769
+ }
2770
+ diffMatchPatch?: {
2771
+ [key: string]: Any
2772
+ }
2773
+ unset?: string[]
2774
+ inc?: {
2775
+ [key: string]: number
2776
+ }
2777
+ dec?: {
2778
+ [key: string]: number
2779
+ }
2780
+ insert?: InsertPatch
2781
+ ifRevisionID?: string
2782
+ }
2783
+
2784
+ /** @internal */
2785
+ export declare type PatchSelection = string | string[] | MutationSelection
2786
+
2787
+ /** @public */
2788
+ declare interface ProgressEvent_2 {
2789
+ type: 'progress'
2790
+ stage: 'upload' | 'download'
2791
+ percent: number
2792
+ total?: number
2793
+ loaded?: number
2794
+ lengthComputable: boolean
2795
+ }
2796
+ export {ProgressEvent_2 as ProgressEvent}
2797
+
2798
+ /** @internal */
2799
+ export declare class ProjectsClient {
2800
+ #private
2801
+ constructor(client: SanityClient, httpRequest: HttpRequest)
3424
2802
  /**
3425
- * Create a new buildable patch of operations to perform
3426
- *
3427
- * @param documentId - Document ID to patch
3428
- * @param operations - Optional object of patch operations to initialize the patch instance with
3429
- * @returns Patch instance - call `.commit()` to perform the operations defined
3430
- */
3431
- patch(documentId: string, operations?: PatchOperations): Patch
3432
- /**
3433
- * Create a new buildable patch of operations to perform
3434
- *
3435
- * @param documentIds - Array of document IDs to patch
3436
- * @param operations - Optional object of patch operations to initialize the patch instance with
3437
- * @returns Patch instance - call `.commit()` to perform the operations defined
3438
- */
3439
- patch(documentIds: string[], operations?: PatchOperations): Patch
3440
- /**
3441
- * Create a new buildable patch of operations to perform
3442
- *
3443
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3444
- * @param operations - Optional object of patch operations to initialize the patch instance with
3445
- * @returns Patch instance - call `.commit()` to perform the operations defined
3446
- */
3447
- patch(selection: MutationSelection, operations?: PatchOperations): Patch
3448
- /**
3449
- * Create a new transaction of mutations
2803
+ * Fetch a list of projects the authenticated user has access to.
3450
2804
  *
3451
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2805
+ * @param options - Options for the list request
2806
+ * - `includeMembers` - Whether to include members in the response (default: true)
3452
2807
  */
3453
- transaction<R extends Record<string, Any> = Record<string, Any>>(
3454
- operations?: Mutation<R>[],
3455
- ): Transaction
2808
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2809
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3456
2810
  /**
3457
- * Perform action operations against the configured dataset
3458
- * Returns a promise that resolves to the transaction result
2811
+ * Fetch a project by project ID
3459
2812
  *
3460
- * @param operations - Action operation(s) to execute
3461
- * @param options - Action options
2813
+ * @param projectId - ID of the project to fetch
3462
2814
  */
3463
- action(
3464
- operations: Action | Action[],
3465
- options?: BaseActionOptions,
3466
- ): Promise<SingleActionResult | MultipleActionResult>
2815
+ getById(projectId: string): Promise<SanityProject>
2816
+ }
2817
+
2818
+ /**
2819
+ * Publishes a draft document.
2820
+ * If a published version of the document already exists this is replaced by the current draft document.
2821
+ * In either case the draft document is deleted.
2822
+ * The optional revision id parameters can be used for optimistic locking to ensure
2823
+ * that the draft and/or published versions of the document have not been changed by another client.
2824
+ *
2825
+ * @public
2826
+ */
2827
+ export declare type PublishAction = {
2828
+ actionType: 'sanity.action.document.publish'
3467
2829
  /**
3468
- * Perform a request against the Sanity API
3469
- * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
3470
- *
3471
- * @param options - Request options
3472
- * @returns Promise resolving to the response body
2830
+ * Draft document ID to publish
3473
2831
  */
3474
- request<R = Any>(options: RawRequestOptions): Promise<R>
2832
+ draftId: string
3475
2833
  /**
3476
- * Perform an HTTP request a `/data` sub-endpoint
3477
- * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
3478
- *
3479
- * @deprecated - Use `request()` or your own HTTP library instead
3480
- * @param endpoint - Endpoint to hit (mutate, query etc)
3481
- * @param body - Request body
3482
- * @param options - Request options
3483
- * @internal
2834
+ * Draft revision ID to match
3484
2835
  */
3485
- dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
2836
+ ifDraftRevisionId?: string
3486
2837
  /**
3487
- * Get a Sanity API URL for the URI provided
3488
- *
3489
- * @param uri - URI/path to build URL for
3490
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
2838
+ * Published document ID to replace
3491
2839
  */
3492
- getUrl(uri: string, canUseCdn?: boolean): string
2840
+ publishedId: string
3493
2841
  /**
3494
- * Get a Sanity API URL for the data operation and path provided
3495
- *
3496
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3497
- * @param path - Path to append after the operation
2842
+ * Published revision ID to match
3498
2843
  */
3499
- getDataUrl(operation: string, path?: string): string
2844
+ ifPublishedRevisionId?: string
2845
+ }
2846
+
2847
+ /** @public */
2848
+ export declare type QueryOptions =
2849
+ | FilteredResponseQueryOptions
2850
+ | UnfilteredResponseQueryOptions
2851
+ | UnfilteredResponseWithoutQuery
2852
+
2853
+ /** @public */
2854
+ export declare interface QueryParams {
2855
+ [key: string]: any
2856
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2857
+ body?: never
2858
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2859
+ cache?: 'next' extends keyof RequestInit ? never : any
2860
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2861
+ filterResponse?: never
2862
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2863
+ headers?: never
2864
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2865
+ method?: never
2866
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2867
+ next?: 'next' extends keyof RequestInit ? never : any
2868
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2869
+ perspective?: never
2870
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2871
+ query?: never
2872
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2873
+ resultSourceMap?: never
2874
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2875
+ returnQuery?: never
2876
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2877
+ signal?: never
2878
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2879
+ stega?: never
2880
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2881
+ tag?: never
2882
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2883
+ timeout?: never
2884
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2885
+ token?: never
2886
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2887
+ useCdn?: never
2888
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2889
+ lastLiveEventId?: never
2890
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2891
+ cacheMode?: never
2892
+ }
2893
+
2894
+ /**
2895
+ * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2896
+ * @public
2897
+ */
2898
+ export declare type QueryWithoutParams = Record<string, never> | undefined
2899
+
2900
+ /** @public */
2901
+ export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2902
+
2903
+ /** @public */
2904
+ export declare interface RawQueryResponse<R> {
2905
+ query: string
2906
+ ms: number
2907
+ result: R
2908
+ resultSourceMap?: ContentSourceMap
2909
+ /** Requires `apiVersion` to be `2021-03-25` or later. */
2910
+ syncTags?: SyncTag[]
2911
+ }
2912
+
2913
+ /** @internal */
2914
+ export declare interface RawRequestOptions {
2915
+ url?: string
2916
+ uri?: string
2917
+ method?: string
2918
+ token?: string
2919
+ json?: boolean
2920
+ tag?: string
2921
+ useGlobalApi?: boolean
2922
+ withCredentials?: boolean
2923
+ query?: {
2924
+ [key: string]: string | string[]
2925
+ }
2926
+ headers?: {
2927
+ [key: string]: string
2928
+ }
2929
+ timeout?: number
2930
+ proxy?: string
2931
+ body?: Any
2932
+ maxRedirects?: number
2933
+ signal?: AbortSignal
3500
2934
  }
3501
2935
 
3502
2936
  /**
3503
- * Shared base type for the `SanityClient` and `ObservableSanityClient` classes.
3504
- * TODO: refactor the Promise and Observable differences to use generics so we no longer suffer from all this duplication in TS docs
2937
+ * The listener has been disconnected, and a reconnect attempt is scheduled.
2938
+ *
2939
+ * @public
3505
2940
  */
3506
- declare interface SanityClientBase {
3507
- live: LiveClient
3508
- listen: typeof _listen
2941
+ export declare type ReconnectEvent = {
2942
+ type: 'reconnect'
2943
+ }
2944
+
2945
+ /**
2946
+ * @public
2947
+ * @deprecated – The `r`-prefix is not required, use `string` instead
2948
+ */
2949
+ export declare type ReleaseId = `r${string}`
2950
+
2951
+ /**
2952
+ * Replaces an existing draft document.
2953
+ * At least one of the draft or published versions of the document must exist.
2954
+ *
2955
+ * @public
2956
+ */
2957
+ export declare type ReplaceDraftAction = {
2958
+ actionType: 'sanity.action.document.replaceDraft'
3509
2959
  /**
3510
- * Get a Sanity API URL for the URI provided
3511
- *
3512
- * @param uri - URI/path to build URL for
3513
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
2960
+ * Published document ID to create draft from, if draft does not exist
3514
2961
  */
3515
- getUrl(uri: string, canUseCdn?: boolean): string
2962
+ publishedId: string
3516
2963
  /**
3517
- * Get a Sanity API URL for the data operation and path provided
2964
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
2965
+ */
2966
+ attributes: IdentifiedSanityDocumentStub
2967
+ }
2968
+
2969
+ /** @public */
2970
+ export declare const requester: Requester
2971
+
2972
+ /** @internal */
2973
+ export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
2974
+ url?: string
2975
+ uri?: string
2976
+ canUseCdn?: boolean
2977
+ useCdn?: boolean
2978
+ tag?: string
2979
+ returnQuery?: boolean
2980
+ resultSourceMap?: boolean | 'withKeyArraySelector'
2981
+ perspective?: ClientPerspective
2982
+ lastLiveEventId?: string
2983
+ cacheMode?: 'noStale'
2984
+ }
2985
+
2986
+ /** @public */
2987
+ export declare interface RequestOptions {
2988
+ timeout?: number
2989
+ token?: string
2990
+ tag?: string
2991
+ headers?: Record<string, string>
2992
+ method?: string
2993
+ query?: Any
2994
+ body?: Any
2995
+ signal?: AbortSignal
2996
+ }
2997
+
2998
+ export {ResolveStudioUrl}
2999
+
3000
+ /** @public */
3001
+ export declare interface ResponseEvent<T = unknown> {
3002
+ type: 'response'
3003
+ body: T
3004
+ url: string
3005
+ method: string
3006
+ statusCode: number
3007
+ statusMessage?: string
3008
+ headers: Record<string, string>
3009
+ }
3010
+
3011
+ /** @public */
3012
+ export declare interface ResponseQueryOptions extends RequestOptions {
3013
+ perspective?: ClientPerspective
3014
+ resultSourceMap?: boolean | 'withKeyArraySelector'
3015
+ returnQuery?: boolean
3016
+ useCdn?: boolean
3017
+ stega?: boolean | StegaConfig
3018
+ cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
3019
+ next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
3020
+ lastLiveEventId?: string | string[] | null
3021
+ /**
3022
+ * When set to `noStale`, APICDN will not return a cached response if the content is stale.
3023
+ * Tradeoff between latency and freshness of content.
3518
3024
  *
3519
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3520
- * @param path - Path to append after the operation
3025
+ * Only to be used with live content queries and when useCdn is true.
3521
3026
  */
3522
- getDataUrl(operation: string, path?: string): string
3027
+ cacheMode?: 'noStale'
3523
3028
  }
3524
3029
 
3525
- /**
3526
- * The interface implemented by the `SanityClient` class.
3527
- * When writing code that wants to take an instance of `SanityClient` as input it's better to use this type,
3528
- * as the `SanityClient` class has private properties and thus TypeScrict will consider the type incompatible
3529
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
3530
- * @public
3531
- */
3532
- export declare interface SanityClientType extends SanityClientBase {
3030
+ /** @internal */
3031
+ export declare interface SanityAssetDocument extends SanityDocument {
3032
+ url: string
3033
+ path: string
3034
+ size: number
3035
+ assetId: string
3036
+ mimeType: string
3037
+ sha1hash: string
3038
+ extension: string
3039
+ uploadId?: string
3040
+ originalFilename?: string
3041
+ }
3042
+
3043
+ /** @public */
3044
+ export declare class SanityClient {
3045
+ #private
3533
3046
  assets: AssetsClient
3534
3047
  datasets: DatasetsClient
3048
+ live: LiveClient
3535
3049
  projects: ProjectsClient
3536
3050
  users: UsersClient
3051
+ agent: {
3052
+ action: AgentActionsClient
3053
+ }
3537
3054
  /**
3538
3055
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3539
3056
  */
3540
- observable: ObservableSanityClientType
3057
+ observable: ObservableSanityClient
3058
+ /**
3059
+ * Instance properties
3060
+ */
3061
+ listen: typeof _listen
3062
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
3541
3063
  /**
3542
3064
  * Clone the client - returns a new instance
3543
3065
  */
3544
- clone(): SanityClientType
3066
+ clone(): SanityClient
3545
3067
  /**
3546
3068
  * Returns the current client configuration
3547
3069
  */
@@ -3549,13 +3071,13 @@ export declare interface SanityClientType extends SanityClientBase {
3549
3071
  /**
3550
3072
  * Reconfigure the client. Note that this _mutates_ the current client.
3551
3073
  */
3552
- config(newConfig?: Partial<ClientConfig>): SanityClientType
3074
+ config(newConfig?: Partial<ClientConfig>): this
3553
3075
  /**
3554
3076
  * Clone the client with a new (partial) configuration.
3555
3077
  *
3556
3078
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3557
3079
  */
3558
- withConfig(newConfig?: Partial<ClientConfig>): SanityClientType
3080
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3559
3081
  /**
3560
3082
  * Perform a GROQ-query against the configured dataset.
3561
3083
  *
@@ -3565,10 +3087,7 @@ export declare interface SanityClientType extends SanityClientBase {
3565
3087
  R = Any,
3566
3088
  Q extends QueryWithoutParams = QueryWithoutParams,
3567
3089
  const G extends string = string,
3568
- >(
3569
- query: G,
3570
- params?: Q | QueryWithoutParams,
3571
- ): Promise<ClientReturn<G, R>>
3090
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3572
3091
  /**
3573
3092
  * Perform a GROQ-query against the configured dataset.
3574
3093
  *
@@ -3994,14 +3513,6 @@ export declare interface SanityClientType extends SanityClientBase {
3994
3513
  * @returns Patch instance - call `.commit()` to perform the operations defined
3995
3514
  */
3996
3515
  patch(selection: MutationSelection, operations?: PatchOperations): Patch
3997
- /**
3998
- * Create a new buildable patch of operations to perform
3999
- *
4000
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
4001
- * @param operations - Optional object of patch operations to initialize the patch instance with
4002
- * @returns Patch instance - call `.commit()` to perform the operations defined
4003
- */
4004
- patch(selection: PatchSelection, operations?: PatchOperations): Patch
4005
3516
  /**
4006
3517
  * Create a new transaction of mutations
4007
3518
  *
@@ -4040,6 +3551,20 @@ export declare interface SanityClientType extends SanityClientBase {
4040
3551
  * @internal
4041
3552
  */
4042
3553
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
3554
+ /**
3555
+ * Get a Sanity API URL for the URI provided
3556
+ *
3557
+ * @param uri - URI/path to build URL for
3558
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
3559
+ */
3560
+ getUrl(uri: string, canUseCdn?: boolean): string
3561
+ /**
3562
+ * Get a Sanity API URL for the data operation and path provided
3563
+ *
3564
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3565
+ * @param path - Path to append after the operation
3566
+ */
3567
+ getDataUrl(operation: string, path?: string): string
4043
3568
  }
4044
3569
 
4045
3570
  /** @internal */
@@ -4340,6 +3865,309 @@ export declare type TransactionMutationOptions =
4340
3865
  | TransactionAllDocumentsMutationOptions
4341
3866
  | TransactionAllDocumentIdsMutationOptions
4342
3867
 
3868
+ /** @beta */
3869
+ export declare type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
3870
+ | TransformDocumentSync<T>
3871
+ | TransformDocumentAsync
3872
+
3873
+ /** @beta */
3874
+ declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
3875
+
3876
+ /** @beta */
3877
+ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
3878
+ TransformRequestBase & AgentActionSync
3879
+
3880
+ /** @beta */
3881
+ declare interface TransformRequestBase extends AgentActionRequestBase {
3882
+ /** schemaId as reported by sanity deploy / sanity schema store */
3883
+ schemaId: string
3884
+ /**
3885
+ * The source document the transformation will use as input.
3886
+ */
3887
+ documentId: string
3888
+ /**
3889
+ * The source document's content is first copied to the target,
3890
+ * then it is transformed according to the instruction.
3891
+ *
3892
+ * When omitted, the source document (documentId) is also the target document.
3893
+ */
3894
+ targetDocument?: TransformTargetDocument
3895
+ /**
3896
+ * Instruct the LLM how to transform the input to th output.
3897
+ *
3898
+ * String template using $variable from instructionParams.
3899
+ *
3900
+ * Capped to 2000 characters, after variables has been injected.
3901
+ * */
3902
+ instruction: string
3903
+ /**
3904
+ *
3905
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3906
+ *
3907
+ * ### Examples
3908
+ *
3909
+ * #### Constant
3910
+ *
3911
+ * ##### Shorthand
3912
+ * ```ts
3913
+ * client.agent.action.generate({
3914
+ * schemaId,
3915
+ * documentId,
3916
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
3917
+ * instructionParams: {
3918
+ * topic: 'Grapefruit'
3919
+ * },
3920
+ * })
3921
+ * ```
3922
+ * ##### Object-form
3923
+ *
3924
+ * ```ts
3925
+ * client.agent.action.transform({
3926
+ * schemaId,
3927
+ * documentId,
3928
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
3929
+ * instructionParams: {
3930
+ * topic: {
3931
+ * type: 'constant',
3932
+ * value: 'Grapefruit'
3933
+ * },
3934
+ * },
3935
+ * })
3936
+ * ```
3937
+ * #### Field
3938
+ * ```ts
3939
+ * client.agent.action.transform({
3940
+ * schemaId,
3941
+ * documentId,
3942
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3943
+ * instructionParams: {
3944
+ * pte: {
3945
+ * type: 'field',
3946
+ * path: ['pteField'],
3947
+ * },
3948
+ * },
3949
+ * target: {path: 'keywords' }
3950
+ * })
3951
+ * ```
3952
+ * #### Document
3953
+ * ```ts
3954
+ * client.agent.action.transform({
3955
+ * schemaId,
3956
+ * documentId,
3957
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
3958
+ * instructionParams: {
3959
+ * document: {
3960
+ * type: 'document',
3961
+ * },
3962
+ * },
3963
+ * target: {path: 'keywords' }
3964
+ * })
3965
+ * ```
3966
+ *
3967
+ * #### GROQ
3968
+ * ```ts
3969
+ * client.agent.action.transform({
3970
+ * schemaId,
3971
+ * documentId,
3972
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
3973
+ * instructionParams: {
3974
+ * list: {
3975
+ * type: 'groq',
3976
+ * query: '* [_type==$type].title',
3977
+ * params: {type: 'article'}
3978
+ * },
3979
+ * },
3980
+ * target: {path: 'title'}
3981
+ * })
3982
+ * ```
3983
+ * */
3984
+ instructionParams?: AgentActionParams
3985
+ /**
3986
+ * Target defines which parts of the document will be affected by the instruction.
3987
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
3988
+ *
3989
+ * Omitting target implies that the document itself is the root.
3990
+ *
3991
+ * Notes:
3992
+ * - instruction can only affect fields up to `maxPathDepth`
3993
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
3994
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
3995
+ *
3996
+ * Default max depth for transform: 12
3997
+ * @see AgentActionRequestBase#conditionalPaths
3998
+ */
3999
+ target?: TransformTarget | TransformTarget[]
4000
+ }
4001
+
4002
+ /** @beta */
4003
+ export declare interface TransformTarget extends AgentActionTarget {
4004
+ /**
4005
+ * Specifies a tailored instruction of this target.
4006
+ *
4007
+ * string template using $variable from instructionParams.
4008
+ * */
4009
+ instruction?: string
4010
+ /**
4011
+ * By default, all children up to `target.maxPathDepth` are included.
4012
+ *
4013
+ * When `include` is specified, only segments explicitly listed will be included.
4014
+ *
4015
+ * Fields or array items not on the include list, are implicitly excluded.
4016
+ */
4017
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
4018
+ }
4019
+
4020
+ /** @beta */
4021
+ export declare type TransformTargetDocument =
4022
+ | {
4023
+ operation: 'edit'
4024
+ _id: string
4025
+ }
4026
+ | {
4027
+ operation: 'create'
4028
+ _id?: string
4029
+ }
4030
+ | {
4031
+ operation: 'createIfNotExists'
4032
+ _id: string
4033
+ }
4034
+ | {
4035
+ operation: 'createOrReplace'
4036
+ _id: string
4037
+ }
4038
+
4039
+ /** @beta */
4040
+ export declare interface TransformTargetInclude extends AgentActionTargetInclude {
4041
+ /**
4042
+ * Specifies a tailored instruction of this target.
4043
+ *
4044
+ * string template using $variable from instructionParams */
4045
+ instruction?: string
4046
+ /**
4047
+ * By default, all children up to `target.maxPathDepth` are included.
4048
+ *
4049
+ * When `include` is specified, only segments explicitly listed will be included.
4050
+ *
4051
+ * Fields or array items not on the include list, are implicitly excluded.
4052
+ */
4053
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
4054
+ }
4055
+
4056
+ /** @beta */
4057
+ export declare type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
4058
+ | TranslateDocumentSync<T>
4059
+ | TranslateDocumentAsync
4060
+
4061
+ /** @beta */
4062
+ declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
4063
+
4064
+ /** @beta */
4065
+ declare type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
4066
+ TranslateRequestBase & AgentActionSync
4067
+
4068
+ /** @beta */
4069
+ declare interface TranslateLanguage {
4070
+ /**
4071
+ * Language code
4072
+ */
4073
+ id: string
4074
+ /**
4075
+ * While optional, it is recommended to provide a language title
4076
+ */
4077
+ title?: string
4078
+ }
4079
+
4080
+ /** @beta */
4081
+ declare interface TranslateRequestBase extends AgentActionRequestBase {
4082
+ /** schemaId as reported by sanity deploy / sanity schema store */
4083
+ schemaId: string
4084
+ /**
4085
+ * The source document the transformation will use as input.
4086
+ */
4087
+ documentId: string
4088
+ /**
4089
+ * The target document will first get content copied over from the source,
4090
+ * then it is translated according to the instruction.
4091
+ *
4092
+ * When omitted, the source document (documentId) is also the target document.
4093
+ */
4094
+ targetDocument?: TransformTargetDocument
4095
+ /**
4096
+ * While optional, it is recommended
4097
+ */
4098
+ fromLanguage?: TranslateLanguage
4099
+ toLanguage: TranslateLanguage
4100
+ /**
4101
+ * `styleGuide` can be used to tailor how the translation should be preformed.
4102
+ *
4103
+ * String template using $variable from styleGuideParams.
4104
+ *
4105
+ * Capped to 2000 characters, after variables has been injected.
4106
+ *
4107
+ * @see #protectedPhrases
4108
+ */
4109
+ styleGuide?: string
4110
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
4111
+ styleGuideParams?: AgentActionParams
4112
+ /**
4113
+ * When the input string contains any phrase from `protectedPhrases`, the LLM will be instructed not
4114
+ * to translate them.
4115
+ *
4116
+ * It is recommended to use `protectedPhrases` instead of `styleGuide` for deny-list words and phrases,
4117
+ * since it keeps token cost low, resulting in faster responses, and limits how much information the LLM
4118
+ * has to process, since only phrases that are actually in the input string will be included in the final prompt.
4119
+ */
4120
+ protectedPhrases?: string[]
4121
+ /**
4122
+ * When specified, the `toLanguage.id` will be stored in the specified path in the target document.
4123
+ *
4124
+ * The file _can_ be hidden: true (unlike other fields in the target, which will be ignored)
4125
+ */
4126
+ languageFieldPath?: AgentActionPathSegment | AgentActionPath
4127
+ /**
4128
+ * Target defines which parts of the document will be affected by the instruction.
4129
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
4130
+ *
4131
+ * Omitting target implies that the document itself is the root.
4132
+ *
4133
+ * Notes:
4134
+ * - instruction can only affect fields up to `maxPathDepth`
4135
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
4136
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
4137
+ *
4138
+ * @see AgentActionRequestBase#conditionalPaths
4139
+ */
4140
+ target?: TranslateTarget | TranslateTarget[]
4141
+ }
4142
+
4143
+ /** @beta */
4144
+ export declare interface TranslateTarget extends AgentActionTarget {
4145
+ /** string template using $variable from instructionParams */
4146
+ styleGuide?: string
4147
+ /**
4148
+ * By default, all children up to `target.maxPathDepth` are included.
4149
+ *
4150
+ * When `include` is specified, only segments explicitly listed will be included.
4151
+ *
4152
+ * Fields or array items not on the include list, are implicitly excluded.
4153
+ */
4154
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
4155
+ }
4156
+
4157
+ /** @beta */
4158
+ export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
4159
+ /** string template using $variable from instructionParams */
4160
+ styleGuide?: string
4161
+ /**
4162
+ * By default, all children up to `target.maxPathDepth` are included.
4163
+ *
4164
+ * When `include` is specified, only segments explicitly listed will be included.
4165
+ *
4166
+ * Fields or array items not on the include list, are implicitly excluded.
4167
+ */
4168
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
4169
+ }
4170
+
4343
4171
  /** @public */
4344
4172
  export declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
4345
4173
  filterResponse: false