@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/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {ContentSourceMapDocuments as ContentSourceMapDocuments_2} from '@sanity/client/csm'
|
|
2
2
|
import {ContentSourceMapParsedPath} from '@sanity/client/csm'
|
|
3
3
|
import {ContentSourceMapParsedPathKeyedSegment} from '@sanity/client/csm'
|
|
4
|
+
import type {HttpContext} from 'get-it'
|
|
4
5
|
import {Observable} from 'rxjs'
|
|
5
6
|
import {Requester} from 'get-it'
|
|
6
7
|
import type {ResolveStudioUrl} from '@sanity/client/csm'
|
|
@@ -24,11 +25,9 @@ export declare type Action =
|
|
|
24
25
|
|
|
25
26
|
/** @internal */
|
|
26
27
|
export declare interface ActionError {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
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 */
|
|
@@ -1105,6 +1169,23 @@ export declare type DisconnectEvent = {
|
|
|
1105
1169
|
reason: string
|
|
1106
1170
|
}
|
|
1107
1171
|
|
|
1172
|
+
declare type DocIdParam<
|
|
1173
|
+
TParamConfig extends {
|
|
1174
|
+
docIdRequired: boolean
|
|
1175
|
+
} = {
|
|
1176
|
+
docIdRequired: false
|
|
1177
|
+
},
|
|
1178
|
+
> = TParamConfig['docIdRequired'] extends true
|
|
1179
|
+
? {
|
|
1180
|
+
documentId: string
|
|
1181
|
+
}
|
|
1182
|
+
: {
|
|
1183
|
+
/**
|
|
1184
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
1185
|
+
*/
|
|
1186
|
+
documentId?: string
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1108
1189
|
/**
|
|
1109
1190
|
*
|
|
1110
1191
|
* Includes a LLM-friendly version of the document in the instruction
|
|
@@ -1125,13 +1206,15 @@ export declare type DisconnectEvent = {
|
|
|
1125
1206
|
*
|
|
1126
1207
|
* @beta
|
|
1127
1208
|
* */
|
|
1128
|
-
export declare
|
|
1209
|
+
export declare type DocumentAgentActionParam<
|
|
1210
|
+
TParamConfig extends {
|
|
1211
|
+
docIdRequired: boolean
|
|
1212
|
+
} = {
|
|
1213
|
+
docIdRequired: false
|
|
1214
|
+
},
|
|
1215
|
+
> = {
|
|
1129
1216
|
type: 'document'
|
|
1130
|
-
|
|
1131
|
-
* If omitted, implicitly uses the documentId of the instruction target
|
|
1132
|
-
*/
|
|
1133
|
-
documentId?: string
|
|
1134
|
-
}
|
|
1217
|
+
} & DocIdParam<TParamConfig>
|
|
1135
1218
|
|
|
1136
1219
|
/** @internal */
|
|
1137
1220
|
export declare type EditableReleaseDocument = Omit<
|
|
@@ -1218,17 +1301,19 @@ export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSo
|
|
|
1218
1301
|
*
|
|
1219
1302
|
* @beta
|
|
1220
1303
|
* */
|
|
1221
|
-
export declare
|
|
1304
|
+
export declare type FieldAgentActionParam<
|
|
1305
|
+
TParamConfig extends {
|
|
1306
|
+
docIdRequired: boolean
|
|
1307
|
+
} = {
|
|
1308
|
+
docIdRequired: false
|
|
1309
|
+
},
|
|
1310
|
+
> = {
|
|
1222
1311
|
type: 'field'
|
|
1223
1312
|
/**
|
|
1224
1313
|
* Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
|
|
1225
1314
|
*/
|
|
1226
1315
|
path: AgentActionPathSegment | AgentActionPath
|
|
1227
|
-
|
|
1228
|
-
* If omitted, implicitly uses the documentId of the instruction target
|
|
1229
|
-
*/
|
|
1230
|
-
documentId?: string
|
|
1231
|
-
}
|
|
1316
|
+
} & DocIdParam<TParamConfig>
|
|
1232
1317
|
|
|
1233
1318
|
/** @public */
|
|
1234
1319
|
export declare type FilterDefault = (props: {
|
|
@@ -1296,6 +1381,16 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
|
|
|
1296
1381
|
returnDocuments?: true
|
|
1297
1382
|
}
|
|
1298
1383
|
|
|
1384
|
+
/**
|
|
1385
|
+
* Formats a GROQ query parse error into a human-readable string.
|
|
1386
|
+
*
|
|
1387
|
+
* @param error - The error object containing details about the parse error.
|
|
1388
|
+
* @param tag - An optional tag to include in the error message.
|
|
1389
|
+
* @returns A formatted error message string.
|
|
1390
|
+
* @public
|
|
1391
|
+
*/
|
|
1392
|
+
export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
|
|
1393
|
+
|
|
1299
1394
|
/** @beta */
|
|
1300
1395
|
declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
1301
1396
|
| GenerateExistingDocumentRequest
|
|
@@ -1309,8 +1404,11 @@ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<str
|
|
|
1309
1404
|
* @beta
|
|
1310
1405
|
*/
|
|
1311
1406
|
declare interface GenerateExistingDocumentRequest {
|
|
1407
|
+
/**
|
|
1408
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1409
|
+
*/
|
|
1312
1410
|
documentId: string
|
|
1313
|
-
|
|
1411
|
+
targetDocument?: never
|
|
1314
1412
|
}
|
|
1315
1413
|
|
|
1316
1414
|
/** @beta */
|
|
@@ -1330,7 +1428,7 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
|
|
|
1330
1428
|
*
|
|
1331
1429
|
* The LLM only has access to information in the instruction, plus the target schema.
|
|
1332
1430
|
*
|
|
1333
|
-
*
|
|
1431
|
+
* String template with support for $variable from `instructionParams`.
|
|
1334
1432
|
* */
|
|
1335
1433
|
instruction: string
|
|
1336
1434
|
/**
|
|
@@ -1425,6 +1523,21 @@ declare interface GenerateRequestBase extends AgentActionRequestBase {
|
|
|
1425
1523
|
* - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
|
|
1426
1524
|
* It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
1427
1525
|
*
|
|
1526
|
+
* ## Generating images
|
|
1527
|
+
*
|
|
1528
|
+
* Generate will generate images the same was as AI Assist, for images that have been configured using
|
|
1529
|
+
* [AI Assist schema options](https://github.com/sanity-io/assist/tree/main/plugin#image-generation).
|
|
1530
|
+
*
|
|
1531
|
+
* To generate images _without_ changing the schema, directly target an image asset path.
|
|
1532
|
+
*
|
|
1533
|
+
* For example, all the following will generate an image into the provided asset:
|
|
1534
|
+
* * `target: {path: ['image', 'asset'] }`
|
|
1535
|
+
* * `target: {path: 'image', include: ['asset'] }`
|
|
1536
|
+
*
|
|
1537
|
+
* Image generation can be combined with regular content targets:
|
|
1538
|
+
* * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
|
|
1539
|
+
*
|
|
1540
|
+
* Since Generate happens in a single LLM pass, the image will be contextually related to other generated content.
|
|
1428
1541
|
* @see AgentActionRequestBase#conditionalPaths
|
|
1429
1542
|
*/
|
|
1430
1543
|
target?: GenerateTarget | GenerateTarget[]
|
|
@@ -1471,6 +1584,7 @@ export declare interface GenerateTarget extends AgentActionTarget {
|
|
|
1471
1584
|
* @see #AgentActionTargetInclude.operation
|
|
1472
1585
|
* @see #include
|
|
1473
1586
|
* @see #AgentActionTargetInclude.include
|
|
1587
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1474
1588
|
*/
|
|
1475
1589
|
operation?: GenerateOperation
|
|
1476
1590
|
/**
|
|
@@ -1487,22 +1601,34 @@ export declare interface GenerateTarget extends AgentActionTarget {
|
|
|
1487
1601
|
export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
|
|
1488
1602
|
| {
|
|
1489
1603
|
operation: 'edit'
|
|
1604
|
+
/**
|
|
1605
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1606
|
+
*/
|
|
1490
1607
|
_id: string
|
|
1491
1608
|
}
|
|
1492
1609
|
| {
|
|
1493
1610
|
operation: 'create'
|
|
1611
|
+
/**
|
|
1612
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1613
|
+
*/
|
|
1494
1614
|
_id?: string
|
|
1495
1615
|
_type: string
|
|
1496
1616
|
initialValues?: T
|
|
1497
1617
|
}
|
|
1498
1618
|
| {
|
|
1499
1619
|
operation: 'createIfNotExists'
|
|
1620
|
+
/**
|
|
1621
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1622
|
+
*/
|
|
1500
1623
|
_id: string
|
|
1501
1624
|
_type: string
|
|
1502
1625
|
initialValues?: T
|
|
1503
1626
|
}
|
|
1504
1627
|
| {
|
|
1505
1628
|
operation: 'createOrReplace'
|
|
1629
|
+
/**
|
|
1630
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1631
|
+
*/
|
|
1506
1632
|
_id: string
|
|
1507
1633
|
_type: string
|
|
1508
1634
|
initialValues?: T
|
|
@@ -1515,6 +1641,9 @@ export declare type GenerateTargetDocument<T extends Record<string, Any> = Recor
|
|
|
1515
1641
|
declare interface GenerateTargetDocumentRequest<
|
|
1516
1642
|
T extends Record<string, Any> = Record<string, Any>,
|
|
1517
1643
|
> {
|
|
1644
|
+
/**
|
|
1645
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
1646
|
+
*/
|
|
1518
1647
|
targetDocument: GenerateTargetDocument<T>
|
|
1519
1648
|
documentId?: never
|
|
1520
1649
|
}
|
|
@@ -1630,6 +1759,9 @@ export declare type InsertPatch =
|
|
|
1630
1759
|
items: Any[]
|
|
1631
1760
|
}
|
|
1632
1761
|
|
|
1762
|
+
/** @internal */
|
|
1763
|
+
export declare function isQueryParseError(error: object): error is QueryParseError
|
|
1764
|
+
|
|
1633
1765
|
/**
|
|
1634
1766
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
1635
1767
|
*
|
|
@@ -1863,11 +1995,9 @@ export declare type Mutation<R extends Record<string, Any> = Record<string, Any>
|
|
|
1863
1995
|
|
|
1864
1996
|
/** @internal */
|
|
1865
1997
|
export declare interface MutationError {
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
items?: MutationErrorItem[]
|
|
1870
|
-
}
|
|
1998
|
+
type: 'mutationError'
|
|
1999
|
+
description: string
|
|
2000
|
+
items?: MutationErrorItem[]
|
|
1871
2001
|
}
|
|
1872
2002
|
|
|
1873
2003
|
/** @internal */
|
|
@@ -3386,9 +3516,45 @@ export declare class Patch extends BasePatch {
|
|
|
3386
3516
|
/** @public */
|
|
3387
3517
|
export declare type PatchBuilder = (patch: Patch) => Patch
|
|
3388
3518
|
|
|
3519
|
+
/** @beta */
|
|
3520
|
+
export declare type PatchDocument<T extends Record<string, Any> = Record<string, Any>> =
|
|
3521
|
+
| PatchDocumentSync<T>
|
|
3522
|
+
| PatchDocumentAsync<T>
|
|
3523
|
+
|
|
3524
|
+
/** @beta */
|
|
3525
|
+
declare type PatchDocumentAsync<T extends Record<string, Any> = Record<string, Any>> = (
|
|
3526
|
+
| PatchExistingDocumentRequest
|
|
3527
|
+
| PatchTargetDocumentRequest<T>
|
|
3528
|
+
) &
|
|
3529
|
+
PatchRequestBase &
|
|
3530
|
+
AgentActionAsync
|
|
3531
|
+
|
|
3532
|
+
/** @beta */
|
|
3533
|
+
declare type PatchDocumentSync<T extends Record<string, Any> = Record<string, Any>> = (
|
|
3534
|
+
| PatchExistingDocumentRequest
|
|
3535
|
+
| PatchTargetDocumentRequest<T>
|
|
3536
|
+
) &
|
|
3537
|
+
PatchRequestBase &
|
|
3538
|
+
AgentActionSync
|
|
3539
|
+
|
|
3540
|
+
/**
|
|
3541
|
+
* Patches an existing document
|
|
3542
|
+
* @beta
|
|
3543
|
+
*/
|
|
3544
|
+
declare interface PatchExistingDocumentRequest {
|
|
3545
|
+
/**
|
|
3546
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
3547
|
+
*/
|
|
3548
|
+
documentId: string
|
|
3549
|
+
targetDocument?: never
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3389
3552
|
/** @internal */
|
|
3390
3553
|
export declare type PatchMutationOperation = PatchOperations & MutationSelection
|
|
3391
3554
|
|
|
3555
|
+
/** @beta */
|
|
3556
|
+
export declare type PatchOperation = 'set' | 'append' | 'mixed' | 'unset'
|
|
3557
|
+
|
|
3392
3558
|
/** @internal */
|
|
3393
3559
|
export declare interface PatchOperations {
|
|
3394
3560
|
set?: {
|
|
@@ -3411,9 +3577,80 @@ export declare interface PatchOperations {
|
|
|
3411
3577
|
ifRevisionID?: string
|
|
3412
3578
|
}
|
|
3413
3579
|
|
|
3580
|
+
/** @beta */
|
|
3581
|
+
declare interface PatchRequestBase extends AgentActionSchema {
|
|
3582
|
+
/**
|
|
3583
|
+
* Target defines which parts of the document will be affected by the instruction.
|
|
3584
|
+
* It can be an array, so multiple parts of the document can be separately configured in detail.
|
|
3585
|
+
*
|
|
3586
|
+
* Omitting target implies that the document itself is the root.
|
|
3587
|
+
*
|
|
3588
|
+
* Notes:
|
|
3589
|
+
* - instruction can only affect fields up to `maxPathDepth`
|
|
3590
|
+
* - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
|
|
3591
|
+
* It is therefore an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
3592
|
+
*
|
|
3593
|
+
* @see AgentActionRequestBase#conditionalPaths
|
|
3594
|
+
*/
|
|
3595
|
+
target: PatchTarget | PatchTarget[]
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3414
3598
|
/** @internal */
|
|
3415
3599
|
export declare type PatchSelection = string | string[] | MutationSelection
|
|
3416
3600
|
|
|
3601
|
+
/** @beta */
|
|
3602
|
+
export declare type PatchTarget = {
|
|
3603
|
+
/**
|
|
3604
|
+
* Determines how the target path will be patched.
|
|
3605
|
+
*
|
|
3606
|
+
* ### Operation types
|
|
3607
|
+
* - `'set'` – an *overwriting* operation: sets the full field value for primitive targets, and merges the provided value with existing values for objects
|
|
3608
|
+
* - `'append'`:
|
|
3609
|
+
* – array fields: appends new items to the end of the array,
|
|
3610
|
+
* - string fields: '"existing content" "new content"'
|
|
3611
|
+
* - text fields: '"existing content"\\n"new content"'
|
|
3612
|
+
* - number fields: existing + new
|
|
3613
|
+
* - other field types not mentioned will set instead (dates, url)
|
|
3614
|
+
* - `'mixed'` – sets non-array fields, and appends to array fields
|
|
3615
|
+
* - `'unset'` – removes whatever value is on the target path
|
|
3616
|
+
*
|
|
3617
|
+
* All operations except unset requires a `value`.
|
|
3618
|
+
*
|
|
3619
|
+
* #### Appending in the middle of arrays
|
|
3620
|
+
* To append to an array, use the 'append' operation, and provide an array value with one or more array items.
|
|
3621
|
+
*
|
|
3622
|
+
* `target: {path: ['array'], operation: 'append', value: [{_type: 'item' _key: 'a'}]}` will append the items in the value to the existing array.
|
|
3623
|
+
*
|
|
3624
|
+
* To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append', value: [{_type: 'item' _key: 'a'}]}`.
|
|
3625
|
+
* Here, `{_type: 'item' _key: 'a'}` will be appended after the array item with key `'appendAfterKey'`
|
|
3626
|
+
*
|
|
3627
|
+
* It is optional to provide a _key for inserted array items; if one isn't provided, it will be generated.
|
|
3628
|
+
*/
|
|
3629
|
+
operation: PatchOperation
|
|
3630
|
+
path: AgentActionPathSegment | AgentActionPath
|
|
3631
|
+
} & (
|
|
3632
|
+
| {
|
|
3633
|
+
operation: 'unset'
|
|
3634
|
+
value?: never
|
|
3635
|
+
}
|
|
3636
|
+
| {
|
|
3637
|
+
operation: Exclude<PatchOperation, 'unset'>
|
|
3638
|
+
value: AnyNonNullable
|
|
3639
|
+
}
|
|
3640
|
+
)
|
|
3641
|
+
|
|
3642
|
+
/**
|
|
3643
|
+
* Create a new document, then patch it
|
|
3644
|
+
* @beta
|
|
3645
|
+
*/
|
|
3646
|
+
declare interface PatchTargetDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
|
|
3647
|
+
/**
|
|
3648
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
3649
|
+
*/
|
|
3650
|
+
targetDocument: GenerateTargetDocument<T>
|
|
3651
|
+
documentId?: never
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3417
3654
|
/** @public */
|
|
3418
3655
|
declare interface ProgressEvent_2 {
|
|
3419
3656
|
type: 'progress'
|
|
@@ -3445,6 +3682,131 @@ export declare class ProjectsClient {
|
|
|
3445
3682
|
getById(projectId: string): Promise<SanityProject>
|
|
3446
3683
|
}
|
|
3447
3684
|
|
|
3685
|
+
/**
|
|
3686
|
+
* @beta
|
|
3687
|
+
*/
|
|
3688
|
+
declare interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
|
|
3689
|
+
/**
|
|
3690
|
+
*
|
|
3691
|
+
* When true, the response body will be json according to the instruction.
|
|
3692
|
+
* When false, the response is the raw text response to the instruction.
|
|
3693
|
+
*
|
|
3694
|
+
* Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3695
|
+
*/
|
|
3696
|
+
format: 'json'
|
|
3697
|
+
}
|
|
3698
|
+
|
|
3699
|
+
/** @beta */
|
|
3700
|
+
export declare type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
|
|
3701
|
+
| PromptTextResponse
|
|
3702
|
+
| PromptJsonResponse<T>
|
|
3703
|
+
) &
|
|
3704
|
+
PromptRequestBase
|
|
3705
|
+
|
|
3706
|
+
/** @beta */
|
|
3707
|
+
declare interface PromptRequestBase {
|
|
3708
|
+
/**
|
|
3709
|
+
* Instruct the LLM how it should generate content. Be as specific and detailed as needed.
|
|
3710
|
+
*
|
|
3711
|
+
* The LLM only has access to information in the instruction, plus the target schema.
|
|
3712
|
+
*
|
|
3713
|
+
* String template with support for $variable from `instructionParams`.
|
|
3714
|
+
* */
|
|
3715
|
+
instruction: string
|
|
3716
|
+
/**
|
|
3717
|
+
* param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
|
|
3718
|
+
*
|
|
3719
|
+
* ### Examples
|
|
3720
|
+
*
|
|
3721
|
+
* #### Constant
|
|
3722
|
+
*
|
|
3723
|
+
* ##### Shorthand
|
|
3724
|
+
* ```ts
|
|
3725
|
+
* client.agent.action.prompt({
|
|
3726
|
+
* instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
|
|
3727
|
+
* instructionParams: {
|
|
3728
|
+
* topic: 'Grapefruit'
|
|
3729
|
+
* },
|
|
3730
|
+
* })
|
|
3731
|
+
* ```
|
|
3732
|
+
* ##### Object-form
|
|
3733
|
+
*
|
|
3734
|
+
* ```ts
|
|
3735
|
+
* client.agent.action.prompt({
|
|
3736
|
+
* instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
|
|
3737
|
+
* instructionParams: {
|
|
3738
|
+
* topic: {
|
|
3739
|
+
* type: 'constant',
|
|
3740
|
+
* value: 'Grapefruit'
|
|
3741
|
+
* },
|
|
3742
|
+
* },
|
|
3743
|
+
* })
|
|
3744
|
+
* ```
|
|
3745
|
+
* #### Field
|
|
3746
|
+
* ```ts
|
|
3747
|
+
* client.agent.action.prompt({
|
|
3748
|
+
* instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
|
|
3749
|
+
* instructionParams: {
|
|
3750
|
+
* pte: {
|
|
3751
|
+
* type: 'field',
|
|
3752
|
+
* path: ['pteField'],
|
|
3753
|
+
* documentId: 'someSanityDocId'
|
|
3754
|
+
* },
|
|
3755
|
+
* },
|
|
3756
|
+
* })
|
|
3757
|
+
* ```
|
|
3758
|
+
* #### Document
|
|
3759
|
+
* ```ts
|
|
3760
|
+
* client.agent.action.prompt({
|
|
3761
|
+
* json: true,
|
|
3762
|
+
* instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
|
|
3763
|
+
* instructionParams: {
|
|
3764
|
+
* document: {
|
|
3765
|
+
* type: 'document',
|
|
3766
|
+
* documentId: 'someSanityDocId'
|
|
3767
|
+
* },
|
|
3768
|
+
* },
|
|
3769
|
+
* })
|
|
3770
|
+
* ```
|
|
3771
|
+
*
|
|
3772
|
+
* #### GROQ
|
|
3773
|
+
* ```ts
|
|
3774
|
+
* client.agent.action.prompt({
|
|
3775
|
+
* instruction: 'Return the best title amongst these: $titles.',
|
|
3776
|
+
* instructionParams: {
|
|
3777
|
+
* titles: {
|
|
3778
|
+
* type: 'groq',
|
|
3779
|
+
* query: '* [_type==$type].title',
|
|
3780
|
+
* params: {type: 'article'}
|
|
3781
|
+
* },
|
|
3782
|
+
* },
|
|
3783
|
+
* })
|
|
3784
|
+
* ```
|
|
3785
|
+
* */
|
|
3786
|
+
instructionParams?: AgentActionParams<{
|
|
3787
|
+
docIdRequired: true
|
|
3788
|
+
}>
|
|
3789
|
+
/**
|
|
3790
|
+
* Controls how much variance the instructions will run with.
|
|
3791
|
+
*
|
|
3792
|
+
* Value must be in the range [0, 1] (inclusive).
|
|
3793
|
+
*
|
|
3794
|
+
* Default: 0.3
|
|
3795
|
+
*/
|
|
3796
|
+
temperature?: number
|
|
3797
|
+
}
|
|
3798
|
+
|
|
3799
|
+
declare interface PromptTextResponse {
|
|
3800
|
+
/**
|
|
3801
|
+
*
|
|
3802
|
+
* When true, the response body will be json according to the instruction.
|
|
3803
|
+
* When false, the response is the raw text response to the instruction.
|
|
3804
|
+
*
|
|
3805
|
+
* Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
|
|
3806
|
+
*/
|
|
3807
|
+
format?: 'text'
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3448
3810
|
/**
|
|
3449
3811
|
* Publishes a draft document.
|
|
3450
3812
|
* If a published version of the document already exists this is replaced by the current draft document.
|
|
@@ -3531,6 +3893,23 @@ export declare interface QueryParams {
|
|
|
3531
3893
|
cacheMode?: never
|
|
3532
3894
|
}
|
|
3533
3895
|
|
|
3896
|
+
/**
|
|
3897
|
+
* Returned from the Content Lake API when a query is malformed, usually with a start
|
|
3898
|
+
* and end column to indicate where the error occurred, but not always. Can we used to
|
|
3899
|
+
* provide a more structured error message to the user.
|
|
3900
|
+
*
|
|
3901
|
+
* This will be located under the response `error` property.
|
|
3902
|
+
*
|
|
3903
|
+
* @public
|
|
3904
|
+
*/
|
|
3905
|
+
export declare interface QueryParseError {
|
|
3906
|
+
type: 'queryParseError'
|
|
3907
|
+
description: string
|
|
3908
|
+
start?: number
|
|
3909
|
+
end?: number
|
|
3910
|
+
query?: string
|
|
3911
|
+
}
|
|
3912
|
+
|
|
3534
3913
|
/**
|
|
3535
3914
|
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
3536
3915
|
* @public
|
|
@@ -5137,6 +5516,8 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
|
|
|
5137
5516
|
schemaId: string
|
|
5138
5517
|
/**
|
|
5139
5518
|
* The source document the transformation will use as input.
|
|
5519
|
+
*
|
|
5520
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5140
5521
|
*/
|
|
5141
5522
|
documentId: string
|
|
5142
5523
|
/**
|
|
@@ -5144,12 +5525,14 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
|
|
|
5144
5525
|
* then it is transformed according to the instruction.
|
|
5145
5526
|
*
|
|
5146
5527
|
* When omitted, the source document (documentId) is also the target document.
|
|
5528
|
+
*
|
|
5529
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5147
5530
|
*/
|
|
5148
5531
|
targetDocument?: TransformTargetDocument
|
|
5149
5532
|
/**
|
|
5150
5533
|
* Instruct the LLM how to transform the input to th output.
|
|
5151
5534
|
*
|
|
5152
|
-
* String template
|
|
5535
|
+
* String template with support for $variable from `instructionParams`.
|
|
5153
5536
|
*
|
|
5154
5537
|
* Capped to 2000 characters, after variables has been injected.
|
|
5155
5538
|
* */
|
|
@@ -5248,6 +5631,21 @@ declare interface TransformRequestBase extends AgentActionRequestBase {
|
|
|
5248
5631
|
* It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
5249
5632
|
*
|
|
5250
5633
|
* Default max depth for transform: 12
|
|
5634
|
+
*
|
|
5635
|
+
* ## Transforming images
|
|
5636
|
+
*
|
|
5637
|
+
* To transform an existing image, directly target an image asset path.
|
|
5638
|
+
*
|
|
5639
|
+
* For example, all the following will transform the image into the provided asset:
|
|
5640
|
+
* * `target: {path: ['image', 'asset'] }`
|
|
5641
|
+
* * `target: {path: 'image', include: ['asset'] }`
|
|
5642
|
+
*
|
|
5643
|
+
* Image transform can be combined with regular content targets:
|
|
5644
|
+
* * `target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]`
|
|
5645
|
+
*
|
|
5646
|
+
* Image transform can have per-path instructions, just like any other target paths:
|
|
5647
|
+
* * `target: [{path: ['image', 'asset'], instruction: 'Make the sky blue' }`
|
|
5648
|
+
*
|
|
5251
5649
|
* @see AgentActionRequestBase#conditionalPaths
|
|
5252
5650
|
*/
|
|
5253
5651
|
target?: TransformTarget | TransformTarget[]
|
|
@@ -5258,7 +5656,7 @@ export declare interface TransformTarget extends AgentActionTarget {
|
|
|
5258
5656
|
/**
|
|
5259
5657
|
* Specifies a tailored instruction of this target.
|
|
5260
5658
|
*
|
|
5261
|
-
*
|
|
5659
|
+
* String template with support for $variable from `instructionParams`.
|
|
5262
5660
|
* */
|
|
5263
5661
|
instruction?: string
|
|
5264
5662
|
/**
|
|
@@ -5271,7 +5669,11 @@ export declare interface TransformTarget extends AgentActionTarget {
|
|
|
5271
5669
|
include?: (AgentActionPathSegment | TransformTargetInclude)[]
|
|
5272
5670
|
}
|
|
5273
5671
|
|
|
5274
|
-
/**
|
|
5672
|
+
/**
|
|
5673
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5674
|
+
*
|
|
5675
|
+
* @beta
|
|
5676
|
+
*/
|
|
5275
5677
|
export declare type TransformTargetDocument =
|
|
5276
5678
|
| {
|
|
5277
5679
|
operation: 'edit'
|
|
@@ -5295,7 +5697,7 @@ export declare interface TransformTargetInclude extends AgentActionTargetInclude
|
|
|
5295
5697
|
/**
|
|
5296
5698
|
* Specifies a tailored instruction of this target.
|
|
5297
5699
|
*
|
|
5298
|
-
*
|
|
5700
|
+
* String template with support for $variable from `instructionParams`. */
|
|
5299
5701
|
instruction?: string
|
|
5300
5702
|
/**
|
|
5301
5703
|
* By default, all children up to `target.maxPathDepth` are included.
|
|
@@ -5337,6 +5739,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
|
|
|
5337
5739
|
schemaId: string
|
|
5338
5740
|
/**
|
|
5339
5741
|
* The source document the transformation will use as input.
|
|
5742
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5340
5743
|
*/
|
|
5341
5744
|
documentId: string
|
|
5342
5745
|
/**
|
|
@@ -5344,6 +5747,8 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
|
|
|
5344
5747
|
* then it is translated according to the instruction.
|
|
5345
5748
|
*
|
|
5346
5749
|
* When omitted, the source document (documentId) is also the target document.
|
|
5750
|
+
*
|
|
5751
|
+
* @see #AgentActionSchema.forcePublishedWrite
|
|
5347
5752
|
*/
|
|
5348
5753
|
targetDocument?: TransformTargetDocument
|
|
5349
5754
|
/**
|
|
@@ -5396,7 +5801,7 @@ declare interface TranslateRequestBase extends AgentActionRequestBase {
|
|
|
5396
5801
|
|
|
5397
5802
|
/** @beta */
|
|
5398
5803
|
export declare interface TranslateTarget extends AgentActionTarget {
|
|
5399
|
-
/**
|
|
5804
|
+
/** String template using $variable from styleGuideParams. */
|
|
5400
5805
|
styleGuide?: string
|
|
5401
5806
|
/**
|
|
5402
5807
|
* By default, all children up to `target.maxPathDepth` are included.
|
|
@@ -5410,7 +5815,7 @@ export declare interface TranslateTarget extends AgentActionTarget {
|
|
|
5410
5815
|
|
|
5411
5816
|
/** @beta */
|
|
5412
5817
|
export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
|
|
5413
|
-
/**
|
|
5818
|
+
/** String template using $variable from styleGuideParams. */
|
|
5414
5819
|
styleGuide?: string
|
|
5415
5820
|
/**
|
|
5416
5821
|
* By default, all children up to `target.maxPathDepth` are included.
|