@sanity/client 7.2.2 → 7.4.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.
Files changed (54) hide show
  1. package/README.md +126 -1
  2. package/dist/_chunks-cjs/isRecord.cjs +6 -0
  3. package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
  4. package/dist/_chunks-cjs/resolveEditInfo.cjs +3 -5
  5. package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
  6. package/dist/_chunks-cjs/stegaClean.cjs +4 -0
  7. package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
  8. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -5
  9. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
  10. package/dist/_chunks-es/isRecord.js +7 -0
  11. package/dist/_chunks-es/isRecord.js.map +1 -0
  12. package/dist/_chunks-es/resolveEditInfo.js +1 -3
  13. package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
  14. package/dist/_chunks-es/stegaClean.js +4 -0
  15. package/dist/_chunks-es/stegaClean.js.map +1 -1
  16. package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -4
  17. package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
  18. package/dist/index.browser.cjs +158 -33
  19. package/dist/index.browser.cjs.map +1 -1
  20. package/dist/index.browser.d.cts +485 -68
  21. package/dist/index.browser.d.ts +485 -68
  22. package/dist/index.browser.js +159 -34
  23. package/dist/index.browser.js.map +1 -1
  24. package/dist/index.cjs +160 -35
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +485 -68
  27. package/dist/index.d.ts +485 -68
  28. package/dist/index.js +160 -34
  29. package/dist/index.js.map +1 -1
  30. package/dist/stega.browser.d.cts +485 -68
  31. package/dist/stega.browser.d.ts +485 -68
  32. package/dist/stega.d.cts +485 -68
  33. package/dist/stega.d.ts +485 -68
  34. package/package.json +1 -1
  35. package/src/agent/actions/AgentActionsClient.ts +29 -2
  36. package/src/agent/actions/commonTypes.ts +57 -17
  37. package/src/agent/actions/generate.ts +36 -2
  38. package/src/agent/actions/patch.ts +136 -0
  39. package/src/agent/actions/prompt.ts +145 -0
  40. package/src/agent/actions/transform.ts +27 -4
  41. package/src/agent/actions/translate.ts +5 -2
  42. package/src/csm/walkMap.ts +1 -1
  43. package/src/data/eventsource.ts +16 -7
  44. package/src/data/listen.ts +10 -4
  45. package/src/data/live.ts +13 -5
  46. package/src/defineCreateClient.ts +7 -1
  47. package/src/http/errors.ts +92 -27
  48. package/src/http/request.ts +3 -3
  49. package/src/http/requestOptions.ts +4 -0
  50. package/src/types.ts +39 -10
  51. package/src/util/codeFrame.ts +174 -0
  52. package/src/{csm → util}/isRecord.ts +1 -1
  53. package/umd/sanityClient.js +161 -36
  54. package/umd/sanityClient.min.js +2 -2
@@ -1,6 +1,7 @@
1
1
  import type {ContentSourceMapDocuments as ContentSourceMapDocuments_2} from '@sanity/client/csm'
2
2
  import {ContentSourceMapParsedPath} from '@sanity/client/csm'
3
3
  import {ContentSourceMapParsedPathKeyedSegment} from '@sanity/client/csm'
4
+ import type {HttpContext} from 'get-it'
4
5
  import {Observable} from 'rxjs'
5
6
  import {Requester} from 'get-it'
6
7
  import type {ResolveStudioUrl} from '@sanity/client/csm'
@@ -24,11 +25,9 @@ export declare type Action =
24
25
 
25
26
  /** @internal */
26
27
  export declare interface ActionError {
27
- error: {
28
- type: 'actionError'
29
- description: string
30
- items?: ActionErrorItem[]
31
- }
28
+ type: 'actionError'
29
+ description: string
30
+ items?: ActionErrorItem[]
32
31
  }
33
32
 
34
33
  /** @internal */
@@ -55,15 +54,27 @@ declare interface AgentActionAsync {
55
54
  }
56
55
 
57
56
  /** @beta */
58
- export declare type AgentActionParam =
57
+ export declare type AgentActionParam<
58
+ TParamConfig extends {
59
+ docIdRequired: boolean
60
+ } = {
61
+ docIdRequired: false
62
+ },
63
+ > =
59
64
  | string
60
65
  | ConstantAgentActionParam
61
- | FieldAgentActionParam
62
- | DocumentAgentActionParam
66
+ | FieldAgentActionParam<TParamConfig>
67
+ | DocumentAgentActionParam<TParamConfig>
63
68
  | GroqAgentActionParam
64
69
 
65
70
  /** @beta */
66
- export declare type AgentActionParams = Record<string, AgentActionParam>
71
+ export declare type AgentActionParams<
72
+ TParamConfig extends {
73
+ docIdRequired: boolean
74
+ } = {
75
+ docIdRequired: false
76
+ },
77
+ > = Record<string, AgentActionParam<TParamConfig>>
67
78
 
68
79
  /** @beta */
69
80
  export declare type AgentActionPath = AgentActionPathSegment[]
@@ -76,39 +87,7 @@ export declare type AgentActionPathSegment =
76
87
  }
77
88
 
78
89
  /** @beta */
79
- declare interface AgentActionRequestBase {
80
- /** schemaId as reported by sanity deploy / sanity schema store */
81
- schemaId: string
82
- /**
83
- * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
84
- *
85
- * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
86
- * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
87
- *
88
- * `conditionalPaths` param allows setting the default conditional value for
89
- * `hidden` and `readOnly` to false,
90
- * or individually set `hidden` and `readOnly` state for individual document paths.
91
- *
92
- * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
93
- * and cannot be changed via conditionalPaths
94
- *
95
- * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
96
- *
97
- * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
98
- * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
99
- *
100
- * @see GenerateRequestBase#target
101
- */
102
- conditionalPaths?: {
103
- defaultReadOnly?: boolean
104
- defaultHidden?: boolean
105
- paths?: {
106
- /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
107
- path: AgentActionPath
108
- readOnly: boolean
109
- hidden: boolean
110
- }[]
111
- }
90
+ declare interface AgentActionRequestBase extends AgentActionSchema {
112
91
  /**
113
92
  * When localeSettings is provided on the request, instruct can write to date and datetime fields.
114
93
  * Otherwise, such fields will be ignored.
@@ -149,6 +128,68 @@ declare interface AgentActionRequestBase {
149
128
  temperature?: number
150
129
  }
151
130
 
131
+ /** @beta */
132
+ declare interface AgentActionSchema {
133
+ /** schemaId as reported by sanity deploy / sanity schema store */
134
+ schemaId: string
135
+ /**
136
+ * ### forcePublishedWrite: false (default)
137
+ * By default, agent actions will never write to a published document.
138
+ *
139
+ * Instead, they will force the use of a draft ID ("drafts.some-id") instead of the published ID ("some-id"),
140
+ * even when a published ID is provided.
141
+ *
142
+ * Actions will use state from an existing draft if it exists,
143
+ * or use the published document to create a draft, if no draft exists.
144
+ *
145
+ * Successful responses contains the _id that was mutated by the action.
146
+ *
147
+ *
148
+ * ### forcePublishedWrite: true
149
+ *
150
+ * When forcePublishedWrite: true an agent action will write to the exact id provided.
151
+ * The action will also not fallback to published state for draft ids.
152
+ *
153
+ *
154
+ * ### Versioned ids (releases)
155
+ *
156
+ * When an ID on the form "versions.<release>.some-id" is provided, agent actions will
157
+ * always behave as if `forcePublishedWrite: true`.
158
+ * That is, only the exact document state of the id provided is considered and mutated.
159
+ * */
160
+ forcePublishedWrite?: boolean
161
+ /**
162
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
163
+ *
164
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
165
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
166
+ *
167
+ * `conditionalPaths` param allows setting the default conditional value for
168
+ * `hidden` and `readOnly` to false,
169
+ * or individually set `hidden` and `readOnly` state for individual document paths.
170
+ *
171
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
172
+ * and cannot be changed via conditionalPaths
173
+ *
174
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
175
+ *
176
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
177
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
178
+ *
179
+ * @see GenerateRequestBase#target
180
+ */
181
+ conditionalPaths?: {
182
+ defaultReadOnly?: boolean
183
+ defaultHidden?: boolean
184
+ paths?: {
185
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
186
+ path: AgentActionPath
187
+ readOnly: boolean
188
+ hidden: boolean
189
+ }[]
190
+ }
191
+ }
192
+
152
193
  /** @public */
153
194
  declare class AgentActionsClient {
154
195
  #private
@@ -192,6 +233,27 @@ declare class AgentActionsClient {
192
233
  }
193
234
  : IdentifiedSanityDocumentStub & DocumentShape
194
235
  >
236
+ /**
237
+ * Run a raw instruction and return the result either as text or json
238
+ * @param request - prompt request
239
+ */
240
+ prompt<const DocumentShape extends Record<string, Any>>(
241
+ request: PromptRequest<DocumentShape>,
242
+ ): Promise<(typeof request)['format'] extends 'json' ? DocumentShape : string>
243
+ /**
244
+ * Patch a document using a schema aware API.
245
+ * Does not use an LLM, but uses the schema to ensure paths and values matches the schema.
246
+ * @param request - instruction request
247
+ */
248
+ patch<DocumentShape extends Record<string, Any>>(
249
+ request: PatchDocument<DocumentShape>,
250
+ ): Promise<
251
+ (typeof request)['async'] extends true
252
+ ? {
253
+ _id: string
254
+ }
255
+ : IdentifiedSanityDocumentStub & DocumentShape
256
+ >
195
257
  }
196
258
 
197
259
  /** @beta */
@@ -315,6 +377,8 @@ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
315
377
  */
316
378
  export declare type Any = any
317
379
 
380
+ declare type AnyNonNullable = Exclude<any, null | undefined>
381
+
318
382
  /** @internal */
319
383
  export declare interface ApiError {
320
384
  error: string
@@ -627,6 +691,12 @@ export declare interface ClientConfig {
627
691
  * Optional request tag prefix for all request tags
628
692
  */
629
693
  requestTagPrefix?: string
694
+ /**
695
+ * Optional default headers to include with all requests
696
+ *
697
+ * @remarks request-specific headers will override any default headers with the same name.
698
+ */
699
+ headers?: Record<string, string>
630
700
  ignoreBrowserTokenWarning?: boolean
631
701
  withCredentials?: boolean
632
702
  allowReconfigure?: boolean
@@ -693,7 +763,7 @@ export declare class ClientError extends Error {
693
763
  statusCode: ErrorProps['statusCode']
694
764
  responseBody: ErrorProps['responseBody']
695
765
  details: ErrorProps['details']
696
- constructor(res: Any)
766
+ constructor(res: Any, context?: HttpContext)
697
767
  }
698
768
 
699
769
  /** @public */
@@ -1095,6 +1165,23 @@ export declare type DisconnectEvent = {
1095
1165
  reason: string
1096
1166
  }
1097
1167
 
1168
+ declare type DocIdParam<
1169
+ TParamConfig extends {
1170
+ docIdRequired: boolean
1171
+ } = {
1172
+ docIdRequired: false
1173
+ },
1174
+ > = TParamConfig['docIdRequired'] extends true
1175
+ ? {
1176
+ documentId: string
1177
+ }
1178
+ : {
1179
+ /**
1180
+ * If omitted, implicitly uses the documentId of the instruction target
1181
+ */
1182
+ documentId?: string
1183
+ }
1184
+
1098
1185
  /**
1099
1186
  *
1100
1187
  * Includes a LLM-friendly version of the document in the instruction
@@ -1115,13 +1202,15 @@ export declare type DisconnectEvent = {
1115
1202
  *
1116
1203
  * @beta
1117
1204
  * */
1118
- export declare interface DocumentAgentActionParam {
1205
+ export declare type DocumentAgentActionParam<
1206
+ TParamConfig extends {
1207
+ docIdRequired: boolean
1208
+ } = {
1209
+ docIdRequired: false
1210
+ },
1211
+ > = {
1119
1212
  type: 'document'
1120
- /**
1121
- * If omitted, implicitly uses the documentId of the instruction target
1122
- */
1123
- documentId?: string
1124
- }
1213
+ } & DocIdParam<TParamConfig>
1125
1214
 
1126
1215
  /** @internal */
1127
1216
  export declare type EditableReleaseDocument = Omit<
@@ -1208,17 +1297,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
1208
1297
  *
1209
1298
  * @beta
1210
1299
  * */
1211
- export declare interface FieldAgentActionParam {
1300
+ export declare type FieldAgentActionParam<
1301
+ TParamConfig extends {
1302
+ docIdRequired: boolean
1303
+ } = {
1304
+ docIdRequired: false
1305
+ },
1306
+ > = {
1212
1307
  type: 'field'
1213
1308
  /**
1214
1309
  * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1215
1310
  */
1216
1311
  path: AgentActionPathSegment | AgentActionPath
1217
- /**
1218
- * If omitted, implicitly uses the documentId of the instruction target
1219
- */
1220
- documentId?: string
1221
- }
1312
+ } & DocIdParam<TParamConfig>
1222
1313
 
1223
1314
  /** @public */
1224
1315
  export declare type FilterDefault = (props: {
@@ -1286,6 +1377,16 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1286
1377
  returnDocuments?: true
1287
1378
  }
1288
1379
 
1380
+ /**
1381
+ * Formats a GROQ query parse error into a human-readable string.
1382
+ *
1383
+ * @param error - The error object containing details about the parse error.
1384
+ * @param tag - An optional tag to include in the error message.
1385
+ * @returns A formatted error message string.
1386
+ * @public
1387
+ */
1388
+ export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
1389
+
1289
1390
  /** @beta */
1290
1391
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1291
1392
  | GenerateExistingDocumentRequest
@@ -1299,8 +1400,11 @@ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<str
1299
1400
  * @beta
1300
1401
  */
1301
1402
  declare interface GenerateExistingDocumentRequest {
1403
+ /**
1404
+ * @see #AgentActionSchema.forcePublishedWrite
1405
+ */
1302
1406
  documentId: string
1303
- createDocument?: never
1407
+ targetDocument?: never
1304
1408
  }
1305
1409
 
1306
1410
  /** @beta */
@@ -1320,7 +1424,7 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1320
1424
  *
1321
1425
  * The LLM only has access to information in the instruction, plus the target schema.
1322
1426
  *
1323
- * string template using $variable
1427
+ * String template with support for $variable from `instructionParams`.
1324
1428
  * */
1325
1429
  instruction: string
1326
1430
  /**
@@ -1415,6 +1519,21 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1415
1519
  * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1416
1520
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1417
1521
  *
1522
+ * ## Generating images
1523
+ *
1524
+ * Generate will generate images the same was as AI Assist, for images that have been configured using
1525
+ * [AI Assist schema options](https://github.com/sanity-io/assist/tree/main/plugin#image-generation).
1526
+ *
1527
+ * To generate images _without_ changing the schema, directly target an image asset path.
1528
+ *
1529
+ * For example, all the following will generate an image into the provided asset:
1530
+ * * `target: {path: ['image', 'asset'] }`
1531
+ * * `target: {path: 'image', include: ['asset'] }`
1532
+ *
1533
+ * Image generation can be combined with regular content targets:
1534
+ * * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
1535
+ *
1536
+ * Since Generate happens in a single LLM pass, the image will be contextually related to other generated content.
1418
1537
  * @see AgentActionRequestBase#conditionalPaths
1419
1538
  */
1420
1539
  target?: GenerateTarget | GenerateTarget[]
@@ -1461,6 +1580,7 @@ export declare interface GenerateTarget extends AgentActionTarget {
1461
1580
  * @see #AgentActionTargetInclude.operation
1462
1581
  * @see #include
1463
1582
  * @see #AgentActionTargetInclude.include
1583
+ * @see #AgentActionSchema.forcePublishedWrite
1464
1584
  */
1465
1585
  operation?: GenerateOperation
1466
1586
  /**
@@ -1477,22 +1597,34 @@ export declare interface GenerateTarget extends AgentActionTarget {
1477
1597
  export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1478
1598
  | {
1479
1599
  operation: 'edit'
1600
+ /**
1601
+ * @see #AgentActionSchema.forcePublishedWrite
1602
+ */
1480
1603
  _id: string
1481
1604
  }
1482
1605
  | {
1483
1606
  operation: 'create'
1607
+ /**
1608
+ * @see #AgentActionSchema.forcePublishedWrite
1609
+ */
1484
1610
  _id?: string
1485
1611
  _type: string
1486
1612
  initialValues?: T
1487
1613
  }
1488
1614
  | {
1489
1615
  operation: 'createIfNotExists'
1616
+ /**
1617
+ * @see #AgentActionSchema.forcePublishedWrite
1618
+ */
1490
1619
  _id: string
1491
1620
  _type: string
1492
1621
  initialValues?: T
1493
1622
  }
1494
1623
  | {
1495
1624
  operation: 'createOrReplace'
1625
+ /**
1626
+ * @see #AgentActionSchema.forcePublishedWrite
1627
+ */
1496
1628
  _id: string
1497
1629
  _type: string
1498
1630
  initialValues?: T
@@ -1505,6 +1637,9 @@ export declare type GenerateTargetDocument<T extends Record<string, Any> = Recor
1505
1637
  declare interface GenerateTargetDocumentRequest<
1506
1638
  T extends Record<string, Any> = Record<string, Any>,
1507
1639
  > {
1640
+ /**
1641
+ * @see #AgentActionSchema.forcePublishedWrite
1642
+ */
1508
1643
  targetDocument: GenerateTargetDocument<T>
1509
1644
  documentId?: never
1510
1645
  }
@@ -1593,6 +1728,12 @@ export declare interface InitializedClientConfig extends ClientConfig {
1593
1728
  * The fully initialized stega config, can be used to check if stega is enabled
1594
1729
  */
1595
1730
  stega: InitializedStegaConfig
1731
+ /**
1732
+ * Default headers to include with all requests
1733
+ *
1734
+ * @remarks request-specific headers will override any default headers with the same name.
1735
+ */
1736
+ headers?: Record<string, string>
1596
1737
  }
1597
1738
 
1598
1739
  /** @public */
@@ -1614,6 +1755,9 @@ export declare type InsertPatch =
1614
1755
  items: Any[]
1615
1756
  }
1616
1757
 
1758
+ /** @internal */
1759
+ export declare function isQueryParseError(error: object): error is QueryParseError
1760
+
1617
1761
  /**
1618
1762
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1619
1763
  *
@@ -1847,11 +1991,9 @@ export declare type Mutation<R extends Record<string, Any> = Record<string, Any>
1847
1991
 
1848
1992
  /** @internal */
1849
1993
  export declare interface MutationError {
1850
- error: {
1851
- type: 'mutationError'
1852
- description: string
1853
- items?: MutationErrorItem[]
1854
- }
1994
+ type: 'mutationError'
1995
+ description: string
1996
+ items?: MutationErrorItem[]
1855
1997
  }
1856
1998
 
1857
1999
  /** @internal */
@@ -3370,9 +3512,45 @@ export declare class Patch extends BasePatch {
3370
3512
  /** @public */
3371
3513
  export declare type PatchBuilder = (patch: Patch) => Patch
3372
3514
 
3515
+ /** @beta */
3516
+ export declare type PatchDocument<T extends Record<string, Any> = Record<string, Any>> =
3517
+ | PatchDocumentSync<T>
3518
+ | PatchDocumentAsync<T>
3519
+
3520
+ /** @beta */
3521
+ declare type PatchDocumentAsync<T extends Record<string, Any> = Record<string, Any>> = (
3522
+ | PatchExistingDocumentRequest
3523
+ | PatchTargetDocumentRequest<T>
3524
+ ) &
3525
+ PatchRequestBase &
3526
+ AgentActionAsync
3527
+
3528
+ /** @beta */
3529
+ declare type PatchDocumentSync<T extends Record<string, Any> = Record<string, Any>> = (
3530
+ | PatchExistingDocumentRequest
3531
+ | PatchTargetDocumentRequest<T>
3532
+ ) &
3533
+ PatchRequestBase &
3534
+ AgentActionSync
3535
+
3536
+ /**
3537
+ * Patches an existing document
3538
+ * @beta
3539
+ */
3540
+ declare interface PatchExistingDocumentRequest {
3541
+ /**
3542
+ * @see #AgentActionSchema.forcePublishedWrite
3543
+ */
3544
+ documentId: string
3545
+ targetDocument?: never
3546
+ }
3547
+
3373
3548
  /** @internal */
3374
3549
  export declare type PatchMutationOperation = PatchOperations & MutationSelection
3375
3550
 
3551
+ /** @beta */
3552
+ export declare type PatchOperation = 'set' | 'append' | 'mixed' | 'unset'
3553
+
3376
3554
  /** @internal */
3377
3555
  export declare interface PatchOperations {
3378
3556
  set?: {
@@ -3395,9 +3573,80 @@ export declare interface PatchOperations {
3395
3573
  ifRevisionID?: string
3396
3574
  }
3397
3575
 
3576
+ /** @beta */
3577
+ declare interface PatchRequestBase extends AgentActionSchema {
3578
+ /**
3579
+ * Target defines which parts of the document will be affected by the instruction.
3580
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
3581
+ *
3582
+ * Omitting target implies that the document itself is the root.
3583
+ *
3584
+ * Notes:
3585
+ * - instruction can only affect fields up to `maxPathDepth`
3586
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
3587
+ * It is therefore an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
3588
+ *
3589
+ * @see AgentActionRequestBase#conditionalPaths
3590
+ */
3591
+ target: PatchTarget | PatchTarget[]
3592
+ }
3593
+
3398
3594
  /** @internal */
3399
3595
  export declare type PatchSelection = string | string[] | MutationSelection
3400
3596
 
3597
+ /** @beta */
3598
+ export declare type PatchTarget = {
3599
+ /**
3600
+ * Determines how the target path will be patched.
3601
+ *
3602
+ * ### Operation types
3603
+ * - `'set'` – an *overwriting* operation: sets the full field value for primitive targets, and merges the provided value with existing values for objects
3604
+ * - `'append'`:
3605
+ * – array fields: appends new items to the end of the array,
3606
+ * - string fields: '"existing content" "new content"'
3607
+ * - text fields: '"existing content"\\n"new content"'
3608
+ * - number fields: existing + new
3609
+ * - other field types not mentioned will set instead (dates, url)
3610
+ * - `'mixed'` – sets non-array fields, and appends to array fields
3611
+ * - `'unset'` – removes whatever value is on the target path
3612
+ *
3613
+ * All operations except unset requires a `value`.
3614
+ *
3615
+ * #### Appending in the middle of arrays
3616
+ * To append to an array, use the 'append' operation, and provide an array value with one or more array items.
3617
+ *
3618
+ * `target: {path: ['array'], operation: 'append', value: [{_type: 'item' _key: 'a'}]}` will append the items in the value to the existing array.
3619
+ *
3620
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append', value: [{_type: 'item' _key: 'a'}]}`.
3621
+ * Here, `{_type: 'item' _key: 'a'}` will be appended after the array item with key `'appendAfterKey'`
3622
+ *
3623
+ * It is optional to provide a _key for inserted array items; if one isn't provided, it will be generated.
3624
+ */
3625
+ operation: PatchOperation
3626
+ path: AgentActionPathSegment | AgentActionPath
3627
+ } & (
3628
+ | {
3629
+ operation: 'unset'
3630
+ value?: never
3631
+ }
3632
+ | {
3633
+ operation: Exclude<PatchOperation, 'unset'>
3634
+ value: AnyNonNullable
3635
+ }
3636
+ )
3637
+
3638
+ /**
3639
+ * Create a new document, then patch it
3640
+ * @beta
3641
+ */
3642
+ declare interface PatchTargetDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
3643
+ /**
3644
+ * @see #AgentActionSchema.forcePublishedWrite
3645
+ */
3646
+ targetDocument: GenerateTargetDocument<T>
3647
+ documentId?: never
3648
+ }
3649
+
3401
3650
  /** @public */
3402
3651
  declare interface ProgressEvent_2 {
3403
3652
  type: 'progress'
@@ -3429,6 +3678,131 @@ export declare class ProjectsClient {
3429
3678
  getById(projectId: string): Promise<SanityProject>
3430
3679
  }
3431
3680
 
3681
+ /**
3682
+ * @beta
3683
+ */
3684
+ declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
3685
+ /**
3686
+ *
3687
+ * When true, the response body will be json according to the instruction.
3688
+ * When false, the response is the raw text response to the instruction.
3689
+ *
3690
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3691
+ */
3692
+ format: 'json'
3693
+ }
3694
+
3695
+ /** @beta */
3696
+ export declare type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
3697
+ | PromptTextResponse
3698
+ | PromptJsonResponse<T>
3699
+ ) &
3700
+ PromptRequestBase
3701
+
3702
+ /** @beta */
3703
+ declare interface PromptRequestBase {
3704
+ /**
3705
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
3706
+ *
3707
+ * The LLM only has access to information in the instruction, plus the target schema.
3708
+ *
3709
+ * String template with support for $variable from `instructionParams`.
3710
+ * */
3711
+ instruction: string
3712
+ /**
3713
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3714
+ *
3715
+ * ### Examples
3716
+ *
3717
+ * #### Constant
3718
+ *
3719
+ * ##### Shorthand
3720
+ * ```ts
3721
+ * client.agent.action.prompt({
3722
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
3723
+ * instructionParams: {
3724
+ * topic: 'Grapefruit'
3725
+ * },
3726
+ * })
3727
+ * ```
3728
+ * ##### Object-form
3729
+ *
3730
+ * ```ts
3731
+ * client.agent.action.prompt({
3732
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
3733
+ * instructionParams: {
3734
+ * topic: {
3735
+ * type: 'constant',
3736
+ * value: 'Grapefruit'
3737
+ * },
3738
+ * },
3739
+ * })
3740
+ * ```
3741
+ * #### Field
3742
+ * ```ts
3743
+ * client.agent.action.prompt({
3744
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3745
+ * instructionParams: {
3746
+ * pte: {
3747
+ * type: 'field',
3748
+ * path: ['pteField'],
3749
+ * documentId: 'someSanityDocId'
3750
+ * },
3751
+ * },
3752
+ * })
3753
+ * ```
3754
+ * #### Document
3755
+ * ```ts
3756
+ * client.agent.action.prompt({
3757
+ * json: true,
3758
+ * instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
3759
+ * instructionParams: {
3760
+ * document: {
3761
+ * type: 'document',
3762
+ * documentId: 'someSanityDocId'
3763
+ * },
3764
+ * },
3765
+ * })
3766
+ * ```
3767
+ *
3768
+ * #### GROQ
3769
+ * ```ts
3770
+ * client.agent.action.prompt({
3771
+ * instruction: 'Return the best title amongst these: $titles.',
3772
+ * instructionParams: {
3773
+ * titles: {
3774
+ * type: 'groq',
3775
+ * query: '* [_type==$type].title',
3776
+ * params: {type: 'article'}
3777
+ * },
3778
+ * },
3779
+ * })
3780
+ * ```
3781
+ * */
3782
+ instructionParams?: AgentActionParams<{
3783
+ docIdRequired: true
3784
+ }>
3785
+ /**
3786
+ * Controls how much variance the instructions will run with.
3787
+ *
3788
+ * Value must be in the range [0, 1] (inclusive).
3789
+ *
3790
+ * Default: 0.3
3791
+ */
3792
+ temperature?: number
3793
+ }
3794
+
3795
+ declare interface PromptTextResponse {
3796
+ /**
3797
+ *
3798
+ * When true, the response body will be json according to the instruction.
3799
+ * When false, the response is the raw text response to the instruction.
3800
+ *
3801
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3802
+ */
3803
+ format?: 'text'
3804
+ }
3805
+
3432
3806
  /**
3433
3807
  * Publishes a draft document.
3434
3808
  * If a published version of the document already exists this is replaced by the current draft document.
@@ -3515,6 +3889,23 @@ export declare interface QueryParams {
3515
3889
  cacheMode?: never
3516
3890
  }
3517
3891
 
3892
+ /**
3893
+ * Returned from the Content Lake API when a query is malformed, usually with a start
3894
+ * and end column to indicate where the error occurred, but not always. Can we used to
3895
+ * provide a more structured error message to the user.
3896
+ *
3897
+ * This will be located under the response `error` property.
3898
+ *
3899
+ * @public
3900
+ */
3901
+ export declare interface QueryParseError {
3902
+ type: 'queryParseError'
3903
+ description: string
3904
+ start?: number
3905
+ end?: number
3906
+ query?: string
3907
+ }
3908
+
3518
3909
  /**
3519
3910
  * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3520
3911
  * @public
@@ -5121,6 +5512,8 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5121
5512
  schemaId: string
5122
5513
  /**
5123
5514
  * The source document the transformation will use as input.
5515
+ *
5516
+ * @see #AgentActionSchema.forcePublishedWrite
5124
5517
  */
5125
5518
  documentId: string
5126
5519
  /**
@@ -5128,12 +5521,14 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5128
5521
  * then it is transformed according to the instruction.
5129
5522
  *
5130
5523
  * When omitted, the source document (documentId) is also the target document.
5524
+ *
5525
+ * @see #AgentActionSchema.forcePublishedWrite
5131
5526
  */
5132
5527
  targetDocument?: TransformTargetDocument
5133
5528
  /**
5134
5529
  * Instruct the LLM how to transform the input to th output.
5135
5530
  *
5136
- * String template using $variable from instructionParams.
5531
+ * String template with support for $variable from `instructionParams`.
5137
5532
  *
5138
5533
  * Capped to 2000 characters, after variables has been injected.
5139
5534
  * */
@@ -5232,6 +5627,21 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5232
5627
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
5233
5628
  *
5234
5629
  * Default max depth for transform: 12
5630
+ *
5631
+ * ## Transforming images
5632
+ *
5633
+ * To transform an existing image, directly target an image asset path.
5634
+ *
5635
+ * For example, all the following will transform the image into the provided asset:
5636
+ * * `target: {path: ['image', 'asset'] }`
5637
+ * * `target: {path: 'image', include: ['asset'] }`
5638
+ *
5639
+ * Image transform can be combined with regular content targets:
5640
+ * * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
5641
+ *
5642
+ * Image transform can have per-path instructions, just like any other target paths:
5643
+ * * `target: [{path: ['image', 'asset'], instruction: 'Make the sky blue' }`
5644
+ *
5235
5645
  * @see AgentActionRequestBase#conditionalPaths
5236
5646
  */
5237
5647
  target?: TransformTarget | TransformTarget[]
@@ -5242,7 +5652,7 @@ export declare interface TransformTarget extends AgentActionTarget {
5242
5652
  /**
5243
5653
  * Specifies a tailored instruction of this target.
5244
5654
  *
5245
- * string template using $variable from instructionParams.
5655
+ * String template with support for $variable from `instructionParams`.
5246
5656
  * */
5247
5657
  instruction?: string
5248
5658
  /**
@@ -5255,7 +5665,11 @@ export declare interface TransformTarget extends AgentActionTarget {
5255
5665
  include?: (AgentActionPathSegment | TransformTargetInclude)[]
5256
5666
  }
5257
5667
 
5258
- /** @beta */
5668
+ /**
5669
+ * @see #AgentActionSchema.forcePublishedWrite
5670
+ *
5671
+ * @beta
5672
+ */
5259
5673
  export declare type TransformTargetDocument =
5260
5674
  | {
5261
5675
  operation: 'edit'
@@ -5279,7 +5693,7 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
5279
5693
  /**
5280
5694
  * Specifies a tailored instruction of this target.
5281
5695
  *
5282
- * string template using $variable from instructionParams */
5696
+ * String template with support for $variable from `instructionParams`. */
5283
5697
  instruction?: string
5284
5698
  /**
5285
5699
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5321,6 +5735,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5321
5735
  schemaId: string
5322
5736
  /**
5323
5737
  * The source document the transformation will use as input.
5738
+ * @see #AgentActionSchema.forcePublishedWrite
5324
5739
  */
5325
5740
  documentId: string
5326
5741
  /**
@@ -5328,6 +5743,8 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5328
5743
  * then it is translated according to the instruction.
5329
5744
  *
5330
5745
  * When omitted, the source document (documentId) is also the target document.
5746
+ *
5747
+ * @see #AgentActionSchema.forcePublishedWrite
5331
5748
  */
5332
5749
  targetDocument?: TransformTargetDocument
5333
5750
  /**
@@ -5380,7 +5797,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5380
5797
 
5381
5798
  /** @beta */
5382
5799
  export declare interface TranslateTarget extends AgentActionTarget {
5383
- /** string template using $variable from instructionParams */
5800
+ /** String template using $variable from styleGuideParams. */
5384
5801
  styleGuide?: string
5385
5802
  /**
5386
5803
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5394,7 +5811,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
5394
5811
 
5395
5812
  /** @beta */
5396
5813
  export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
5397
- /** string template using $variable from instructionParams */
5814
+ /** String template using $variable from styleGuideParams. */
5398
5815
  styleGuide?: string
5399
5816
  /**
5400
5817
  * By default, all children up to `target.maxPathDepth` are included.