@sanity/client 7.3.0 → 7.4.0-agent-actions.1

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 (53) hide show
  1. package/README.md +137 -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 +155 -32
  19. package/dist/index.browser.cjs.map +1 -1
  20. package/dist/index.browser.d.cts +506 -68
  21. package/dist/index.browser.d.ts +506 -68
  22. package/dist/index.browser.js +156 -33
  23. package/dist/index.browser.js.map +1 -1
  24. package/dist/index.cjs +157 -34
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +506 -68
  27. package/dist/index.d.ts +506 -68
  28. package/dist/index.js +157 -33
  29. package/dist/index.js.map +1 -1
  30. package/dist/stega.browser.d.cts +506 -68
  31. package/dist/stega.browser.d.ts +506 -68
  32. package/dist/stega.d.cts +506 -68
  33. package/dist/stega.d.ts +506 -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 +62 -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/types.ts +25 -10
  50. package/src/util/codeFrame.ts +174 -0
  51. package/src/{csm → util}/isRecord.ts +1 -1
  52. package/umd/sanityClient.js +158 -35
  53. 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
@@ -699,7 +763,7 @@ export declare class ClientError extends Error {
699
763
  statusCode: ErrorProps['statusCode']
700
764
  responseBody: ErrorProps['responseBody']
701
765
  details: ErrorProps['details']
702
- constructor(res: Any)
766
+ constructor(res: Any, context?: HttpContext)
703
767
  }
704
768
 
705
769
  /** @public */
@@ -1101,6 +1165,23 @@ export declare type DisconnectEvent = {
1101
1165
  reason: string
1102
1166
  }
1103
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
+
1104
1185
  /**
1105
1186
  *
1106
1187
  * Includes a LLM-friendly version of the document in the instruction
@@ -1121,13 +1202,15 @@ export declare type DisconnectEvent = {
1121
1202
  *
1122
1203
  * @beta
1123
1204
  * */
1124
- export declare interface DocumentAgentActionParam {
1205
+ export declare type DocumentAgentActionParam<
1206
+ TParamConfig extends {
1207
+ docIdRequired: boolean
1208
+ } = {
1209
+ docIdRequired: false
1210
+ },
1211
+ > = {
1125
1212
  type: 'document'
1126
- /**
1127
- * If omitted, implicitly uses the documentId of the instruction target
1128
- */
1129
- documentId?: string
1130
- }
1213
+ } & DocIdParam<TParamConfig>
1131
1214
 
1132
1215
  /** @internal */
1133
1216
  export declare type EditableReleaseDocument = Omit<
@@ -1214,17 +1297,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
1214
1297
  *
1215
1298
  * @beta
1216
1299
  * */
1217
- export declare interface FieldAgentActionParam {
1300
+ export declare type FieldAgentActionParam<
1301
+ TParamConfig extends {
1302
+ docIdRequired: boolean
1303
+ } = {
1304
+ docIdRequired: false
1305
+ },
1306
+ > = {
1218
1307
  type: 'field'
1219
1308
  /**
1220
1309
  * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1221
1310
  */
1222
1311
  path: AgentActionPathSegment | AgentActionPath
1223
- /**
1224
- * If omitted, implicitly uses the documentId of the instruction target
1225
- */
1226
- documentId?: string
1227
- }
1312
+ } & DocIdParam<TParamConfig>
1228
1313
 
1229
1314
  /** @public */
1230
1315
  export declare type FilterDefault = (props: {
@@ -1292,6 +1377,16 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1292
1377
  returnDocuments?: true
1293
1378
  }
1294
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
+
1295
1390
  /** @beta */
1296
1391
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1297
1392
  | GenerateExistingDocumentRequest
@@ -1305,8 +1400,11 @@ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<str
1305
1400
  * @beta
1306
1401
  */
1307
1402
  declare interface GenerateExistingDocumentRequest {
1403
+ /**
1404
+ * @see #AgentActionSchema.forcePublishedWrite
1405
+ */
1308
1406
  documentId: string
1309
- createDocument?: never
1407
+ targetDocument?: never
1310
1408
  }
1311
1409
 
1312
1410
  /** @beta */
@@ -1326,7 +1424,7 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1326
1424
  *
1327
1425
  * The LLM only has access to information in the instruction, plus the target schema.
1328
1426
  *
1329
- * string template using $variable
1427
+ * String template with support for $variable from `instructionParams`.
1330
1428
  * */
1331
1429
  instruction: string
1332
1430
  /**
@@ -1421,6 +1519,21 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1421
1519
  * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1422
1520
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1423
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.
1424
1537
  * @see AgentActionRequestBase#conditionalPaths
1425
1538
  */
1426
1539
  target?: GenerateTarget | GenerateTarget[]
@@ -1467,6 +1580,7 @@ export declare interface GenerateTarget extends AgentActionTarget {
1467
1580
  * @see #AgentActionTargetInclude.operation
1468
1581
  * @see #include
1469
1582
  * @see #AgentActionTargetInclude.include
1583
+ * @see #AgentActionSchema.forcePublishedWrite
1470
1584
  */
1471
1585
  operation?: GenerateOperation
1472
1586
  /**
@@ -1483,22 +1597,34 @@ export declare interface GenerateTarget extends AgentActionTarget {
1483
1597
  export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1484
1598
  | {
1485
1599
  operation: 'edit'
1600
+ /**
1601
+ * @see #AgentActionSchema.forcePublishedWrite
1602
+ */
1486
1603
  _id: string
1487
1604
  }
1488
1605
  | {
1489
1606
  operation: 'create'
1607
+ /**
1608
+ * @see #AgentActionSchema.forcePublishedWrite
1609
+ */
1490
1610
  _id?: string
1491
1611
  _type: string
1492
1612
  initialValues?: T
1493
1613
  }
1494
1614
  | {
1495
1615
  operation: 'createIfNotExists'
1616
+ /**
1617
+ * @see #AgentActionSchema.forcePublishedWrite
1618
+ */
1496
1619
  _id: string
1497
1620
  _type: string
1498
1621
  initialValues?: T
1499
1622
  }
1500
1623
  | {
1501
1624
  operation: 'createOrReplace'
1625
+ /**
1626
+ * @see #AgentActionSchema.forcePublishedWrite
1627
+ */
1502
1628
  _id: string
1503
1629
  _type: string
1504
1630
  initialValues?: T
@@ -1511,6 +1637,9 @@ export declare type GenerateTargetDocument<T extends Record<string, Any> = Recor
1511
1637
  declare interface GenerateTargetDocumentRequest<
1512
1638
  T extends Record<string, Any> = Record<string, Any>,
1513
1639
  > {
1640
+ /**
1641
+ * @see #AgentActionSchema.forcePublishedWrite
1642
+ */
1514
1643
  targetDocument: GenerateTargetDocument<T>
1515
1644
  documentId?: never
1516
1645
  }
@@ -1626,6 +1755,9 @@ export declare type InsertPatch =
1626
1755
  items: Any[]
1627
1756
  }
1628
1757
 
1758
+ /** @internal */
1759
+ export declare function isQueryParseError(error: object): error is QueryParseError
1760
+
1629
1761
  /**
1630
1762
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1631
1763
  *
@@ -1859,11 +1991,9 @@ export declare type Mutation<R extends Record<string, Any> = Record<string, Any>
1859
1991
 
1860
1992
  /** @internal */
1861
1993
  export declare interface MutationError {
1862
- error: {
1863
- type: 'mutationError'
1864
- description: string
1865
- items?: MutationErrorItem[]
1866
- }
1994
+ type: 'mutationError'
1995
+ description: string
1996
+ items?: MutationErrorItem[]
1867
1997
  }
1868
1998
 
1869
1999
  /** @internal */
@@ -3382,9 +3512,45 @@ export declare class Patch extends BasePatch {
3382
3512
  /** @public */
3383
3513
  export declare type PatchBuilder = (patch: Patch) => Patch
3384
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
+
3385
3548
  /** @internal */
3386
3549
  export declare type PatchMutationOperation = PatchOperations & MutationSelection
3387
3550
 
3551
+ /** @beta */
3552
+ export declare type PatchOperation = 'set' | 'append' | 'mixed' | 'unset'
3553
+
3388
3554
  /** @internal */
3389
3555
  export declare interface PatchOperations {
3390
3556
  set?: {
@@ -3407,9 +3573,80 @@ export declare interface PatchOperations {
3407
3573
  ifRevisionID?: string
3408
3574
  }
3409
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
+
3410
3594
  /** @internal */
3411
3595
  export declare type PatchSelection = string | string[] | MutationSelection
3412
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
+
3413
3650
  /** @public */
3414
3651
  declare interface ProgressEvent_2 {
3415
3652
  type: 'progress'
@@ -3441,6 +3678,131 @@ export declare class ProjectsClient {
3441
3678
  getById(projectId: string): Promise<SanityProject>
3442
3679
  }
3443
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
+
3444
3806
  /**
3445
3807
  * Publishes a draft document.
3446
3808
  * If a published version of the document already exists this is replaced by the current draft document.
@@ -3527,6 +3889,23 @@ export declare interface QueryParams {
3527
3889
  cacheMode?: never
3528
3890
  }
3529
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
+
3530
3909
  /**
3531
3910
  * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3532
3911
  * @public
@@ -5127,12 +5506,37 @@ declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
5127
5506
  declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
5128
5507
  TransformRequestBase & AgentActionSync
5129
5508
 
5509
+ /**
5510
+ *
5511
+ * ## Set by default
5512
+ * By default, transform will change the value of every target field in place using a set operation.
5513
+ *
5514
+ * ## Image description
5515
+ *
5516
+ * Images can be transformed to an textual description by targeting a `string`, `text` or Portable Text field (`array` with `block`)
5517
+ * with `operation: 'image-description'`.
5518
+ *
5519
+ * Custom instructions for image description targets will be used to generate the description.
5520
+ *
5521
+ * Such targets must be a descendant field of an image object.
5522
+ *
5523
+ * For example:
5524
+ * * `target: {path: ['image', 'description'], operation: 'image-description' }`
5525
+ * * `target: {path: ['array', {_key: 'abc'}, 'alt'], operation: 'image-description' } //assuming the item in the array on the key-ed path is an image`
5526
+ * * `target: {path: ['image'], include: ['portableTextField'], operation: 'image-description', instruction: 'Use formatting and headings to describe the image in great detail' }`
5527
+ *
5528
+ * @beta
5529
+ */
5530
+ declare type TransformOperation = 'set' | 'image-description'
5531
+
5130
5532
  /** @beta */
5131
5533
  declare interface TransformRequestBase extends AgentActionRequestBase {
5132
5534
  /** schemaId as reported by sanity deploy / sanity schema store */
5133
5535
  schemaId: string
5134
5536
  /**
5135
5537
  * The source document the transformation will use as input.
5538
+ *
5539
+ * @see #AgentActionSchema.forcePublishedWrite
5136
5540
  */
5137
5541
  documentId: string
5138
5542
  /**
@@ -5140,12 +5544,14 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5140
5544
  * then it is transformed according to the instruction.
5141
5545
  *
5142
5546
  * When omitted, the source document (documentId) is also the target document.
5547
+ *
5548
+ * @see #AgentActionSchema.forcePublishedWrite
5143
5549
  */
5144
5550
  targetDocument?: TransformTargetDocument
5145
5551
  /**
5146
5552
  * Instruct the LLM how to transform the input to th output.
5147
5553
  *
5148
- * String template using $variable from instructionParams.
5554
+ * String template with support for $variable from `instructionParams`.
5149
5555
  *
5150
5556
  * Capped to 2000 characters, after variables has been injected.
5151
5557
  * */
@@ -5244,6 +5650,21 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5244
5650
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
5245
5651
  *
5246
5652
  * Default max depth for transform: 12
5653
+ *
5654
+ * ## Transforming images
5655
+ *
5656
+ * To transform an existing image, directly target an image asset path.
5657
+ *
5658
+ * For example, all the following will transform the image into the provided asset:
5659
+ * * `target: {path: ['image', 'asset'] }`
5660
+ * * `target: {path: 'image', include: ['asset'] }`
5661
+ *
5662
+ * Image transform can be combined with regular content targets:
5663
+ * * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
5664
+ *
5665
+ * Image transform can have per-path instructions, just like any other target paths:
5666
+ * * `target: [{path: ['image', 'asset'], instruction: 'Make the sky blue' }`
5667
+ *
5247
5668
  * @see AgentActionRequestBase#conditionalPaths
5248
5669
  */
5249
5670
  target?: TransformTarget | TransformTarget[]
@@ -5254,7 +5675,7 @@ export declare interface TransformTarget extends AgentActionTarget {
5254
5675
  /**
5255
5676
  * Specifies a tailored instruction of this target.
5256
5677
  *
5257
- * string template using $variable from instructionParams.
5678
+ * String template with support for $variable from `instructionParams`.
5258
5679
  * */
5259
5680
  instruction?: string
5260
5681
  /**
@@ -5265,9 +5686,18 @@ export declare interface TransformTarget extends AgentActionTarget {
5265
5686
  * Fields or array items not on the include list, are implicitly excluded.
5266
5687
  */
5267
5688
  include?: (AgentActionPathSegment | TransformTargetInclude)[]
5689
+ /**
5690
+ * Default: `set`
5691
+ * @see #TransformOperation
5692
+ */
5693
+ operation?: TransformOperation
5268
5694
  }
5269
5695
 
5270
- /** @beta */
5696
+ /**
5697
+ * @see #AgentActionSchema.forcePublishedWrite
5698
+ *
5699
+ * @beta
5700
+ */
5271
5701
  export declare type TransformTargetDocument =
5272
5702
  | {
5273
5703
  operation: 'edit'
@@ -5291,7 +5721,7 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
5291
5721
  /**
5292
5722
  * Specifies a tailored instruction of this target.
5293
5723
  *
5294
- * string template using $variable from instructionParams */
5724
+ * String template with support for $variable from `instructionParams`. */
5295
5725
  instruction?: string
5296
5726
  /**
5297
5727
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5301,6 +5731,11 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
5301
5731
  * Fields or array items not on the include list, are implicitly excluded.
5302
5732
  */
5303
5733
  include?: (AgentActionPathSegment | TransformTargetInclude)[]
5734
+ /**
5735
+ * Default: `set`
5736
+ * @see #TransformOperation
5737
+ */
5738
+ operation?: TransformOperation
5304
5739
  }
5305
5740
 
5306
5741
  /** @beta */
@@ -5333,6 +5768,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5333
5768
  schemaId: string
5334
5769
  /**
5335
5770
  * The source document the transformation will use as input.
5771
+ * @see #AgentActionSchema.forcePublishedWrite
5336
5772
  */
5337
5773
  documentId: string
5338
5774
  /**
@@ -5340,6 +5776,8 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5340
5776
  * then it is translated according to the instruction.
5341
5777
  *
5342
5778
  * When omitted, the source document (documentId) is also the target document.
5779
+ *
5780
+ * @see #AgentActionSchema.forcePublishedWrite
5343
5781
  */
5344
5782
  targetDocument?: TransformTargetDocument
5345
5783
  /**
@@ -5392,7 +5830,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5392
5830
 
5393
5831
  /** @beta */
5394
5832
  export declare interface TranslateTarget extends AgentActionTarget {
5395
- /** string template using $variable from instructionParams */
5833
+ /** String template using $variable from styleGuideParams. */
5396
5834
  styleGuide?: string
5397
5835
  /**
5398
5836
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5406,7 +5844,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
5406
5844
 
5407
5845
  /** @beta */
5408
5846
  export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
5409
- /** string template using $variable from instructionParams */
5847
+ /** String template using $variable from styleGuideParams. */
5410
5848
  styleGuide?: string
5411
5849
  /**
5412
5850
  * By default, all children up to `target.maxPathDepth` are included.