@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/stega.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {ClientConfig as ClientConfig_2} from '@sanity/client'
2
+ import type {HttpContext} from 'get-it'
2
3
  import {Observable} from 'rxjs'
3
4
  import {Requester} from 'get-it'
4
5
  import {adapter as unstable__adapter} from 'get-it'
@@ -18,11 +19,9 @@ export declare type Action =
18
19
 
19
20
  /** @internal */
20
21
  export declare interface ActionError {
21
- error: {
22
- type: 'actionError'
23
- description: string
24
- items?: ActionErrorItem[]
25
- }
22
+ type: 'actionError'
23
+ description: string
24
+ items?: ActionErrorItem[]
26
25
  }
27
26
 
28
27
  /** @internal */
@@ -49,15 +48,27 @@ declare interface AgentActionAsync {
49
48
  }
50
49
 
51
50
  /** @beta */
52
- export declare type AgentActionParam =
51
+ export declare type AgentActionParam<
52
+ TParamConfig extends {
53
+ docIdRequired: boolean
54
+ } = {
55
+ docIdRequired: false
56
+ },
57
+ > =
53
58
  | string
54
59
  | ConstantAgentActionParam
55
- | FieldAgentActionParam
56
- | DocumentAgentActionParam
60
+ | FieldAgentActionParam<TParamConfig>
61
+ | DocumentAgentActionParam<TParamConfig>
57
62
  | GroqAgentActionParam
58
63
 
59
64
  /** @beta */
60
- export declare type AgentActionParams = Record<string, AgentActionParam>
65
+ export declare type AgentActionParams<
66
+ TParamConfig extends {
67
+ docIdRequired: boolean
68
+ } = {
69
+ docIdRequired: false
70
+ },
71
+ > = Record<string, AgentActionParam<TParamConfig>>
61
72
 
62
73
  /** @beta */
63
74
  export declare type AgentActionPath = AgentActionPathSegment[]
@@ -70,39 +81,7 @@ export declare type AgentActionPathSegment =
70
81
  }
71
82
 
72
83
  /** @beta */
73
- declare interface AgentActionRequestBase {
74
- /** schemaId as reported by sanity deploy / sanity schema store */
75
- schemaId: string
76
- /**
77
- * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
78
- *
79
- * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
80
- * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
81
- *
82
- * `conditionalPaths` param allows setting the default conditional value for
83
- * `hidden` and `readOnly` to false,
84
- * or individually set `hidden` and `readOnly` state for individual document paths.
85
- *
86
- * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
87
- * and cannot be changed via conditionalPaths
88
- *
89
- * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
90
- *
91
- * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
92
- * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
93
- *
94
- * @see GenerateRequestBase#target
95
- */
96
- conditionalPaths?: {
97
- defaultReadOnly?: boolean
98
- defaultHidden?: boolean
99
- paths?: {
100
- /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
101
- path: AgentActionPath
102
- readOnly: boolean
103
- hidden: boolean
104
- }[]
105
- }
84
+ declare interface AgentActionRequestBase extends AgentActionSchema {
106
85
  /**
107
86
  * When localeSettings is provided on the request, instruct can write to date and datetime fields.
108
87
  * Otherwise, such fields will be ignored.
@@ -143,6 +122,68 @@ declare interface AgentActionRequestBase {
143
122
  temperature?: number
144
123
  }
145
124
 
125
+ /** @beta */
126
+ declare interface AgentActionSchema {
127
+ /** schemaId as reported by sanity deploy / sanity schema store */
128
+ schemaId: string
129
+ /**
130
+ * ### forcePublishedWrite: false (default)
131
+ * By default, agent actions will never write to a published document.
132
+ *
133
+ * Instead, they will force the use of a draft ID ("drafts.some-id") instead of the published ID ("some-id"),
134
+ * even when a published ID is provided.
135
+ *
136
+ * Actions will use state from an existing draft if it exists,
137
+ * or use the published document to create a draft, if no draft exists.
138
+ *
139
+ * Successful responses contains the _id that was mutated by the action.
140
+ *
141
+ *
142
+ * ### forcePublishedWrite: true
143
+ *
144
+ * When forcePublishedWrite: true an agent action will write to the exact id provided.
145
+ * The action will also not fallback to published state for draft ids.
146
+ *
147
+ *
148
+ * ### Versioned ids (releases)
149
+ *
150
+ * When an ID on the form "versions.<release>.some-id" is provided, agent actions will
151
+ * always behave as if `forcePublishedWrite: true`.
152
+ * That is, only the exact document state of the id provided is considered and mutated.
153
+ * */
154
+ forcePublishedWrite?: boolean
155
+ /**
156
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
157
+ *
158
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
159
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
160
+ *
161
+ * `conditionalPaths` param allows setting the default conditional value for
162
+ * `hidden` and `readOnly` to false,
163
+ * or individually set `hidden` and `readOnly` state for individual document paths.
164
+ *
165
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
166
+ * and cannot be changed via conditionalPaths
167
+ *
168
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
169
+ *
170
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
171
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
172
+ *
173
+ * @see GenerateRequestBase#target
174
+ */
175
+ conditionalPaths?: {
176
+ defaultReadOnly?: boolean
177
+ defaultHidden?: boolean
178
+ paths?: {
179
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
180
+ path: AgentActionPath
181
+ readOnly: boolean
182
+ hidden: boolean
183
+ }[]
184
+ }
185
+ }
186
+
146
187
  /** @public */
147
188
  declare class AgentActionsClient {
148
189
  #private
@@ -186,6 +227,27 @@ declare class AgentActionsClient {
186
227
  }
187
228
  : IdentifiedSanityDocumentStub & DocumentShape
188
229
  >
230
+ /**
231
+ * Run a raw instruction and return the result either as text or json
232
+ * @param request - prompt request
233
+ */
234
+ prompt<const DocumentShape extends Record<string, Any>>(
235
+ request: PromptRequest<DocumentShape>,
236
+ ): Promise<(typeof request)['format'] extends 'json' ? DocumentShape : string>
237
+ /**
238
+ * Patch a document using a schema aware API.
239
+ * Does not use an LLM, but uses the schema to ensure paths and values matches the schema.
240
+ * @param request - instruction request
241
+ */
242
+ patch<DocumentShape extends Record<string, Any>>(
243
+ request: PatchDocument<DocumentShape>,
244
+ ): Promise<
245
+ (typeof request)['async'] extends true
246
+ ? {
247
+ _id: string
248
+ }
249
+ : IdentifiedSanityDocumentStub & DocumentShape
250
+ >
189
251
  }
190
252
 
191
253
  /** @beta */
@@ -309,6 +371,8 @@ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
309
371
  */
310
372
  export declare type Any = any
311
373
 
374
+ declare type AnyNonNullable = Exclude<any, null | undefined>
375
+
312
376
  /** @internal */
313
377
  export declare interface ApiError {
314
378
  error: string
@@ -621,6 +685,12 @@ export declare interface ClientConfig {
621
685
  * Optional request tag prefix for all request tags
622
686
  */
623
687
  requestTagPrefix?: string
688
+ /**
689
+ * Optional default headers to include with all requests
690
+ *
691
+ * @remarks request-specific headers will override any default headers with the same name.
692
+ */
693
+ headers?: Record<string, string>
624
694
  ignoreBrowserTokenWarning?: boolean
625
695
  withCredentials?: boolean
626
696
  allowReconfigure?: boolean
@@ -687,7 +757,7 @@ export declare class ClientError extends Error {
687
757
  statusCode: ErrorProps['statusCode']
688
758
  responseBody: ErrorProps['responseBody']
689
759
  details: ErrorProps['details']
690
- constructor(res: Any)
760
+ constructor(res: Any, context?: HttpContext)
691
761
  }
692
762
 
693
763
  /** @public */
@@ -1187,6 +1257,23 @@ export declare type DisconnectEvent = {
1187
1257
  reason: string
1188
1258
  }
1189
1259
 
1260
+ declare type DocIdParam<
1261
+ TParamConfig extends {
1262
+ docIdRequired: boolean
1263
+ } = {
1264
+ docIdRequired: false
1265
+ },
1266
+ > = TParamConfig['docIdRequired'] extends true
1267
+ ? {
1268
+ documentId: string
1269
+ }
1270
+ : {
1271
+ /**
1272
+ * If omitted, implicitly uses the documentId of the instruction target
1273
+ */
1274
+ documentId?: string
1275
+ }
1276
+
1190
1277
  /**
1191
1278
  *
1192
1279
  * Includes a LLM-friendly version of the document in the instruction
@@ -1207,13 +1294,15 @@ export declare type DisconnectEvent = {
1207
1294
  *
1208
1295
  * @beta
1209
1296
  * */
1210
- export declare interface DocumentAgentActionParam {
1297
+ export declare type DocumentAgentActionParam<
1298
+ TParamConfig extends {
1299
+ docIdRequired: boolean
1300
+ } = {
1301
+ docIdRequired: false
1302
+ },
1303
+ > = {
1211
1304
  type: 'document'
1212
- /**
1213
- * If omitted, implicitly uses the documentId of the instruction target
1214
- */
1215
- documentId?: string
1216
- }
1305
+ } & DocIdParam<TParamConfig>
1217
1306
 
1218
1307
  /** @internal */
1219
1308
  export declare type EditableReleaseDocument = Omit<
@@ -1319,17 +1408,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
1319
1408
  *
1320
1409
  * @beta
1321
1410
  * */
1322
- export declare interface FieldAgentActionParam {
1411
+ export declare type FieldAgentActionParam<
1412
+ TParamConfig extends {
1413
+ docIdRequired: boolean
1414
+ } = {
1415
+ docIdRequired: false
1416
+ },
1417
+ > = {
1323
1418
  type: 'field'
1324
1419
  /**
1325
1420
  * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1326
1421
  */
1327
1422
  path: AgentActionPathSegment | AgentActionPath
1328
- /**
1329
- * If omitted, implicitly uses the documentId of the instruction target
1330
- */
1331
- documentId?: string
1332
- }
1423
+ } & DocIdParam<TParamConfig>
1333
1424
 
1334
1425
  /** @public */
1335
1426
  export declare type FilterDefault = (props: {
@@ -1446,6 +1537,16 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1446
1537
  returnDocuments?: true
1447
1538
  }
1448
1539
 
1540
+ /**
1541
+ * Formats a GROQ query parse error into a human-readable string.
1542
+ *
1543
+ * @param error - The error object containing details about the parse error.
1544
+ * @param tag - An optional tag to include in the error message.
1545
+ * @returns A formatted error message string.
1546
+ * @public
1547
+ */
1548
+ export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
1549
+
1449
1550
  /** @beta */
1450
1551
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1451
1552
  | GenerateExistingDocumentRequest
@@ -1459,8 +1560,11 @@ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<str
1459
1560
  * @beta
1460
1561
  */
1461
1562
  declare interface GenerateExistingDocumentRequest {
1563
+ /**
1564
+ * @see #AgentActionSchema.forcePublishedWrite
1565
+ */
1462
1566
  documentId: string
1463
- createDocument?: never
1567
+ targetDocument?: never
1464
1568
  }
1465
1569
 
1466
1570
  /** @beta */
@@ -1480,7 +1584,7 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1480
1584
  *
1481
1585
  * The LLM only has access to information in the instruction, plus the target schema.
1482
1586
  *
1483
- * string template using $variable
1587
+ * String template with support for $variable from `instructionParams`.
1484
1588
  * */
1485
1589
  instruction: string
1486
1590
  /**
@@ -1575,6 +1679,21 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
1575
1679
  * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1576
1680
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1577
1681
  *
1682
+ * ## Generating images
1683
+ *
1684
+ * Generate will generate images the same was as AI Assist, for images that have been configured using
1685
+ * [AI Assist schema options](https://github.com/sanity-io/assist/tree/main/plugin#image-generation).
1686
+ *
1687
+ * To generate images _without_ changing the schema, directly target an image asset path.
1688
+ *
1689
+ * For example, all the following will generate an image into the provided asset:
1690
+ * * `target: {path: ['image', 'asset'] }`
1691
+ * * `target: {path: 'image', include: ['asset'] }`
1692
+ *
1693
+ * Image generation can be combined with regular content targets:
1694
+ * * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
1695
+ *
1696
+ * Since Generate happens in a single LLM pass, the image will be contextually related to other generated content.
1578
1697
  * @see AgentActionRequestBase#conditionalPaths
1579
1698
  */
1580
1699
  target?: GenerateTarget | GenerateTarget[]
@@ -1621,6 +1740,7 @@ export declare interface GenerateTarget extends AgentActionTarget {
1621
1740
  * @see #AgentActionTargetInclude.operation
1622
1741
  * @see #include
1623
1742
  * @see #AgentActionTargetInclude.include
1743
+ * @see #AgentActionSchema.forcePublishedWrite
1624
1744
  */
1625
1745
  operation?: GenerateOperation
1626
1746
  /**
@@ -1637,22 +1757,34 @@ export declare interface GenerateTarget extends AgentActionTarget {
1637
1757
  export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1638
1758
  | {
1639
1759
  operation: 'edit'
1760
+ /**
1761
+ * @see #AgentActionSchema.forcePublishedWrite
1762
+ */
1640
1763
  _id: string
1641
1764
  }
1642
1765
  | {
1643
1766
  operation: 'create'
1767
+ /**
1768
+ * @see #AgentActionSchema.forcePublishedWrite
1769
+ */
1644
1770
  _id?: string
1645
1771
  _type: string
1646
1772
  initialValues?: T
1647
1773
  }
1648
1774
  | {
1649
1775
  operation: 'createIfNotExists'
1776
+ /**
1777
+ * @see #AgentActionSchema.forcePublishedWrite
1778
+ */
1650
1779
  _id: string
1651
1780
  _type: string
1652
1781
  initialValues?: T
1653
1782
  }
1654
1783
  | {
1655
1784
  operation: 'createOrReplace'
1785
+ /**
1786
+ * @see #AgentActionSchema.forcePublishedWrite
1787
+ */
1656
1788
  _id: string
1657
1789
  _type: string
1658
1790
  initialValues?: T
@@ -1665,6 +1797,9 @@ export declare type GenerateTargetDocument<T extends Record<string, Any> = Recor
1665
1797
  declare interface GenerateTargetDocumentRequest<
1666
1798
  T extends Record<string, Any> = Record<string, Any>,
1667
1799
  > {
1800
+ /**
1801
+ * @see #AgentActionSchema.forcePublishedWrite
1802
+ */
1668
1803
  targetDocument: GenerateTargetDocument<T>
1669
1804
  documentId?: never
1670
1805
  }
@@ -1753,6 +1888,12 @@ export declare interface InitializedClientConfig extends ClientConfig {
1753
1888
  * The fully initialized stega config, can be used to check if stega is enabled
1754
1889
  */
1755
1890
  stega: InitializedStegaConfig
1891
+ /**
1892
+ * Default headers to include with all requests
1893
+ *
1894
+ * @remarks request-specific headers will override any default headers with the same name.
1895
+ */
1896
+ headers?: Record<string, string>
1756
1897
  }
1757
1898
 
1758
1899
  /**
@@ -1784,6 +1925,9 @@ export declare type InsertPatch =
1784
1925
  items: Any[]
1785
1926
  }
1786
1927
 
1928
+ /** @internal */
1929
+ export declare function isQueryParseError(error: object): error is QueryParseError
1930
+
1787
1931
  /**
1788
1932
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1789
1933
  *
@@ -2024,11 +2168,9 @@ export declare type Mutation<R extends Record<string, Any> = Record<string, Any>
2024
2168
 
2025
2169
  /** @internal */
2026
2170
  export declare interface MutationError {
2027
- error: {
2028
- type: 'mutationError'
2029
- description: string
2030
- items?: MutationErrorItem[]
2031
- }
2171
+ type: 'mutationError'
2172
+ description: string
2173
+ items?: MutationErrorItem[]
2032
2174
  }
2033
2175
 
2034
2176
  /** @internal */
@@ -3553,9 +3695,45 @@ export declare class Patch extends BasePatch {
3553
3695
  /** @public */
3554
3696
  export declare type PatchBuilder = (patch: Patch) => Patch
3555
3697
 
3698
+ /** @beta */
3699
+ export declare type PatchDocument<T extends Record<string, Any> = Record<string, Any>> =
3700
+ | PatchDocumentSync<T>
3701
+ | PatchDocumentAsync<T>
3702
+
3703
+ /** @beta */
3704
+ declare type PatchDocumentAsync<T extends Record<string, Any> = Record<string, Any>> = (
3705
+ | PatchExistingDocumentRequest
3706
+ | PatchTargetDocumentRequest<T>
3707
+ ) &
3708
+ PatchRequestBase &
3709
+ AgentActionAsync
3710
+
3711
+ /** @beta */
3712
+ declare type PatchDocumentSync<T extends Record<string, Any> = Record<string, Any>> = (
3713
+ | PatchExistingDocumentRequest
3714
+ | PatchTargetDocumentRequest<T>
3715
+ ) &
3716
+ PatchRequestBase &
3717
+ AgentActionSync
3718
+
3719
+ /**
3720
+ * Patches an existing document
3721
+ * @beta
3722
+ */
3723
+ declare interface PatchExistingDocumentRequest {
3724
+ /**
3725
+ * @see #AgentActionSchema.forcePublishedWrite
3726
+ */
3727
+ documentId: string
3728
+ targetDocument?: never
3729
+ }
3730
+
3556
3731
  /** @internal */
3557
3732
  export declare type PatchMutationOperation = PatchOperations & MutationSelection
3558
3733
 
3734
+ /** @beta */
3735
+ export declare type PatchOperation = 'set' | 'append' | 'mixed' | 'unset'
3736
+
3559
3737
  /** @internal */
3560
3738
  export declare interface PatchOperations {
3561
3739
  set?: {
@@ -3578,9 +3756,80 @@ export declare interface PatchOperations {
3578
3756
  ifRevisionID?: string
3579
3757
  }
3580
3758
 
3759
+ /** @beta */
3760
+ declare interface PatchRequestBase extends AgentActionSchema {
3761
+ /**
3762
+ * Target defines which parts of the document will be affected by the instruction.
3763
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
3764
+ *
3765
+ * Omitting target implies that the document itself is the root.
3766
+ *
3767
+ * Notes:
3768
+ * - instruction can only affect fields up to `maxPathDepth`
3769
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
3770
+ * It is therefore an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
3771
+ *
3772
+ * @see AgentActionRequestBase#conditionalPaths
3773
+ */
3774
+ target: PatchTarget | PatchTarget[]
3775
+ }
3776
+
3581
3777
  /** @internal */
3582
3778
  export declare type PatchSelection = string | string[] | MutationSelection
3583
3779
 
3780
+ /** @beta */
3781
+ export declare type PatchTarget = {
3782
+ /**
3783
+ * Determines how the target path will be patched.
3784
+ *
3785
+ * ### Operation types
3786
+ * - `'set'` – an *overwriting* operation: sets the full field value for primitive targets, and merges the provided value with existing values for objects
3787
+ * - `'append'`:
3788
+ * – array fields: appends new items to the end of the array,
3789
+ * - string fields: '"existing content" "new content"'
3790
+ * - text fields: '"existing content"\\n"new content"'
3791
+ * - number fields: existing + new
3792
+ * - other field types not mentioned will set instead (dates, url)
3793
+ * - `'mixed'` – sets non-array fields, and appends to array fields
3794
+ * - `'unset'` – removes whatever value is on the target path
3795
+ *
3796
+ * All operations except unset requires a `value`.
3797
+ *
3798
+ * #### Appending in the middle of arrays
3799
+ * To append to an array, use the 'append' operation, and provide an array value with one or more array items.
3800
+ *
3801
+ * `target: {path: ['array'], operation: 'append', value: [{_type: 'item' _key: 'a'}]}` will append the items in the value to the existing array.
3802
+ *
3803
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append', value: [{_type: 'item' _key: 'a'}]}`.
3804
+ * Here, `{_type: 'item' _key: 'a'}` will be appended after the array item with key `'appendAfterKey'`
3805
+ *
3806
+ * It is optional to provide a _key for inserted array items; if one isn't provided, it will be generated.
3807
+ */
3808
+ operation: PatchOperation
3809
+ path: AgentActionPathSegment | AgentActionPath
3810
+ } & (
3811
+ | {
3812
+ operation: 'unset'
3813
+ value?: never
3814
+ }
3815
+ | {
3816
+ operation: Exclude<PatchOperation, 'unset'>
3817
+ value: AnyNonNullable
3818
+ }
3819
+ )
3820
+
3821
+ /**
3822
+ * Create a new document, then patch it
3823
+ * @beta
3824
+ */
3825
+ declare interface PatchTargetDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
3826
+ /**
3827
+ * @see #AgentActionSchema.forcePublishedWrite
3828
+ */
3829
+ targetDocument: GenerateTargetDocument<T>
3830
+ documentId?: never
3831
+ }
3832
+
3584
3833
  /** @public */
3585
3834
  declare interface ProgressEvent_2 {
3586
3835
  type: 'progress'
@@ -3612,6 +3861,131 @@ export declare class ProjectsClient {
3612
3861
  getById(projectId: string): Promise<SanityProject>
3613
3862
  }
3614
3863
 
3864
+ /**
3865
+ * @beta
3866
+ */
3867
+ declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
3868
+ /**
3869
+ *
3870
+ * When true, the response body will be json according to the instruction.
3871
+ * When false, the response is the raw text response to the instruction.
3872
+ *
3873
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3874
+ */
3875
+ format: 'json'
3876
+ }
3877
+
3878
+ /** @beta */
3879
+ export declare type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
3880
+ | PromptTextResponse
3881
+ | PromptJsonResponse<T>
3882
+ ) &
3883
+ PromptRequestBase
3884
+
3885
+ /** @beta */
3886
+ declare interface PromptRequestBase {
3887
+ /**
3888
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
3889
+ *
3890
+ * The LLM only has access to information in the instruction, plus the target schema.
3891
+ *
3892
+ * String template with support for $variable from `instructionParams`.
3893
+ * */
3894
+ instruction: string
3895
+ /**
3896
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3897
+ *
3898
+ * ### Examples
3899
+ *
3900
+ * #### Constant
3901
+ *
3902
+ * ##### Shorthand
3903
+ * ```ts
3904
+ * client.agent.action.prompt({
3905
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
3906
+ * instructionParams: {
3907
+ * topic: 'Grapefruit'
3908
+ * },
3909
+ * })
3910
+ * ```
3911
+ * ##### Object-form
3912
+ *
3913
+ * ```ts
3914
+ * client.agent.action.prompt({
3915
+ * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
3916
+ * instructionParams: {
3917
+ * topic: {
3918
+ * type: 'constant',
3919
+ * value: 'Grapefruit'
3920
+ * },
3921
+ * },
3922
+ * })
3923
+ * ```
3924
+ * #### Field
3925
+ * ```ts
3926
+ * client.agent.action.prompt({
3927
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3928
+ * instructionParams: {
3929
+ * pte: {
3930
+ * type: 'field',
3931
+ * path: ['pteField'],
3932
+ * documentId: 'someSanityDocId'
3933
+ * },
3934
+ * },
3935
+ * })
3936
+ * ```
3937
+ * #### Document
3938
+ * ```ts
3939
+ * client.agent.action.prompt({
3940
+ * json: true,
3941
+ * instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
3942
+ * instructionParams: {
3943
+ * document: {
3944
+ * type: 'document',
3945
+ * documentId: 'someSanityDocId'
3946
+ * },
3947
+ * },
3948
+ * })
3949
+ * ```
3950
+ *
3951
+ * #### GROQ
3952
+ * ```ts
3953
+ * client.agent.action.prompt({
3954
+ * instruction: 'Return the best title amongst these: $titles.',
3955
+ * instructionParams: {
3956
+ * titles: {
3957
+ * type: 'groq',
3958
+ * query: '* [_type==$type].title',
3959
+ * params: {type: 'article'}
3960
+ * },
3961
+ * },
3962
+ * })
3963
+ * ```
3964
+ * */
3965
+ instructionParams?: AgentActionParams<{
3966
+ docIdRequired: true
3967
+ }>
3968
+ /**
3969
+ * Controls how much variance the instructions will run with.
3970
+ *
3971
+ * Value must be in the range [0, 1] (inclusive).
3972
+ *
3973
+ * Default: 0.3
3974
+ */
3975
+ temperature?: number
3976
+ }
3977
+
3978
+ declare interface PromptTextResponse {
3979
+ /**
3980
+ *
3981
+ * When true, the response body will be json according to the instruction.
3982
+ * When false, the response is the raw text response to the instruction.
3983
+ *
3984
+ * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
3985
+ */
3986
+ format?: 'text'
3987
+ }
3988
+
3615
3989
  /**
3616
3990
  * Publishes a draft document.
3617
3991
  * If a published version of the document already exists this is replaced by the current draft document.
@@ -3698,6 +4072,23 @@ export declare interface QueryParams {
3698
4072
  cacheMode?: never
3699
4073
  }
3700
4074
 
4075
+ /**
4076
+ * Returned from the Content Lake API when a query is malformed, usually with a start
4077
+ * and end column to indicate where the error occurred, but not always. Can we used to
4078
+ * provide a more structured error message to the user.
4079
+ *
4080
+ * This will be located under the response `error` property.
4081
+ *
4082
+ * @public
4083
+ */
4084
+ export declare interface QueryParseError {
4085
+ type: 'queryParseError'
4086
+ description: string
4087
+ start?: number
4088
+ end?: number
4089
+ query?: string
4090
+ }
4091
+
3701
4092
  /**
3702
4093
  * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3703
4094
  * @public
@@ -5379,6 +5770,8 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5379
5770
  schemaId: string
5380
5771
  /**
5381
5772
  * The source document the transformation will use as input.
5773
+ *
5774
+ * @see #AgentActionSchema.forcePublishedWrite
5382
5775
  */
5383
5776
  documentId: string
5384
5777
  /**
@@ -5386,12 +5779,14 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5386
5779
  * then it is transformed according to the instruction.
5387
5780
  *
5388
5781
  * When omitted, the source document (documentId) is also the target document.
5782
+ *
5783
+ * @see #AgentActionSchema.forcePublishedWrite
5389
5784
  */
5390
5785
  targetDocument?: TransformTargetDocument
5391
5786
  /**
5392
5787
  * Instruct the LLM how to transform the input to th output.
5393
5788
  *
5394
- * String template using $variable from instructionParams.
5789
+ * String template with support for $variable from `instructionParams`.
5395
5790
  *
5396
5791
  * Capped to 2000 characters, after variables has been injected.
5397
5792
  * */
@@ -5490,6 +5885,21 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
5490
5885
  * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
5491
5886
  *
5492
5887
  * Default max depth for transform: 12
5888
+ *
5889
+ * ## Transforming images
5890
+ *
5891
+ * To transform an existing image, directly target an image asset path.
5892
+ *
5893
+ * For example, all the following will transform the image into the provided asset:
5894
+ * * `target: {path: ['image', 'asset'] }`
5895
+ * * `target: {path: 'image', include: ['asset'] }`
5896
+ *
5897
+ * Image transform can be combined with regular content targets:
5898
+ * * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
5899
+ *
5900
+ * Image transform can have per-path instructions, just like any other target paths:
5901
+ * * `target: [{path: ['image', 'asset'], instruction: 'Make the sky blue' }`
5902
+ *
5493
5903
  * @see AgentActionRequestBase#conditionalPaths
5494
5904
  */
5495
5905
  target?: TransformTarget | TransformTarget[]
@@ -5500,7 +5910,7 @@ export declare interface TransformTarget extends AgentActionTarget {
5500
5910
  /**
5501
5911
  * Specifies a tailored instruction of this target.
5502
5912
  *
5503
- * string template using $variable from instructionParams.
5913
+ * String template with support for $variable from `instructionParams`.
5504
5914
  * */
5505
5915
  instruction?: string
5506
5916
  /**
@@ -5513,7 +5923,11 @@ export declare interface TransformTarget extends AgentActionTarget {
5513
5923
  include?: (AgentActionPathSegment | TransformTargetInclude)[]
5514
5924
  }
5515
5925
 
5516
- /** @beta */
5926
+ /**
5927
+ * @see #AgentActionSchema.forcePublishedWrite
5928
+ *
5929
+ * @beta
5930
+ */
5517
5931
  export declare type TransformTargetDocument =
5518
5932
  | {
5519
5933
  operation: 'edit'
@@ -5537,7 +5951,7 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
5537
5951
  /**
5538
5952
  * Specifies a tailored instruction of this target.
5539
5953
  *
5540
- * string template using $variable from instructionParams */
5954
+ * String template with support for $variable from `instructionParams`. */
5541
5955
  instruction?: string
5542
5956
  /**
5543
5957
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5579,6 +5993,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5579
5993
  schemaId: string
5580
5994
  /**
5581
5995
  * The source document the transformation will use as input.
5996
+ * @see #AgentActionSchema.forcePublishedWrite
5582
5997
  */
5583
5998
  documentId: string
5584
5999
  /**
@@ -5586,6 +6001,8 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5586
6001
  * then it is translated according to the instruction.
5587
6002
  *
5588
6003
  * When omitted, the source document (documentId) is also the target document.
6004
+ *
6005
+ * @see #AgentActionSchema.forcePublishedWrite
5589
6006
  */
5590
6007
  targetDocument?: TransformTargetDocument
5591
6008
  /**
@@ -5638,7 +6055,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
5638
6055
 
5639
6056
  /** @beta */
5640
6057
  export declare interface TranslateTarget extends AgentActionTarget {
5641
- /** string template using $variable from instructionParams */
6058
+ /** String template using $variable from styleGuideParams. */
5642
6059
  styleGuide?: string
5643
6060
  /**
5644
6061
  * By default, all children up to `target.maxPathDepth` are included.
@@ -5652,7 +6069,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
5652
6069
 
5653
6070
  /** @beta */
5654
6071
  export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
5655
- /** string template using $variable from instructionParams */
6072
+ /** String template using $variable from styleGuideParams. */
5656
6073
  styleGuide?: string
5657
6074
  /**
5658
6075
  * By default, all children up to `target.maxPathDepth` are included.