@sanity/client 7.3.0 → 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.
- package/README.md +122 -1
- package/dist/_chunks-cjs/isRecord.cjs +6 -0
- package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveEditInfo.cjs +3 -5
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +4 -0
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -5
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/isRecord.js +7 -0
- package/dist/_chunks-es/isRecord.js.map +1 -0
- package/dist/_chunks-es/resolveEditInfo.js +1 -3
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +4 -0
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -4
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +155 -32
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +473 -68
- package/dist/index.browser.d.ts +473 -68
- package/dist/index.browser.js +156 -33
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +157 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +473 -68
- package/dist/index.d.ts +473 -68
- package/dist/index.js +157 -33
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +473 -68
- package/dist/stega.browser.d.ts +473 -68
- package/dist/stega.d.cts +473 -68
- package/dist/stega.d.ts +473 -68
- package/package.json +1 -1
- package/src/agent/actions/AgentActionsClient.ts +29 -2
- package/src/agent/actions/commonTypes.ts +57 -17
- package/src/agent/actions/generate.ts +36 -2
- package/src/agent/actions/patch.ts +136 -0
- package/src/agent/actions/prompt.ts +145 -0
- package/src/agent/actions/transform.ts +27 -4
- package/src/agent/actions/translate.ts +5 -2
- package/src/csm/walkMap.ts +1 -1
- package/src/data/eventsource.ts +16 -7
- package/src/data/listen.ts +10 -4
- package/src/data/live.ts +13 -5
- package/src/defineCreateClient.ts +7 -1
- package/src/http/errors.ts +92 -27
- package/src/http/request.ts +3 -3
- package/src/types.ts +25 -10
- package/src/util/codeFrame.ts +174 -0
- package/src/{csm → util}/isRecord.ts +1 -1
- package/umd/sanityClient.js +158 -35
- package/umd/sanityClient.min.js +2 -2
package/dist/stega.d.ts
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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
|
|
@@ -693,7 +757,7 @@ export declare class ClientError extends Error {
|
|
|
693
757
|
statusCode: ErrorProps['statusCode']
|
|
694
758
|
responseBody: ErrorProps['responseBody']
|
|
695
759
|
details: ErrorProps['details']
|
|
696
|
-
constructor(res: Any)
|
|
760
|
+
constructor(res: Any, context?: HttpContext)
|
|
697
761
|
}
|
|
698
762
|
|
|
699
763
|
/** @public */
|
|
@@ -1193,6 +1257,23 @@ export declare type DisconnectEvent = {
|
|
|
1193
1257
|
reason: string
|
|
1194
1258
|
}
|
|
1195
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
|
+
|
|
1196
1277
|
/**
|
|
1197
1278
|
*
|
|
1198
1279
|
* Includes a LLM-friendly version of the document in the instruction
|
|
@@ -1213,13 +1294,15 @@ export declare type DisconnectEvent = {
|
|
|
1213
1294
|
*
|
|
1214
1295
|
* @beta
|
|
1215
1296
|
* */
|
|
1216
|
-
export declare
|
|
1297
|
+
export declare type DocumentAgentActionParam<
|
|
1298
|
+
TParamConfig extends {
|
|
1299
|
+
docIdRequired: boolean
|
|
1300
|
+
} = {
|
|
1301
|
+
docIdRequired: false
|
|
1302
|
+
},
|
|
1303
|
+
> = {
|
|
1217
1304
|
type: 'document'
|
|
1218
|
-
|
|
1219
|
-
* If omitted, implicitly uses the documentId of the instruction target
|
|
1220
|
-
*/
|
|
1221
|
-
documentId?: string
|
|
1222
|
-
}
|
|
1305
|
+
} & DocIdParam<TParamConfig>
|
|
1223
1306
|
|
|
1224
1307
|
/** @internal */
|
|
1225
1308
|
export declare type EditableReleaseDocument = Omit<
|
|
@@ -1325,17 +1408,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
|
|
|
1325
1408
|
*
|
|
1326
1409
|
* @beta
|
|
1327
1410
|
* */
|
|
1328
|
-
export declare
|
|
1411
|
+
export declare type FieldAgentActionParam<
|
|
1412
|
+
TParamConfig extends {
|
|
1413
|
+
docIdRequired: boolean
|
|
1414
|
+
} = {
|
|
1415
|
+
docIdRequired: false
|
|
1416
|
+
},
|
|
1417
|
+
> = {
|
|
1329
1418
|
type: 'field'
|
|
1330
1419
|
/**
|
|
1331
1420
|
* Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
|
|
1332
1421
|
*/
|
|
1333
1422
|
path: AgentActionPathSegment | AgentActionPath
|
|
1334
|
-
|
|
1335
|
-
* If omitted, implicitly uses the documentId of the instruction target
|
|
1336
|
-
*/
|
|
1337
|
-
documentId?: string
|
|
1338
|
-
}
|
|
1423
|
+
} & DocIdParam<TParamConfig>
|
|
1339
1424
|
|
|
1340
1425
|
/** @public */
|
|
1341
1426
|
export declare type FilterDefault = (props: {
|
|
@@ -1452,6 +1537,16 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
|
|
|
1452
1537
|
returnDocuments?: true
|
|
1453
1538
|
}
|
|
1454
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
|
+
|
|
1455
1550
|
/** @beta */
|
|
1456
1551
|
declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
1457
1552
|
| GenerateExistingDocumentRequest
|
|
@@ -1465,8 +1560,11 @@ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<str
|
|
|
1465
1560
|
* @beta
|
|
1466
1561
|
*/
|
|
1467
1562
|
declare interface GenerateExistingDocumentRequest {
|
|
1563
|
+
/**
|
|
1564
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1565
|
+
*/
|
|
1468
1566
|
documentId: string
|
|
1469
|
-
|
|
1567
|
+
targetDocument?: never
|
|
1470
1568
|
}
|
|
1471
1569
|
|
|
1472
1570
|
/** @beta */
|
|
@@ -1486,7 +1584,7 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
|
|
|
1486
1584
|
*
|
|
1487
1585
|
* The LLM only has access to information in the instruction, plus the target schema.
|
|
1488
1586
|
*
|
|
1489
|
-
*
|
|
1587
|
+
* String template with support for $variable from `instructionParams`.
|
|
1490
1588
|
* */
|
|
1491
1589
|
instruction: string
|
|
1492
1590
|
/**
|
|
@@ -1581,6 +1679,21 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
|
|
|
1581
1679
|
* - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
|
|
1582
1680
|
* It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
1583
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.
|
|
1584
1697
|
* @see AgentActionRequestBase#conditionalPaths
|
|
1585
1698
|
*/
|
|
1586
1699
|
target?: GenerateTarget | GenerateTarget[]
|
|
@@ -1627,6 +1740,7 @@ export declare interface GenerateTarget extends AgentActionTarget {
|
|
|
1627
1740
|
* @see #AgentActionTargetInclude.operation
|
|
1628
1741
|
* @see #include
|
|
1629
1742
|
* @see #AgentActionTargetInclude.include
|
|
1743
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1630
1744
|
*/
|
|
1631
1745
|
operation?: GenerateOperation
|
|
1632
1746
|
/**
|
|
@@ -1643,22 +1757,34 @@ export declare interface GenerateTarget extends AgentActionTarget {
|
|
|
1643
1757
|
export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
|
|
1644
1758
|
| {
|
|
1645
1759
|
operation: 'edit'
|
|
1760
|
+
/**
|
|
1761
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1762
|
+
*/
|
|
1646
1763
|
_id: string
|
|
1647
1764
|
}
|
|
1648
1765
|
| {
|
|
1649
1766
|
operation: 'create'
|
|
1767
|
+
/**
|
|
1768
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1769
|
+
*/
|
|
1650
1770
|
_id?: string
|
|
1651
1771
|
_type: string
|
|
1652
1772
|
initialValues?: T
|
|
1653
1773
|
}
|
|
1654
1774
|
| {
|
|
1655
1775
|
operation: 'createIfNotExists'
|
|
1776
|
+
/**
|
|
1777
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1778
|
+
*/
|
|
1656
1779
|
_id: string
|
|
1657
1780
|
_type: string
|
|
1658
1781
|
initialValues?: T
|
|
1659
1782
|
}
|
|
1660
1783
|
| {
|
|
1661
1784
|
operation: 'createOrReplace'
|
|
1785
|
+
/**
|
|
1786
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1787
|
+
*/
|
|
1662
1788
|
_id: string
|
|
1663
1789
|
_type: string
|
|
1664
1790
|
initialValues?: T
|
|
@@ -1671,6 +1797,9 @@ export declare type GenerateTargetDocument<T extends Record<string, Any> = Recor
|
|
|
1671
1797
|
declare interface GenerateTargetDocumentRequest<
|
|
1672
1798
|
T extends Record<string, Any> = Record<string, Any>,
|
|
1673
1799
|
> {
|
|
1800
|
+
/**
|
|
1801
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1802
|
+
*/
|
|
1674
1803
|
targetDocument: GenerateTargetDocument<T>
|
|
1675
1804
|
documentId?: never
|
|
1676
1805
|
}
|
|
@@ -1796,6 +1925,9 @@ export declare type InsertPatch =
|
|
|
1796
1925
|
items: Any[]
|
|
1797
1926
|
}
|
|
1798
1927
|
|
|
1928
|
+
/** @internal */
|
|
1929
|
+
export declare function isQueryParseError(error: object): error is QueryParseError
|
|
1930
|
+
|
|
1799
1931
|
/**
|
|
1800
1932
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
1801
1933
|
*
|
|
@@ -2036,11 +2168,9 @@ export declare type Mutation<R extends Record<string, Any> = Record<string, Any>
|
|
|
2036
2168
|
|
|
2037
2169
|
/** @internal */
|
|
2038
2170
|
export declare interface MutationError {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
items?: MutationErrorItem[]
|
|
2043
|
-
}
|
|
2171
|
+
type: 'mutationError'
|
|
2172
|
+
description: string
|
|
2173
|
+
items?: MutationErrorItem[]
|
|
2044
2174
|
}
|
|
2045
2175
|
|
|
2046
2176
|
/** @internal */
|
|
@@ -3565,9 +3695,45 @@ export declare class Patch extends BasePatch {
|
|
|
3565
3695
|
/** @public */
|
|
3566
3696
|
export declare type PatchBuilder = (patch: Patch) => Patch
|
|
3567
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
|
+
|
|
3568
3731
|
/** @internal */
|
|
3569
3732
|
export declare type PatchMutationOperation = PatchOperations & MutationSelection
|
|
3570
3733
|
|
|
3734
|
+
/** @beta */
|
|
3735
|
+
export declare type PatchOperation = 'set' | 'append' | 'mixed' | 'unset'
|
|
3736
|
+
|
|
3571
3737
|
/** @internal */
|
|
3572
3738
|
export declare interface PatchOperations {
|
|
3573
3739
|
set?: {
|
|
@@ -3590,9 +3756,80 @@ export declare interface PatchOperations {
|
|
|
3590
3756
|
ifRevisionID?: string
|
|
3591
3757
|
}
|
|
3592
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
|
+
|
|
3593
3777
|
/** @internal */
|
|
3594
3778
|
export declare type PatchSelection = string | string[] | MutationSelection
|
|
3595
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
|
+
|
|
3596
3833
|
/** @public */
|
|
3597
3834
|
declare interface ProgressEvent_2 {
|
|
3598
3835
|
type: 'progress'
|
|
@@ -3624,6 +3861,131 @@ export declare class ProjectsClient {
|
|
|
3624
3861
|
getById(projectId: string): Promise<SanityProject>
|
|
3625
3862
|
}
|
|
3626
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
|
+
|
|
3627
3989
|
/**
|
|
3628
3990
|
* Publishes a draft document.
|
|
3629
3991
|
* If a published version of the document already exists this is replaced by the current draft document.
|
|
@@ -3710,6 +4072,23 @@ export declare interface QueryParams {
|
|
|
3710
4072
|
cacheMode?: never
|
|
3711
4073
|
}
|
|
3712
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
|
+
|
|
3713
4092
|
/**
|
|
3714
4093
|
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
3715
4094
|
* @public
|
|
@@ -5391,6 +5770,8 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
|
|
|
5391
5770
|
schemaId: string
|
|
5392
5771
|
/**
|
|
5393
5772
|
* The source document the transformation will use as input.
|
|
5773
|
+
*
|
|
5774
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5394
5775
|
*/
|
|
5395
5776
|
documentId: string
|
|
5396
5777
|
/**
|
|
@@ -5398,12 +5779,14 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
|
|
|
5398
5779
|
* then it is transformed according to the instruction.
|
|
5399
5780
|
*
|
|
5400
5781
|
* When omitted, the source document (documentId) is also the target document.
|
|
5782
|
+
*
|
|
5783
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5401
5784
|
*/
|
|
5402
5785
|
targetDocument?: TransformTargetDocument
|
|
5403
5786
|
/**
|
|
5404
5787
|
* Instruct the LLM how to transform the input to th output.
|
|
5405
5788
|
*
|
|
5406
|
-
* String template
|
|
5789
|
+
* String template with support for $variable from `instructionParams`.
|
|
5407
5790
|
*
|
|
5408
5791
|
* Capped to 2000 characters, after variables has been injected.
|
|
5409
5792
|
* */
|
|
@@ -5502,6 +5885,21 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
|
|
|
5502
5885
|
* It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
5503
5886
|
*
|
|
5504
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
|
+
*
|
|
5505
5903
|
* @see AgentActionRequestBase#conditionalPaths
|
|
5506
5904
|
*/
|
|
5507
5905
|
target?: TransformTarget | TransformTarget[]
|
|
@@ -5512,7 +5910,7 @@ export declare interface TransformTarget extends AgentActionTarget {
|
|
|
5512
5910
|
/**
|
|
5513
5911
|
* Specifies a tailored instruction of this target.
|
|
5514
5912
|
*
|
|
5515
|
-
*
|
|
5913
|
+
* String template with support for $variable from `instructionParams`.
|
|
5516
5914
|
* */
|
|
5517
5915
|
instruction?: string
|
|
5518
5916
|
/**
|
|
@@ -5525,7 +5923,11 @@ export declare interface TransformTarget extends AgentActionTarget {
|
|
|
5525
5923
|
include?: (AgentActionPathSegment | TransformTargetInclude)[]
|
|
5526
5924
|
}
|
|
5527
5925
|
|
|
5528
|
-
/**
|
|
5926
|
+
/**
|
|
5927
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5928
|
+
*
|
|
5929
|
+
* @beta
|
|
5930
|
+
*/
|
|
5529
5931
|
export declare type TransformTargetDocument =
|
|
5530
5932
|
| {
|
|
5531
5933
|
operation: 'edit'
|
|
@@ -5549,7 +5951,7 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
|
|
|
5549
5951
|
/**
|
|
5550
5952
|
* Specifies a tailored instruction of this target.
|
|
5551
5953
|
*
|
|
5552
|
-
*
|
|
5954
|
+
* String template with support for $variable from `instructionParams`. */
|
|
5553
5955
|
instruction?: string
|
|
5554
5956
|
/**
|
|
5555
5957
|
* By default, all children up to `target.maxPathDepth` are included.
|
|
@@ -5591,6 +5993,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
|
|
|
5591
5993
|
schemaId: string
|
|
5592
5994
|
/**
|
|
5593
5995
|
* The source document the transformation will use as input.
|
|
5996
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5594
5997
|
*/
|
|
5595
5998
|
documentId: string
|
|
5596
5999
|
/**
|
|
@@ -5598,6 +6001,8 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
|
|
|
5598
6001
|
* then it is translated according to the instruction.
|
|
5599
6002
|
*
|
|
5600
6003
|
* When omitted, the source document (documentId) is also the target document.
|
|
6004
|
+
*
|
|
6005
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5601
6006
|
*/
|
|
5602
6007
|
targetDocument?: TransformTargetDocument
|
|
5603
6008
|
/**
|
|
@@ -5650,7 +6055,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
|
|
|
5650
6055
|
|
|
5651
6056
|
/** @beta */
|
|
5652
6057
|
export declare interface TranslateTarget extends AgentActionTarget {
|
|
5653
|
-
/**
|
|
6058
|
+
/** String template using $variable from styleGuideParams. */
|
|
5654
6059
|
styleGuide?: string
|
|
5655
6060
|
/**
|
|
5656
6061
|
* By default, all children up to `target.maxPathDepth` are included.
|
|
@@ -5664,7 +6069,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
|
|
|
5664
6069
|
|
|
5665
6070
|
/** @beta */
|
|
5666
6071
|
export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
|
|
5667
|
-
/**
|
|
6072
|
+
/** String template using $variable from styleGuideParams. */
|
|
5668
6073
|
styleGuide?: string
|
|
5669
6074
|
/**
|
|
5670
6075
|
* By default, all children up to `target.maxPathDepth` are included.
|