@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
package/dist/index.d.cts CHANGED
@@ -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 */
@@ -1099,6 +1169,23 @@ export declare type DisconnectEvent = {
1099
1169
  reason: string
1100
1170
  }
1101
1171
 
1172
+ declare type DocIdParam<
1173
+ TParamConfig extends {
1174
+ docIdRequired: boolean
1175
+ } = {
1176
+ docIdRequired: false
1177
+ },
1178
+ > = TParamConfig['docIdRequired'] extends true
1179
+ ? {
1180
+ documentId: string
1181
+ }
1182
+ : {
1183
+ /**
1184
+ * If omitted, implicitly uses the documentId of the instruction target
1185
+ */
1186
+ documentId?: string
1187
+ }
1188
+
1102
1189
  /**
1103
1190
  *
1104
1191
  * Includes a LLM-friendly version of the document in the instruction
@@ -1119,13 +1206,15 @@ export declare type DisconnectEvent = {
1119
1206
  *
1120
1207
  * @beta
1121
1208
  * */
1122
- export declare interface DocumentAgentActionParam {
1209
+ export declare type DocumentAgentActionParam<
1210
+ TParamConfig extends {
1211
+ docIdRequired: boolean
1212
+ } = {
1213
+ docIdRequired: false
1214
+ },
1215
+ > = {
1123
1216
  type: 'document'
1124
- /**
1125
- * If omitted, implicitly uses the documentId of the instruction target
1126
- */
1127
- documentId?: string
1128
- }
1217
+ } & DocIdParam<TParamConfig>
1129
1218
 
1130
1219
  /** @internal */
1131
1220
  export declare type EditableReleaseDocument = Omit<
@@ -1212,17 +1301,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
1212
1301
  *
1213
1302
  * @beta
1214
1303
  * */
1215
- export declare interface FieldAgentActionParam {
1304
+ export declare type FieldAgentActionParam<
1305
+ TParamConfig extends {
1306
+ docIdRequired: boolean
1307
+ } = {
1308
+ docIdRequired: false
1309
+ },
1310
+ > = {
1216
1311
  type: 'field'
1217
1312
  /**
1218
1313
  * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1219
1314
  */
1220
1315
  path: AgentActionPathSegment | AgentActionPath
1221
- /**
1222
- * If omitted, implicitly uses the documentId of the instruction target
1223
- */
1224
- documentId?: string
1225
- }
1316
+ } & DocIdParam<TParamConfig>
1226
1317
 
1227
1318
  /** @public */
1228
1319
  export declare type FilterDefault = (props: {
@@ -1290,6 +1381,16 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1290
1381
  returnDocuments?: true
1291
1382
  }
1292
1383
 
1384
+ /**
1385
+ * Formats a GROQ query parse error into a human-readable string.
1386
+ *
1387
+ * @param error - The error object containing details about the parse error.
1388
+ * @param tag - An optional tag to include in the error message.
1389
+ * @returns A formatted error message string.
1390
+ * @public
1391
+ */
1392
+ export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
1393
+
1293
1394
  /** @beta */
1294
1395
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1295
1396
  | GenerateExistingDocumentRequest
@@ -1303,8 +1404,11 @@ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<str
1303
1404
  * @beta
1304
1405
  */
1305
1406
  declare interface GenerateExistingDocumentRequest {
1407
+ /**
1408
+ * @see #AgentActionSchema.forcePublishedWrite
1409
+ */
1306
1410
  documentId: string
1307
- createDocument?: never
1411
+ targetDocument?: never
1308
1412
  }
1309
1413
 
1310
1414
  /** @beta */
@@ -1324,7 +1428,7 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1324
1428
  *
1325
1429
  * The LLM only has access to information in the instruction, plus the target schema.
1326
1430
  *
1327
- * string template using $variable
1431
+ * String template with support for $variable from `instructionParams`.
1328
1432
  * */
1329
1433
  instruction: string
1330
1434
  /**
@@ -1419,6 +1523,21 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1419
1523
  * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1420
1524
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1421
1525
  *
1526
+ * ## Generating images
1527
+ *
1528
+ * Generate will generate images the same was as AI Assist, for images that have been configured using
1529
+ * [AI Assist schema options](https://github.com/sanity-io/assist/tree/main/plugin#image-generation).
1530
+ *
1531
+ * To generate images _without_ changing the schema, directly target an image asset path.
1532
+ *
1533
+ * For example, all the following will generate an image into the provided asset:
1534
+ * * `target: {path: ['image', 'asset'] }`
1535
+ * * `target: {path: 'image', include: ['asset'] }`
1536
+ *
1537
+ * Image generation can be combined with regular content targets:
1538
+ * * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
1539
+ *
1540
+ * Since Generate happens in a single LLM pass, the image will be contextually related to other generated content.
1422
1541
  * @see AgentActionRequestBase#conditionalPaths
1423
1542
  */
1424
1543
  target?: GenerateTarget | GenerateTarget[]
@@ -1465,6 +1584,7 @@ export declare interface GenerateTarget extends AgentActionTarget {
1465
1584
  * @see #AgentActionTargetInclude.operation
1466
1585
  * @see #include
1467
1586
  * @see #AgentActionTargetInclude.include
1587
+ * @see #AgentActionSchema.forcePublishedWrite
1468
1588
  */
1469
1589
  operation?: GenerateOperation
1470
1590
  /**
@@ -1481,22 +1601,34 @@ export declare interface GenerateTarget extends AgentActionTarget {
1481
1601
  export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1482
1602
  | {
1483
1603
  operation: 'edit'
1604
+ /**
1605
+ * @see #AgentActionSchema.forcePublishedWrite
1606
+ */
1484
1607
  _id: string
1485
1608
  }
1486
1609
  | {
1487
1610
  operation: 'create'
1611
+ /**
1612
+ * @see #AgentActionSchema.forcePublishedWrite
1613
+ */
1488
1614
  _id?: string
1489
1615
  _type: string
1490
1616
  initialValues?: T
1491
1617
  }
1492
1618
  | {
1493
1619
  operation: 'createIfNotExists'
1620
+ /**
1621
+ * @see #AgentActionSchema.forcePublishedWrite
1622
+ */
1494
1623
  _id: string
1495
1624
  _type: string
1496
1625
  initialValues?: T
1497
1626
  }
1498
1627
  | {
1499
1628
  operation: 'createOrReplace'
1629
+ /**
1630
+ * @see #AgentActionSchema.forcePublishedWrite
1631
+ */
1500
1632
  _id: string
1501
1633
  _type: string
1502
1634
  initialValues?: T
@@ -1509,6 +1641,9 @@ export declare type GenerateTargetDocument<T extends Record<string, Any> = Recor
1509
1641
  declare interface GenerateTargetDocumentRequest<
1510
1642
  T extends Record<string, Any> = Record<string, Any>,
1511
1643
  > {
1644
+ /**
1645
+ * @see #AgentActionSchema.forcePublishedWrite
1646
+ */
1512
1647
  targetDocument: GenerateTargetDocument<T>
1513
1648
  documentId?: never
1514
1649
  }
@@ -1597,6 +1732,12 @@ export declare interface InitializedClientConfig extends ClientConfig {
1597
1732
  * The fully initialized stega config, can be used to check if stega is enabled
1598
1733
  */
1599
1734
  stega: InitializedStegaConfig
1735
+ /**
1736
+ * Default headers to include with all requests
1737
+ *
1738
+ * @remarks request-specific headers will override any default headers with the same name.
1739
+ */
1740
+ headers?: Record<string, string>
1600
1741
  }
1601
1742
 
1602
1743
  /** @public */
@@ -1618,6 +1759,9 @@ export declare type InsertPatch =
1618
1759
  items: Any[]
1619
1760
  }
1620
1761
 
1762
+ /** @internal */
1763
+ export declare function isQueryParseError(error: object): error is QueryParseError
1764
+
1621
1765
  /**
1622
1766
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1623
1767
  *
@@ -1851,11 +1995,9 @@ export declare type Mutation<R extends Record<string, Any> = Record<string, Any>
1851
1995
 
1852
1996
  /** @internal */
1853
1997
  export declare interface MutationError {
1854
- error: {
1855
- type: 'mutationError'
1856
- description: string
1857
- items?: MutationErrorItem[]
1858
- }
1998
+ type: 'mutationError'
1999
+ description: string
2000
+ items?: MutationErrorItem[]
1859
2001
  }
1860
2002
 
1861
2003
  /** @internal */
@@ -3374,9 +3516,45 @@ export declare class Patch extends BasePatch {
3374
3516
  /** @public */
3375
3517
  export declare type PatchBuilder = (patch: Patch) => Patch
3376
3518
 
3519
+ /** @beta */
3520
+ export declare type PatchDocument<T extends Record<string, Any> = Record<string, Any>> =
3521
+ | PatchDocumentSync<T>
3522
+ | PatchDocumentAsync<T>
3523
+
3524
+ /** @beta */
3525
+ declare type PatchDocumentAsync<T extends Record<string, Any> = Record<string, Any>> = (
3526
+ | PatchExistingDocumentRequest
3527
+ | PatchTargetDocumentRequest<T>
3528
+ ) &
3529
+ PatchRequestBase &
3530
+ AgentActionAsync
3531
+
3532
+ /** @beta */
3533
+ declare type PatchDocumentSync<T extends Record<string, Any> = Record<string, Any>> = (
3534
+ | PatchExistingDocumentRequest
3535
+ | PatchTargetDocumentRequest<T>
3536
+ ) &
3537
+ PatchRequestBase &
3538
+ AgentActionSync
3539
+
3540
+ /**
3541
+ * Patches an existing document
3542
+ * @beta
3543
+ */
3544
+ declare interface PatchExistingDocumentRequest {
3545
+ /**
3546
+ * @see #AgentActionSchema.forcePublishedWrite
3547
+ */
3548
+ documentId: string
3549
+ targetDocument?: never
3550
+ }
3551
+
3377
3552
  /** @internal */
3378
3553
  export declare type PatchMutationOperation = PatchOperations & MutationSelection
3379
3554
 
3555
+ /** @beta */
3556
+ export declare type PatchOperation = 'set' | 'append' | 'mixed' | 'unset'
3557
+
3380
3558
  /** @internal */
3381
3559
  export declare interface PatchOperations {
3382
3560
  set?: {
@@ -3399,9 +3577,80 @@ export declare interface PatchOperations {
3399
3577
  ifRevisionID?: string
3400
3578
  }
3401
3579
 
3580
+ /** @beta */
3581
+ declare interface PatchRequestBase extends AgentActionSchema {
3582
+ /**
3583
+ * Target defines which parts of the document will be affected by the instruction.
3584
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
3585
+ *
3586
+ * Omitting target implies that the document itself is the root.
3587
+ *
3588
+ * Notes:
3589
+ * - instruction can only affect fields up to `maxPathDepth`
3590
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
3591
+ * It is therefore an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
3592
+ *
3593
+ * @see AgentActionRequestBase#conditionalPaths
3594
+ */
3595
+ target: PatchTarget | PatchTarget[]
3596
+ }
3597
+
3402
3598
  /** @internal */
3403
3599
  export declare type PatchSelection = string | string[] | MutationSelection
3404
3600
 
3601
+ /** @beta */
3602
+ export declare type PatchTarget = {
3603
+ /**
3604
+ * Determines how the target path will be patched.
3605
+ *
3606
+ * ### Operation types
3607
+ * - `'set'` – an *overwriting* operation: sets the full field value for primitive targets, and merges the provided value with existing values for objects
3608
+ * - `'append'`:
3609
+ * – array fields: appends new items to the end of the array,
3610
+ * - string fields: '"existing content" "new content"'
3611
+ * - text fields: '"existing content"\\n"new content"'
3612
+ * - number fields: existing + new
3613
+ * - other field types not mentioned will set instead (dates, url)
3614
+ * - `'mixed'` – sets non-array fields, and appends to array fields
3615
+ * - `'unset'` – removes whatever value is on the target path
3616
+ *
3617
+ * All operations except unset requires a `value`.
3618
+ *
3619
+ * #### Appending in the middle of arrays
3620
+ * To append to an array, use the 'append' operation, and provide an array value with one or more array items.
3621
+ *
3622
+ * `target: {path: ['array'], operation: 'append', value: [{_type: 'item' _key: 'a'}]}` will append the items in the value to the existing array.
3623
+ *
3624
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append', value: [{_type: 'item' _key: 'a'}]}`.
3625
+ * Here, `{_type: 'item' _key: 'a'}` will be appended after the array item with key `'appendAfterKey'`
3626
+ *
3627
+ * It is optional to provide a _key for inserted array items; if one isn't provided, it will be generated.
3628
+ */
3629
+ operation: PatchOperation
3630
+ path: AgentActionPathSegment | AgentActionPath
3631
+ } & (
3632
+ | {
3633
+ operation: 'unset'
3634
+ value?: never
3635
+ }
3636
+ | {
3637
+ operation: Exclude<PatchOperation, 'unset'>
3638
+ value: AnyNonNullable
3639
+ }
3640
+ )
3641
+
3642
+ /**
3643
+ * Create a new document, then patch it
3644
+ * @beta
3645
+ */
3646
+ declare interface PatchTargetDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
3647
+ /**
3648
+ * @see #AgentActionSchema.forcePublishedWrite
3649
+ */
3650
+ targetDocument: GenerateTargetDocument<T>
3651
+ documentId?: never
3652
+ }
3653
+
3405
3654
  /** @public */
3406
3655
  declare interface ProgressEvent_2 {
3407
3656
  type: 'progress'
@@ -3433,6 +3682,131 @@ export declare class ProjectsClient {
3433
3682
  getById(projectId: string): Promise<SanityProject>
3434
3683
  }
3435
3684
 
3685
+ /**
3686
+ * @beta
3687
+ */
3688
+ declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
3689
+ /**
3690
+ *
3691
+ * When true, the response body will be json according to the instruction.
3692
+ * When false, the response is the raw text response to the instruction.
3693
+ *
3694
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3695
+ */
3696
+ format: 'json'
3697
+ }
3698
+
3699
+ /** @beta */
3700
+ export declare type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
3701
+ | PromptTextResponse
3702
+ | PromptJsonResponse<T>
3703
+ ) &
3704
+ PromptRequestBase
3705
+
3706
+ /** @beta */
3707
+ declare interface PromptRequestBase {
3708
+ /**
3709
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
3710
+ *
3711
+ * The LLM only has access to information in the instruction, plus the target schema.
3712
+ *
3713
+ * String template with support for $variable from `instructionParams`.
3714
+ * */
3715
+ instruction: string
3716
+ /**
3717
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3718
+ *
3719
+ * ### Examples
3720
+ *
3721
+ * #### Constant
3722
+ *
3723
+ * ##### Shorthand
3724
+ * ```ts
3725
+ * client.agent.action.prompt({
3726
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
3727
+ * instructionParams: {
3728
+ * topic: 'Grapefruit'
3729
+ * },
3730
+ * })
3731
+ * ```
3732
+ * ##### Object-form
3733
+ *
3734
+ * ```ts
3735
+ * client.agent.action.prompt({
3736
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
3737
+ * instructionParams: {
3738
+ * topic: {
3739
+ * type: 'constant',
3740
+ * value: 'Grapefruit'
3741
+ * },
3742
+ * },
3743
+ * })
3744
+ * ```
3745
+ * #### Field
3746
+ * ```ts
3747
+ * client.agent.action.prompt({
3748
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3749
+ * instructionParams: {
3750
+ * pte: {
3751
+ * type: 'field',
3752
+ * path: ['pteField'],
3753
+ * documentId: 'someSanityDocId'
3754
+ * },
3755
+ * },
3756
+ * })
3757
+ * ```
3758
+ * #### Document
3759
+ * ```ts
3760
+ * client.agent.action.prompt({
3761
+ * json: true,
3762
+ * instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
3763
+ * instructionParams: {
3764
+ * document: {
3765
+ * type: 'document',
3766
+ * documentId: 'someSanityDocId'
3767
+ * },
3768
+ * },
3769
+ * })
3770
+ * ```
3771
+ *
3772
+ * #### GROQ
3773
+ * ```ts
3774
+ * client.agent.action.prompt({
3775
+ * instruction: 'Return the best title amongst these: $titles.',
3776
+ * instructionParams: {
3777
+ * titles: {
3778
+ * type: 'groq',
3779
+ * query: '* [_type==$type].title',
3780
+ * params: {type: 'article'}
3781
+ * },
3782
+ * },
3783
+ * })
3784
+ * ```
3785
+ * */
3786
+ instructionParams?: AgentActionParams<{
3787
+ docIdRequired: true
3788
+ }>
3789
+ /**
3790
+ * Controls how much variance the instructions will run with.
3791
+ *
3792
+ * Value must be in the range [0, 1] (inclusive).
3793
+ *
3794
+ * Default: 0.3
3795
+ */
3796
+ temperature?: number
3797
+ }
3798
+
3799
+ declare interface PromptTextResponse {
3800
+ /**
3801
+ *
3802
+ * When true, the response body will be json according to the instruction.
3803
+ * When false, the response is the raw text response to the instruction.
3804
+ *
3805
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3806
+ */
3807
+ format?: 'text'
3808
+ }
3809
+
3436
3810
  /**
3437
3811
  * Publishes a draft document.
3438
3812
  * If a published version of the document already exists this is replaced by the current draft document.
@@ -3519,6 +3893,23 @@ export declare interface QueryParams {
3519
3893
  cacheMode?: never
3520
3894
  }
3521
3895
 
3896
+ /**
3897
+ * Returned from the Content Lake API when a query is malformed, usually with a start
3898
+ * and end column to indicate where the error occurred, but not always. Can we used to
3899
+ * provide a more structured error message to the user.
3900
+ *
3901
+ * This will be located under the response `error` property.
3902
+ *
3903
+ * @public
3904
+ */
3905
+ export declare interface QueryParseError {
3906
+ type: 'queryParseError'
3907
+ description: string
3908
+ start?: number
3909
+ end?: number
3910
+ query?: string
3911
+ }
3912
+
3522
3913
  /**
3523
3914
  * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3524
3915
  * @public
@@ -5125,6 +5516,8 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5125
5516
  schemaId: string
5126
5517
  /**
5127
5518
  * The source document the transformation will use as input.
5519
+ *
5520
+ * @see #AgentActionSchema.forcePublishedWrite
5128
5521
  */
5129
5522
  documentId: string
5130
5523
  /**
@@ -5132,12 +5525,14 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5132
5525
  * then it is transformed according to the instruction.
5133
5526
  *
5134
5527
  * When omitted, the source document (documentId) is also the target document.
5528
+ *
5529
+ * @see #AgentActionSchema.forcePublishedWrite
5135
5530
  */
5136
5531
  targetDocument?: TransformTargetDocument
5137
5532
  /**
5138
5533
  * Instruct the LLM how to transform the input to th output.
5139
5534
  *
5140
- * String template using $variable from instructionParams.
5535
+ * String template with support for $variable from `instructionParams`.
5141
5536
  *
5142
5537
  * Capped to 2000 characters, after variables has been injected.
5143
5538
  * */
@@ -5236,6 +5631,21 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5236
5631
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
5237
5632
  *
5238
5633
  * Default max depth for transform: 12
5634
+ *
5635
+ * ## Transforming images
5636
+ *
5637
+ * To transform an existing image, directly target an image asset path.
5638
+ *
5639
+ * For example, all the following will transform the image into the provided asset:
5640
+ * * `target: {path: ['image', 'asset'] }`
5641
+ * * `target: {path: 'image', include: ['asset'] }`
5642
+ *
5643
+ * Image transform can be combined with regular content targets:
5644
+ * * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
5645
+ *
5646
+ * Image transform can have per-path instructions, just like any other target paths:
5647
+ * * `target: [{path: ['image', 'asset'], instruction: 'Make the sky blue' }`
5648
+ *
5239
5649
  * @see AgentActionRequestBase#conditionalPaths
5240
5650
  */
5241
5651
  target?: TransformTarget | TransformTarget[]
@@ -5246,7 +5656,7 @@ export declare interface TransformTarget extends AgentActionTarget {
5246
5656
  /**
5247
5657
  * Specifies a tailored instruction of this target.
5248
5658
  *
5249
- * string template using $variable from instructionParams.
5659
+ * String template with support for $variable from `instructionParams`.
5250
5660
  * */
5251
5661
  instruction?: string
5252
5662
  /**
@@ -5259,7 +5669,11 @@ export declare interface TransformTarget extends AgentActionTarget {
5259
5669
  include?: (AgentActionPathSegment | TransformTargetInclude)[]
5260
5670
  }
5261
5671
 
5262
- /** @beta */
5672
+ /**
5673
+ * @see #AgentActionSchema.forcePublishedWrite
5674
+ *
5675
+ * @beta
5676
+ */
5263
5677
  export declare type TransformTargetDocument =
5264
5678
  | {
5265
5679
  operation: 'edit'
@@ -5283,7 +5697,7 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
5283
5697
  /**
5284
5698
  * Specifies a tailored instruction of this target.
5285
5699
  *
5286
- * string template using $variable from instructionParams */
5700
+ * String template with support for $variable from `instructionParams`. */
5287
5701
  instruction?: string
5288
5702
  /**
5289
5703
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5325,6 +5739,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5325
5739
  schemaId: string
5326
5740
  /**
5327
5741
  * The source document the transformation will use as input.
5742
+ * @see #AgentActionSchema.forcePublishedWrite
5328
5743
  */
5329
5744
  documentId: string
5330
5745
  /**
@@ -5332,6 +5747,8 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5332
5747
  * then it is translated according to the instruction.
5333
5748
  *
5334
5749
  * When omitted, the source document (documentId) is also the target document.
5750
+ *
5751
+ * @see #AgentActionSchema.forcePublishedWrite
5335
5752
  */
5336
5753
  targetDocument?: TransformTargetDocument
5337
5754
  /**
@@ -5384,7 +5801,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5384
5801
 
5385
5802
  /** @beta */
5386
5803
  export declare interface TranslateTarget extends AgentActionTarget {
5387
- /** string template using $variable from instructionParams */
5804
+ /** String template using $variable from styleGuideParams. */
5388
5805
  styleGuide?: string
5389
5806
  /**
5390
5807
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5398,7 +5815,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
5398
5815
 
5399
5816
  /** @beta */
5400
5817
  export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
5401
- /** string template using $variable from instructionParams */
5818
+ /** String template using $variable from styleGuideParams. */
5402
5819
  styleGuide?: string
5403
5820
  /**
5404
5821
  * By default, all children up to `target.maxPathDepth` are included.