@sanity/client 6.28.2 → 6.28.3-instruct.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-cjs/config.cjs +6 -13
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +6 -13
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +52 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +247 -3
- package/dist/index.browser.d.ts +247 -3
- package/dist/index.browser.js +52 -18
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +47 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +237 -4
- package/dist/index.d.ts +237 -4
- package/dist/index.js +47 -6
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +236 -3
- package/dist/stega.browser.d.ts +236 -3
- package/dist/stega.d.cts +236 -3
- package/dist/stega.d.ts +236 -3
- package/package.json +20 -20
- package/src/SanityClient.ts +5 -1
- package/src/ai/AiClient.ts +93 -0
- package/src/ai/types.ts +206 -0
- package/src/config.ts +9 -18
- package/src/data/listen.ts +1 -1
- package/src/http/requestOptions.ts +1 -1
- package/src/index.ts +1 -1
- package/src/types.ts +13 -3
- package/src/util/shareReplayLatest.ts +4 -1
- package/src/warnings.ts +5 -0
- package/umd/sanityClient.js +59 -23
- package/umd/sanityClient.min.js +2 -2
package/dist/stega.d.cts
CHANGED
|
@@ -33,6 +33,18 @@ export declare interface ActionErrorItem {
|
|
|
33
33
|
index: number
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** @public */
|
|
37
|
+
declare class AiClient {
|
|
38
|
+
#private
|
|
39
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
40
|
+
instruct(request: InstructAsyncInstruction): Promise<{
|
|
41
|
+
_id: string
|
|
42
|
+
}>
|
|
43
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
44
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
45
|
+
): Promise<IdentifiedSanityDocumentStub & DocumentShape>
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
/** @internal */
|
|
37
49
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
38
50
|
returnFirst: false
|
|
@@ -110,6 +122,18 @@ export declare class AssetsClient {
|
|
|
110
122
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
111
123
|
}
|
|
112
124
|
|
|
125
|
+
declare interface Async {
|
|
126
|
+
/**
|
|
127
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
128
|
+
* The instruction operation will carry on in the background.
|
|
129
|
+
*
|
|
130
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
131
|
+
*
|
|
132
|
+
* async: true is incompatible with skipWrite, as async: true does not return the resulting document
|
|
133
|
+
*/
|
|
134
|
+
async: true
|
|
135
|
+
}
|
|
136
|
+
|
|
113
137
|
/** @internal */
|
|
114
138
|
export declare type AttributeSet = {
|
|
115
139
|
[key: string]: Any
|
|
@@ -336,14 +360,14 @@ export declare interface ClientConfig {
|
|
|
336
360
|
/**
|
|
337
361
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
338
362
|
* @remarks
|
|
339
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
363
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
340
364
|
* @defaultValue 'published'
|
|
341
365
|
*/
|
|
342
366
|
perspective?: ClientPerspective
|
|
343
367
|
apiHost?: string
|
|
344
368
|
/**
|
|
345
369
|
@remarks
|
|
346
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
370
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
347
371
|
*/
|
|
348
372
|
apiVersion?: string
|
|
349
373
|
proxy?: string
|
|
@@ -673,6 +697,18 @@ export declare type CreateAction = {
|
|
|
673
697
|
*/
|
|
674
698
|
export declare const createClient: (config: ClientConfig_2) => SanityClient
|
|
675
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Instruction to create a new document
|
|
702
|
+
* @beta
|
|
703
|
+
*/
|
|
704
|
+
declare interface CreateDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
|
|
705
|
+
createDocument: {
|
|
706
|
+
/** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
|
|
707
|
+
_id?: string
|
|
708
|
+
_type: string
|
|
709
|
+
} & SanityDocumentStub<T>
|
|
710
|
+
}
|
|
711
|
+
|
|
676
712
|
/** @public */
|
|
677
713
|
export declare interface CurrentSanityUser {
|
|
678
714
|
id: string
|
|
@@ -817,6 +853,19 @@ export declare type DisconnectEvent = {
|
|
|
817
853
|
reason: string
|
|
818
854
|
}
|
|
819
855
|
|
|
856
|
+
/**
|
|
857
|
+
*
|
|
858
|
+
* Includes a LLM-friendly version of the document in the instruction
|
|
859
|
+
* @beta
|
|
860
|
+
* */
|
|
861
|
+
declare interface DocumentInstructionParam {
|
|
862
|
+
type: 'document'
|
|
863
|
+
/**
|
|
864
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
865
|
+
*/
|
|
866
|
+
documentId?: string
|
|
867
|
+
}
|
|
868
|
+
|
|
820
869
|
/**
|
|
821
870
|
* Modifies an existing draft document.
|
|
822
871
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -878,6 +927,14 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
878
927
|
*/
|
|
879
928
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
880
929
|
|
|
930
|
+
/**
|
|
931
|
+
* Instruction for an existing document.
|
|
932
|
+
* @beta
|
|
933
|
+
*/
|
|
934
|
+
declare interface ExistingDocumentRequest {
|
|
935
|
+
documentId: string
|
|
936
|
+
}
|
|
937
|
+
|
|
881
938
|
/** @public */
|
|
882
939
|
export declare type FilterDefault = (props: {
|
|
883
940
|
/**
|
|
@@ -1063,6 +1120,145 @@ export declare type InsertPatch =
|
|
|
1063
1120
|
items: Any[]
|
|
1064
1121
|
}
|
|
1065
1122
|
|
|
1123
|
+
/** @beta */
|
|
1124
|
+
export declare type InstructAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> =
|
|
1125
|
+
(ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Async
|
|
1126
|
+
|
|
1127
|
+
/** @beta */
|
|
1128
|
+
export declare interface InstructConstantInstructionParam {
|
|
1129
|
+
type: 'constant'
|
|
1130
|
+
value: string
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
*
|
|
1135
|
+
* Includes a LLM-friendly version of the field value in the instruction
|
|
1136
|
+
* @beta
|
|
1137
|
+
* */
|
|
1138
|
+
export declare interface InstructFieldInstructionParam {
|
|
1139
|
+
type: 'field'
|
|
1140
|
+
/**
|
|
1141
|
+
* Examples: 'title', 'array[_key=="key"].field'
|
|
1142
|
+
*/
|
|
1143
|
+
path: string
|
|
1144
|
+
/**
|
|
1145
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
1146
|
+
*/
|
|
1147
|
+
documentId?: string
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Includes a LLM-friendly version of GROQ query result in the instruction
|
|
1152
|
+
* @beta
|
|
1153
|
+
* */
|
|
1154
|
+
export declare interface InstructGroqInstructionParam {
|
|
1155
|
+
type: 'groq'
|
|
1156
|
+
query: string
|
|
1157
|
+
params?: Record<string, string>
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/** @beta */
|
|
1161
|
+
export declare type InstructInstruction<T extends Record<string, Any> = Record<string, Any>> =
|
|
1162
|
+
| InstructSyncInstruction<T>
|
|
1163
|
+
| InstructAsyncInstruction<T>
|
|
1164
|
+
|
|
1165
|
+
/** @beta */
|
|
1166
|
+
export declare type InstructInstructionParam =
|
|
1167
|
+
| string
|
|
1168
|
+
| InstructConstantInstructionParam
|
|
1169
|
+
| InstructFieldInstructionParam
|
|
1170
|
+
| DocumentInstructionParam
|
|
1171
|
+
| InstructGroqInstructionParam
|
|
1172
|
+
|
|
1173
|
+
/** @beta */
|
|
1174
|
+
export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
|
|
1175
|
+
|
|
1176
|
+
declare interface InstructRequestBase {
|
|
1177
|
+
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
1178
|
+
schemaId: string
|
|
1179
|
+
/** string template using $variable – more on this below under "Dynamic instruction" */
|
|
1180
|
+
instruction: string
|
|
1181
|
+
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
1182
|
+
instructionParams?: InstructInstructionParams
|
|
1183
|
+
/**
|
|
1184
|
+
* Optional document path output target for the instruction.
|
|
1185
|
+
* When provided, the instruction will apply to this path in the document and its children.
|
|
1186
|
+
*
|
|
1187
|
+
* ## Examples
|
|
1188
|
+
* - `path: 'title'` will output to the title field in the document
|
|
1189
|
+
* - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
|
|
1190
|
+
*/
|
|
1191
|
+
path?: string
|
|
1192
|
+
/**
|
|
1193
|
+
* Controls sub-paths in the document that can be output to.
|
|
1194
|
+
*
|
|
1195
|
+
* The string-paths are relative to the `path` param
|
|
1196
|
+
*
|
|
1197
|
+
* Note: these path strings are less strictly validated than the `path` param itself:
|
|
1198
|
+
* if an relative-path does not exist or is invalid, it will be silently ignored.
|
|
1199
|
+
*
|
|
1200
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1201
|
+
* @see InstructRequestBase#outputTypes
|
|
1202
|
+
*/
|
|
1203
|
+
relativeOutputPaths?:
|
|
1204
|
+
| {
|
|
1205
|
+
include: string[]
|
|
1206
|
+
}
|
|
1207
|
+
| {
|
|
1208
|
+
exclude: string[]
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Controls which types the instruction is allowed to output to.
|
|
1212
|
+
*
|
|
1213
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1214
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1215
|
+
*/
|
|
1216
|
+
outputTypes?:
|
|
1217
|
+
| {
|
|
1218
|
+
include: string[]
|
|
1219
|
+
}
|
|
1220
|
+
| {
|
|
1221
|
+
exclude: string[]
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
|
|
1225
|
+
*
|
|
1226
|
+
* By default, AI Instruct will not output to conditional `readOnly` and `hidden` fields,
|
|
1227
|
+
* ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
|
|
1228
|
+
*
|
|
1229
|
+
* `conditionalPaths` param allows setting the default conditional value for
|
|
1230
|
+
* `hidden` and `readOnly` to false,
|
|
1231
|
+
* or individually set `hidden` and `readOnly` state for individual document paths.
|
|
1232
|
+
*
|
|
1233
|
+
*
|
|
1234
|
+
* Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Instruct,
|
|
1235
|
+
* and cannot be changed via conditionalPaths.
|
|
1236
|
+
*
|
|
1237
|
+
* conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
|
|
1238
|
+
*
|
|
1239
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1240
|
+
* @see InstructRequestBase#outputTypes
|
|
1241
|
+
*/
|
|
1242
|
+
conditionalPaths?: {
|
|
1243
|
+
defaultReadOnly?: boolean
|
|
1244
|
+
defaultHidden?: boolean
|
|
1245
|
+
paths?: {
|
|
1246
|
+
/** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
|
|
1247
|
+
path: string
|
|
1248
|
+
readOnly: boolean
|
|
1249
|
+
hidden: boolean
|
|
1250
|
+
}[]
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/** @beta */
|
|
1255
|
+
export declare type InstructSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
1256
|
+
| ExistingDocumentRequest
|
|
1257
|
+
| CreateDocumentRequest<T>
|
|
1258
|
+
) &
|
|
1259
|
+
InstructRequestBase &
|
|
1260
|
+
Sync
|
|
1261
|
+
|
|
1066
1262
|
/**
|
|
1067
1263
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
1068
1264
|
*
|
|
@@ -1134,7 +1330,7 @@ export declare interface ListenOptions {
|
|
|
1134
1330
|
includePreviousRevision?: boolean
|
|
1135
1331
|
/**
|
|
1136
1332
|
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
1137
|
-
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/
|
|
1333
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
|
|
1138
1334
|
* If you need events from drafts and versions, set this to `true`.
|
|
1139
1335
|
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
1140
1336
|
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
@@ -1430,6 +1626,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1430
1626
|
[key: string]: Any
|
|
1431
1627
|
}
|
|
1432
1628
|
|
|
1629
|
+
/** @public */
|
|
1630
|
+
declare class ObservableAiClient {
|
|
1631
|
+
#private
|
|
1632
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1633
|
+
instruct(request: InstructAsyncInstruction): Observable<{
|
|
1634
|
+
_id: string
|
|
1635
|
+
}>
|
|
1636
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
1637
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
1638
|
+
): Observable<IdentifiedSanityDocumentStub & DocumentShape>
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1433
1641
|
/** @internal */
|
|
1434
1642
|
export declare class ObservableAssetsClient {
|
|
1435
1643
|
#private
|
|
@@ -1607,6 +1815,7 @@ export declare class ObservableSanityClient {
|
|
|
1607
1815
|
live: LiveClient
|
|
1608
1816
|
projects: ObservableProjectsClient
|
|
1609
1817
|
users: ObservableUsersClient
|
|
1818
|
+
ai: ObservableAiClient
|
|
1610
1819
|
/**
|
|
1611
1820
|
* Instance properties
|
|
1612
1821
|
*/
|
|
@@ -2538,6 +2747,7 @@ export declare class SanityClient {
|
|
|
2538
2747
|
live: LiveClient
|
|
2539
2748
|
projects: ProjectsClient
|
|
2540
2749
|
users: UsersClient
|
|
2750
|
+
ai: AiClient
|
|
2541
2751
|
/**
|
|
2542
2752
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2543
2753
|
*/
|
|
@@ -3321,6 +3531,29 @@ export declare type StudioBaseUrl =
|
|
|
3321
3531
|
/** @alpha */
|
|
3322
3532
|
export declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
|
|
3323
3533
|
|
|
3534
|
+
declare interface Sync {
|
|
3535
|
+
/**
|
|
3536
|
+
* By default, skipWrite: false.
|
|
3537
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3538
|
+
*
|
|
3539
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3540
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3541
|
+
*
|
|
3542
|
+
* skipWrite: true is incompatible with async: true,
|
|
3543
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3544
|
+
*/
|
|
3545
|
+
skipWrite?: boolean
|
|
3546
|
+
/**
|
|
3547
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3548
|
+
* The instruction operation will carry on in the background.
|
|
3549
|
+
*
|
|
3550
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3551
|
+
*
|
|
3552
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3553
|
+
*/
|
|
3554
|
+
async?: false
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3324
3557
|
/** @public */
|
|
3325
3558
|
export declare type SyncTag = `s1:${string}`
|
|
3326
3559
|
|
package/dist/stega.d.ts
CHANGED
|
@@ -33,6 +33,18 @@ export declare interface ActionErrorItem {
|
|
|
33
33
|
index: number
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** @public */
|
|
37
|
+
declare class AiClient {
|
|
38
|
+
#private
|
|
39
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
40
|
+
instruct(request: InstructAsyncInstruction): Promise<{
|
|
41
|
+
_id: string
|
|
42
|
+
}>
|
|
43
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
44
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
45
|
+
): Promise<IdentifiedSanityDocumentStub & DocumentShape>
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
/** @internal */
|
|
37
49
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
38
50
|
returnFirst: false
|
|
@@ -110,6 +122,18 @@ export declare class AssetsClient {
|
|
|
110
122
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
111
123
|
}
|
|
112
124
|
|
|
125
|
+
declare interface Async {
|
|
126
|
+
/**
|
|
127
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
128
|
+
* The instruction operation will carry on in the background.
|
|
129
|
+
*
|
|
130
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
131
|
+
*
|
|
132
|
+
* async: true is incompatible with skipWrite, as async: true does not return the resulting document
|
|
133
|
+
*/
|
|
134
|
+
async: true
|
|
135
|
+
}
|
|
136
|
+
|
|
113
137
|
/** @internal */
|
|
114
138
|
export declare type AttributeSet = {
|
|
115
139
|
[key: string]: Any
|
|
@@ -336,14 +360,14 @@ export declare interface ClientConfig {
|
|
|
336
360
|
/**
|
|
337
361
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
338
362
|
* @remarks
|
|
339
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
363
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
340
364
|
* @defaultValue 'published'
|
|
341
365
|
*/
|
|
342
366
|
perspective?: ClientPerspective
|
|
343
367
|
apiHost?: string
|
|
344
368
|
/**
|
|
345
369
|
@remarks
|
|
346
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
370
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
347
371
|
*/
|
|
348
372
|
apiVersion?: string
|
|
349
373
|
proxy?: string
|
|
@@ -673,6 +697,18 @@ export declare type CreateAction = {
|
|
|
673
697
|
*/
|
|
674
698
|
export declare const createClient: (config: ClientConfig_2) => SanityClient
|
|
675
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Instruction to create a new document
|
|
702
|
+
* @beta
|
|
703
|
+
*/
|
|
704
|
+
declare interface CreateDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
|
|
705
|
+
createDocument: {
|
|
706
|
+
/** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
|
|
707
|
+
_id?: string
|
|
708
|
+
_type: string
|
|
709
|
+
} & SanityDocumentStub<T>
|
|
710
|
+
}
|
|
711
|
+
|
|
676
712
|
/** @public */
|
|
677
713
|
export declare interface CurrentSanityUser {
|
|
678
714
|
id: string
|
|
@@ -817,6 +853,19 @@ export declare type DisconnectEvent = {
|
|
|
817
853
|
reason: string
|
|
818
854
|
}
|
|
819
855
|
|
|
856
|
+
/**
|
|
857
|
+
*
|
|
858
|
+
* Includes a LLM-friendly version of the document in the instruction
|
|
859
|
+
* @beta
|
|
860
|
+
* */
|
|
861
|
+
declare interface DocumentInstructionParam {
|
|
862
|
+
type: 'document'
|
|
863
|
+
/**
|
|
864
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
865
|
+
*/
|
|
866
|
+
documentId?: string
|
|
867
|
+
}
|
|
868
|
+
|
|
820
869
|
/**
|
|
821
870
|
* Modifies an existing draft document.
|
|
822
871
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -878,6 +927,14 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
878
927
|
*/
|
|
879
928
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
880
929
|
|
|
930
|
+
/**
|
|
931
|
+
* Instruction for an existing document.
|
|
932
|
+
* @beta
|
|
933
|
+
*/
|
|
934
|
+
declare interface ExistingDocumentRequest {
|
|
935
|
+
documentId: string
|
|
936
|
+
}
|
|
937
|
+
|
|
881
938
|
/** @public */
|
|
882
939
|
export declare type FilterDefault = (props: {
|
|
883
940
|
/**
|
|
@@ -1063,6 +1120,145 @@ export declare type InsertPatch =
|
|
|
1063
1120
|
items: Any[]
|
|
1064
1121
|
}
|
|
1065
1122
|
|
|
1123
|
+
/** @beta */
|
|
1124
|
+
export declare type InstructAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> =
|
|
1125
|
+
(ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Async
|
|
1126
|
+
|
|
1127
|
+
/** @beta */
|
|
1128
|
+
export declare interface InstructConstantInstructionParam {
|
|
1129
|
+
type: 'constant'
|
|
1130
|
+
value: string
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
*
|
|
1135
|
+
* Includes a LLM-friendly version of the field value in the instruction
|
|
1136
|
+
* @beta
|
|
1137
|
+
* */
|
|
1138
|
+
export declare interface InstructFieldInstructionParam {
|
|
1139
|
+
type: 'field'
|
|
1140
|
+
/**
|
|
1141
|
+
* Examples: 'title', 'array[_key=="key"].field'
|
|
1142
|
+
*/
|
|
1143
|
+
path: string
|
|
1144
|
+
/**
|
|
1145
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
1146
|
+
*/
|
|
1147
|
+
documentId?: string
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Includes a LLM-friendly version of GROQ query result in the instruction
|
|
1152
|
+
* @beta
|
|
1153
|
+
* */
|
|
1154
|
+
export declare interface InstructGroqInstructionParam {
|
|
1155
|
+
type: 'groq'
|
|
1156
|
+
query: string
|
|
1157
|
+
params?: Record<string, string>
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/** @beta */
|
|
1161
|
+
export declare type InstructInstruction<T extends Record<string, Any> = Record<string, Any>> =
|
|
1162
|
+
| InstructSyncInstruction<T>
|
|
1163
|
+
| InstructAsyncInstruction<T>
|
|
1164
|
+
|
|
1165
|
+
/** @beta */
|
|
1166
|
+
export declare type InstructInstructionParam =
|
|
1167
|
+
| string
|
|
1168
|
+
| InstructConstantInstructionParam
|
|
1169
|
+
| InstructFieldInstructionParam
|
|
1170
|
+
| DocumentInstructionParam
|
|
1171
|
+
| InstructGroqInstructionParam
|
|
1172
|
+
|
|
1173
|
+
/** @beta */
|
|
1174
|
+
export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
|
|
1175
|
+
|
|
1176
|
+
declare interface InstructRequestBase {
|
|
1177
|
+
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
1178
|
+
schemaId: string
|
|
1179
|
+
/** string template using $variable – more on this below under "Dynamic instruction" */
|
|
1180
|
+
instruction: string
|
|
1181
|
+
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
1182
|
+
instructionParams?: InstructInstructionParams
|
|
1183
|
+
/**
|
|
1184
|
+
* Optional document path output target for the instruction.
|
|
1185
|
+
* When provided, the instruction will apply to this path in the document and its children.
|
|
1186
|
+
*
|
|
1187
|
+
* ## Examples
|
|
1188
|
+
* - `path: 'title'` will output to the title field in the document
|
|
1189
|
+
* - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
|
|
1190
|
+
*/
|
|
1191
|
+
path?: string
|
|
1192
|
+
/**
|
|
1193
|
+
* Controls sub-paths in the document that can be output to.
|
|
1194
|
+
*
|
|
1195
|
+
* The string-paths are relative to the `path` param
|
|
1196
|
+
*
|
|
1197
|
+
* Note: these path strings are less strictly validated than the `path` param itself:
|
|
1198
|
+
* if an relative-path does not exist or is invalid, it will be silently ignored.
|
|
1199
|
+
*
|
|
1200
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1201
|
+
* @see InstructRequestBase#outputTypes
|
|
1202
|
+
*/
|
|
1203
|
+
relativeOutputPaths?:
|
|
1204
|
+
| {
|
|
1205
|
+
include: string[]
|
|
1206
|
+
}
|
|
1207
|
+
| {
|
|
1208
|
+
exclude: string[]
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Controls which types the instruction is allowed to output to.
|
|
1212
|
+
*
|
|
1213
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1214
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1215
|
+
*/
|
|
1216
|
+
outputTypes?:
|
|
1217
|
+
| {
|
|
1218
|
+
include: string[]
|
|
1219
|
+
}
|
|
1220
|
+
| {
|
|
1221
|
+
exclude: string[]
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
|
|
1225
|
+
*
|
|
1226
|
+
* By default, AI Instruct will not output to conditional `readOnly` and `hidden` fields,
|
|
1227
|
+
* ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
|
|
1228
|
+
*
|
|
1229
|
+
* `conditionalPaths` param allows setting the default conditional value for
|
|
1230
|
+
* `hidden` and `readOnly` to false,
|
|
1231
|
+
* or individually set `hidden` and `readOnly` state for individual document paths.
|
|
1232
|
+
*
|
|
1233
|
+
*
|
|
1234
|
+
* Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Instruct,
|
|
1235
|
+
* and cannot be changed via conditionalPaths.
|
|
1236
|
+
*
|
|
1237
|
+
* conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
|
|
1238
|
+
*
|
|
1239
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1240
|
+
* @see InstructRequestBase#outputTypes
|
|
1241
|
+
*/
|
|
1242
|
+
conditionalPaths?: {
|
|
1243
|
+
defaultReadOnly?: boolean
|
|
1244
|
+
defaultHidden?: boolean
|
|
1245
|
+
paths?: {
|
|
1246
|
+
/** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
|
|
1247
|
+
path: string
|
|
1248
|
+
readOnly: boolean
|
|
1249
|
+
hidden: boolean
|
|
1250
|
+
}[]
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/** @beta */
|
|
1255
|
+
export declare type InstructSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
1256
|
+
| ExistingDocumentRequest
|
|
1257
|
+
| CreateDocumentRequest<T>
|
|
1258
|
+
) &
|
|
1259
|
+
InstructRequestBase &
|
|
1260
|
+
Sync
|
|
1261
|
+
|
|
1066
1262
|
/**
|
|
1067
1263
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
1068
1264
|
*
|
|
@@ -1134,7 +1330,7 @@ export declare interface ListenOptions {
|
|
|
1134
1330
|
includePreviousRevision?: boolean
|
|
1135
1331
|
/**
|
|
1136
1332
|
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
1137
|
-
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/
|
|
1333
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
|
|
1138
1334
|
* If you need events from drafts and versions, set this to `true`.
|
|
1139
1335
|
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
1140
1336
|
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
@@ -1430,6 +1626,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1430
1626
|
[key: string]: Any
|
|
1431
1627
|
}
|
|
1432
1628
|
|
|
1629
|
+
/** @public */
|
|
1630
|
+
declare class ObservableAiClient {
|
|
1631
|
+
#private
|
|
1632
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1633
|
+
instruct(request: InstructAsyncInstruction): Observable<{
|
|
1634
|
+
_id: string
|
|
1635
|
+
}>
|
|
1636
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
1637
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
1638
|
+
): Observable<IdentifiedSanityDocumentStub & DocumentShape>
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1433
1641
|
/** @internal */
|
|
1434
1642
|
export declare class ObservableAssetsClient {
|
|
1435
1643
|
#private
|
|
@@ -1607,6 +1815,7 @@ export declare class ObservableSanityClient {
|
|
|
1607
1815
|
live: LiveClient
|
|
1608
1816
|
projects: ObservableProjectsClient
|
|
1609
1817
|
users: ObservableUsersClient
|
|
1818
|
+
ai: ObservableAiClient
|
|
1610
1819
|
/**
|
|
1611
1820
|
* Instance properties
|
|
1612
1821
|
*/
|
|
@@ -2538,6 +2747,7 @@ export declare class SanityClient {
|
|
|
2538
2747
|
live: LiveClient
|
|
2539
2748
|
projects: ProjectsClient
|
|
2540
2749
|
users: UsersClient
|
|
2750
|
+
ai: AiClient
|
|
2541
2751
|
/**
|
|
2542
2752
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2543
2753
|
*/
|
|
@@ -3321,6 +3531,29 @@ export declare type StudioBaseUrl =
|
|
|
3321
3531
|
/** @alpha */
|
|
3322
3532
|
export declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
|
|
3323
3533
|
|
|
3534
|
+
declare interface Sync {
|
|
3535
|
+
/**
|
|
3536
|
+
* By default, skipWrite: false.
|
|
3537
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3538
|
+
*
|
|
3539
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3540
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3541
|
+
*
|
|
3542
|
+
* skipWrite: true is incompatible with async: true,
|
|
3543
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3544
|
+
*/
|
|
3545
|
+
skipWrite?: boolean
|
|
3546
|
+
/**
|
|
3547
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3548
|
+
* The instruction operation will carry on in the background.
|
|
3549
|
+
*
|
|
3550
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3551
|
+
*
|
|
3552
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3553
|
+
*/
|
|
3554
|
+
async?: false
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3324
3557
|
/** @public */
|
|
3325
3558
|
export declare type SyncTag = `s1:${string}`
|
|
3326
3559
|
|