@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/index.browser.d.cts
CHANGED
|
@@ -39,6 +39,18 @@ export declare interface ActionErrorItem {
|
|
|
39
39
|
index: number
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** @public */
|
|
43
|
+
declare class AiClient {
|
|
44
|
+
#private
|
|
45
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
46
|
+
instruct(request: InstructAsyncInstruction): Promise<{
|
|
47
|
+
_id: string
|
|
48
|
+
}>
|
|
49
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
50
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
51
|
+
): Promise<IdentifiedSanityDocumentStub & DocumentShape>
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
/** @internal */
|
|
43
55
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
44
56
|
returnFirst: false
|
|
@@ -57,6 +69,12 @@ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
|
|
|
57
69
|
*/
|
|
58
70
|
export declare type Any = any
|
|
59
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
declare type Any_2 = any
|
|
77
|
+
|
|
60
78
|
/** @internal */
|
|
61
79
|
export declare interface ApiError {
|
|
62
80
|
error: string
|
|
@@ -116,6 +134,18 @@ export declare class AssetsClient {
|
|
|
116
134
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
117
135
|
}
|
|
118
136
|
|
|
137
|
+
declare interface Async {
|
|
138
|
+
/**
|
|
139
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
140
|
+
* The instruction operation will carry on in the background.
|
|
141
|
+
*
|
|
142
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
143
|
+
*
|
|
144
|
+
* async: true is incompatible with skipWrite, as async: true does not return the resulting document
|
|
145
|
+
*/
|
|
146
|
+
async: true
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
/** @internal */
|
|
120
150
|
export declare type AttributeSet = {
|
|
121
151
|
[key: string]: Any
|
|
@@ -342,14 +372,14 @@ export declare interface ClientConfig {
|
|
|
342
372
|
/**
|
|
343
373
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
344
374
|
* @remarks
|
|
345
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
375
|
+
* 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}
|
|
346
376
|
* @defaultValue 'published'
|
|
347
377
|
*/
|
|
348
378
|
perspective?: ClientPerspective
|
|
349
379
|
apiHost?: string
|
|
350
380
|
/**
|
|
351
381
|
@remarks
|
|
352
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
382
|
+
* 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}
|
|
353
383
|
*/
|
|
354
384
|
apiVersion?: string
|
|
355
385
|
proxy?: string
|
|
@@ -574,6 +604,18 @@ export declare type CreateAction = {
|
|
|
574
604
|
/** @public */
|
|
575
605
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
576
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Instruction to create a new document
|
|
609
|
+
* @beta
|
|
610
|
+
*/
|
|
611
|
+
declare interface CreateDocumentRequest<T extends Record<string, Any_2> = Record<string, Any_2>> {
|
|
612
|
+
createDocument: {
|
|
613
|
+
/** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
|
|
614
|
+
_id?: string
|
|
615
|
+
_type: string
|
|
616
|
+
} & SanityDocumentStub_2<T>
|
|
617
|
+
}
|
|
618
|
+
|
|
577
619
|
/** @public */
|
|
578
620
|
export declare interface CurrentSanityUser {
|
|
579
621
|
id: string
|
|
@@ -725,6 +767,19 @@ export declare type DisconnectEvent = {
|
|
|
725
767
|
reason: string
|
|
726
768
|
}
|
|
727
769
|
|
|
770
|
+
/**
|
|
771
|
+
*
|
|
772
|
+
* Includes a LLM-friendly version of the document in the instruction
|
|
773
|
+
* @beta
|
|
774
|
+
* */
|
|
775
|
+
declare interface DocumentInstructionParam {
|
|
776
|
+
type: 'document'
|
|
777
|
+
/**
|
|
778
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
779
|
+
*/
|
|
780
|
+
documentId?: string
|
|
781
|
+
}
|
|
782
|
+
|
|
728
783
|
/**
|
|
729
784
|
* Modifies an existing draft document.
|
|
730
785
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -767,6 +822,14 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
767
822
|
*/
|
|
768
823
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
769
824
|
|
|
825
|
+
/**
|
|
826
|
+
* Instruction for an existing document.
|
|
827
|
+
* @beta
|
|
828
|
+
*/
|
|
829
|
+
declare interface ExistingDocumentRequest {
|
|
830
|
+
documentId: string
|
|
831
|
+
}
|
|
832
|
+
|
|
770
833
|
/** @public */
|
|
771
834
|
export declare type FilterDefault = (props: {
|
|
772
835
|
/**
|
|
@@ -893,6 +956,143 @@ export declare type InsertPatch =
|
|
|
893
956
|
items: Any[]
|
|
894
957
|
}
|
|
895
958
|
|
|
959
|
+
/** @beta */
|
|
960
|
+
export declare type InstructAsyncInstruction<
|
|
961
|
+
T extends Record<string, Any_2> = Record<string, Any_2>,
|
|
962
|
+
> = (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Async
|
|
963
|
+
|
|
964
|
+
/** @beta */
|
|
965
|
+
export declare interface InstructConstantInstructionParam {
|
|
966
|
+
type: 'constant'
|
|
967
|
+
value: string
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
*
|
|
972
|
+
* Includes a LLM-friendly version of the field value in the instruction
|
|
973
|
+
* @beta
|
|
974
|
+
* */
|
|
975
|
+
export declare interface InstructFieldInstructionParam {
|
|
976
|
+
type: 'field'
|
|
977
|
+
/**
|
|
978
|
+
* Examples: 'title', 'array[_key=="key"].field'
|
|
979
|
+
*/
|
|
980
|
+
path: string
|
|
981
|
+
/**
|
|
982
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
983
|
+
*/
|
|
984
|
+
documentId?: string
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Includes a LLM-friendly version of GROQ query result in the instruction
|
|
989
|
+
* @beta
|
|
990
|
+
* */
|
|
991
|
+
export declare interface InstructGroqInstructionParam {
|
|
992
|
+
type: 'groq'
|
|
993
|
+
query: string
|
|
994
|
+
params?: Record<string, string>
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/** @beta */
|
|
998
|
+
export declare type InstructInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
|
|
999
|
+
| InstructSyncInstruction<T>
|
|
1000
|
+
| InstructAsyncInstruction<T>
|
|
1001
|
+
|
|
1002
|
+
/** @beta */
|
|
1003
|
+
export declare type InstructInstructionParam =
|
|
1004
|
+
| string
|
|
1005
|
+
| InstructConstantInstructionParam
|
|
1006
|
+
| InstructFieldInstructionParam
|
|
1007
|
+
| DocumentInstructionParam
|
|
1008
|
+
| InstructGroqInstructionParam
|
|
1009
|
+
|
|
1010
|
+
/** @beta */
|
|
1011
|
+
export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
|
|
1012
|
+
|
|
1013
|
+
declare interface InstructRequestBase {
|
|
1014
|
+
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
1015
|
+
schemaId: string
|
|
1016
|
+
/** string template using $variable – more on this below under "Dynamic instruction" */
|
|
1017
|
+
instruction: string
|
|
1018
|
+
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
1019
|
+
instructionParams?: InstructInstructionParams
|
|
1020
|
+
/**
|
|
1021
|
+
* Optional document path output target for the instruction.
|
|
1022
|
+
* When provided, the instruction will apply to this path in the document and its children.
|
|
1023
|
+
*
|
|
1024
|
+
* ## Examples
|
|
1025
|
+
* - `path: 'title'` will output to the title field in the document
|
|
1026
|
+
* - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
|
|
1027
|
+
*/
|
|
1028
|
+
path?: string
|
|
1029
|
+
/**
|
|
1030
|
+
* Controls sub-paths in the document that can be output to.
|
|
1031
|
+
*
|
|
1032
|
+
* The string-paths are relative to the `path` param
|
|
1033
|
+
*
|
|
1034
|
+
* Note: these path strings are less strictly validated than the `path` param itself:
|
|
1035
|
+
* if an relative-path does not exist or is invalid, it will be silently ignored.
|
|
1036
|
+
*
|
|
1037
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1038
|
+
* @see InstructRequestBase#outputTypes
|
|
1039
|
+
*/
|
|
1040
|
+
relativeOutputPaths?:
|
|
1041
|
+
| {
|
|
1042
|
+
include: string[]
|
|
1043
|
+
}
|
|
1044
|
+
| {
|
|
1045
|
+
exclude: string[]
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Controls which types the instruction is allowed to output to.
|
|
1049
|
+
*
|
|
1050
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1051
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1052
|
+
*/
|
|
1053
|
+
outputTypes?:
|
|
1054
|
+
| {
|
|
1055
|
+
include: string[]
|
|
1056
|
+
}
|
|
1057
|
+
| {
|
|
1058
|
+
exclude: string[]
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
|
|
1062
|
+
*
|
|
1063
|
+
* By default, AI Instruct will not output to conditional `readOnly` and `hidden` fields,
|
|
1064
|
+
* ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
|
|
1065
|
+
*
|
|
1066
|
+
* `conditionalPaths` param allows setting the default conditional value for
|
|
1067
|
+
* `hidden` and `readOnly` to false,
|
|
1068
|
+
* or individually set `hidden` and `readOnly` state for individual document paths.
|
|
1069
|
+
*
|
|
1070
|
+
*
|
|
1071
|
+
* Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Instruct,
|
|
1072
|
+
* and cannot be changed via conditionalPaths.
|
|
1073
|
+
*
|
|
1074
|
+
* conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
|
|
1075
|
+
*
|
|
1076
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1077
|
+
* @see InstructRequestBase#outputTypes
|
|
1078
|
+
*/
|
|
1079
|
+
conditionalPaths?: {
|
|
1080
|
+
defaultReadOnly?: boolean
|
|
1081
|
+
defaultHidden?: boolean
|
|
1082
|
+
paths?: {
|
|
1083
|
+
/** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
|
|
1084
|
+
path: string
|
|
1085
|
+
readOnly: boolean
|
|
1086
|
+
hidden: boolean
|
|
1087
|
+
}[]
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/** @beta */
|
|
1092
|
+
export declare type InstructSyncInstruction<
|
|
1093
|
+
T extends Record<string, Any_2> = Record<string, Any_2>,
|
|
1094
|
+
> = (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Sync
|
|
1095
|
+
|
|
896
1096
|
/**
|
|
897
1097
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
898
1098
|
*
|
|
@@ -964,7 +1164,7 @@ export declare interface ListenOptions {
|
|
|
964
1164
|
includePreviousRevision?: boolean
|
|
965
1165
|
/**
|
|
966
1166
|
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
967
|
-
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/
|
|
1167
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
|
|
968
1168
|
* If you need events from drafts and versions, set this to `true`.
|
|
969
1169
|
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
970
1170
|
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
@@ -1253,6 +1453,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1253
1453
|
[key: string]: Any
|
|
1254
1454
|
}
|
|
1255
1455
|
|
|
1456
|
+
/** @public */
|
|
1457
|
+
declare class ObservableAiClient {
|
|
1458
|
+
#private
|
|
1459
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1460
|
+
instruct(request: InstructAsyncInstruction): Observable<{
|
|
1461
|
+
_id: string
|
|
1462
|
+
}>
|
|
1463
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
1464
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
1465
|
+
): Observable<IdentifiedSanityDocumentStub & DocumentShape>
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1256
1468
|
/** @internal */
|
|
1257
1469
|
export declare class ObservableAssetsClient {
|
|
1258
1470
|
#private
|
|
@@ -1430,6 +1642,7 @@ export declare class ObservableSanityClient {
|
|
|
1430
1642
|
live: LiveClient
|
|
1431
1643
|
projects: ObservableProjectsClient
|
|
1432
1644
|
users: ObservableUsersClient
|
|
1645
|
+
ai: ObservableAiClient
|
|
1433
1646
|
/**
|
|
1434
1647
|
* Instance properties
|
|
1435
1648
|
*/
|
|
@@ -2349,6 +2562,7 @@ export declare class SanityClient {
|
|
|
2349
2562
|
live: LiveClient
|
|
2350
2563
|
projects: ProjectsClient
|
|
2351
2564
|
users: UsersClient
|
|
2565
|
+
ai: AiClient
|
|
2352
2566
|
/**
|
|
2353
2567
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2354
2568
|
*/
|
|
@@ -2887,6 +3101,13 @@ export declare type SanityDocumentStub<T extends Record<string, Any> = Record<st
|
|
|
2887
3101
|
_type: string
|
|
2888
3102
|
}
|
|
2889
3103
|
|
|
3104
|
+
/** @public */
|
|
3105
|
+
declare type SanityDocumentStub_2<T extends Record<string, Any_2> = Record<string, Any_2>> = {
|
|
3106
|
+
[P in keyof T]: T[P]
|
|
3107
|
+
} & {
|
|
3108
|
+
_type: string
|
|
3109
|
+
}
|
|
3110
|
+
|
|
2890
3111
|
/** @internal */
|
|
2891
3112
|
export declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
2892
3113
|
metadata: {
|
|
@@ -3063,6 +3284,29 @@ export {StudioBaseUrl}
|
|
|
3063
3284
|
|
|
3064
3285
|
export {StudioUrl}
|
|
3065
3286
|
|
|
3287
|
+
declare interface Sync {
|
|
3288
|
+
/**
|
|
3289
|
+
* By default, skipWrite: false.
|
|
3290
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3291
|
+
*
|
|
3292
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3293
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3294
|
+
*
|
|
3295
|
+
* skipWrite: true is incompatible with async: true,
|
|
3296
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3297
|
+
*/
|
|
3298
|
+
skipWrite?: boolean
|
|
3299
|
+
/**
|
|
3300
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3301
|
+
* The instruction operation will carry on in the background.
|
|
3302
|
+
*
|
|
3303
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3304
|
+
*
|
|
3305
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3306
|
+
*/
|
|
3307
|
+
async?: false
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3066
3310
|
/** @public */
|
|
3067
3311
|
export declare type SyncTag = `s1:${string}`
|
|
3068
3312
|
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -39,6 +39,18 @@ export declare interface ActionErrorItem {
|
|
|
39
39
|
index: number
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** @public */
|
|
43
|
+
declare class AiClient {
|
|
44
|
+
#private
|
|
45
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
46
|
+
instruct(request: InstructAsyncInstruction): Promise<{
|
|
47
|
+
_id: string
|
|
48
|
+
}>
|
|
49
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
50
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
51
|
+
): Promise<IdentifiedSanityDocumentStub & DocumentShape>
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
/** @internal */
|
|
43
55
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
44
56
|
returnFirst: false
|
|
@@ -57,6 +69,12 @@ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
|
|
|
57
69
|
*/
|
|
58
70
|
export declare type Any = any
|
|
59
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
declare type Any_2 = any
|
|
77
|
+
|
|
60
78
|
/** @internal */
|
|
61
79
|
export declare interface ApiError {
|
|
62
80
|
error: string
|
|
@@ -116,6 +134,18 @@ export declare class AssetsClient {
|
|
|
116
134
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
117
135
|
}
|
|
118
136
|
|
|
137
|
+
declare interface Async {
|
|
138
|
+
/**
|
|
139
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
140
|
+
* The instruction operation will carry on in the background.
|
|
141
|
+
*
|
|
142
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
143
|
+
*
|
|
144
|
+
* async: true is incompatible with skipWrite, as async: true does not return the resulting document
|
|
145
|
+
*/
|
|
146
|
+
async: true
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
/** @internal */
|
|
120
150
|
export declare type AttributeSet = {
|
|
121
151
|
[key: string]: Any
|
|
@@ -342,14 +372,14 @@ export declare interface ClientConfig {
|
|
|
342
372
|
/**
|
|
343
373
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
344
374
|
* @remarks
|
|
345
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
375
|
+
* 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}
|
|
346
376
|
* @defaultValue 'published'
|
|
347
377
|
*/
|
|
348
378
|
perspective?: ClientPerspective
|
|
349
379
|
apiHost?: string
|
|
350
380
|
/**
|
|
351
381
|
@remarks
|
|
352
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
382
|
+
* 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}
|
|
353
383
|
*/
|
|
354
384
|
apiVersion?: string
|
|
355
385
|
proxy?: string
|
|
@@ -574,6 +604,18 @@ export declare type CreateAction = {
|
|
|
574
604
|
/** @public */
|
|
575
605
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
576
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Instruction to create a new document
|
|
609
|
+
* @beta
|
|
610
|
+
*/
|
|
611
|
+
declare interface CreateDocumentRequest<T extends Record<string, Any_2> = Record<string, Any_2>> {
|
|
612
|
+
createDocument: {
|
|
613
|
+
/** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
|
|
614
|
+
_id?: string
|
|
615
|
+
_type: string
|
|
616
|
+
} & SanityDocumentStub_2<T>
|
|
617
|
+
}
|
|
618
|
+
|
|
577
619
|
/** @public */
|
|
578
620
|
export declare interface CurrentSanityUser {
|
|
579
621
|
id: string
|
|
@@ -725,6 +767,19 @@ export declare type DisconnectEvent = {
|
|
|
725
767
|
reason: string
|
|
726
768
|
}
|
|
727
769
|
|
|
770
|
+
/**
|
|
771
|
+
*
|
|
772
|
+
* Includes a LLM-friendly version of the document in the instruction
|
|
773
|
+
* @beta
|
|
774
|
+
* */
|
|
775
|
+
declare interface DocumentInstructionParam {
|
|
776
|
+
type: 'document'
|
|
777
|
+
/**
|
|
778
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
779
|
+
*/
|
|
780
|
+
documentId?: string
|
|
781
|
+
}
|
|
782
|
+
|
|
728
783
|
/**
|
|
729
784
|
* Modifies an existing draft document.
|
|
730
785
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -767,6 +822,14 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
767
822
|
*/
|
|
768
823
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
769
824
|
|
|
825
|
+
/**
|
|
826
|
+
* Instruction for an existing document.
|
|
827
|
+
* @beta
|
|
828
|
+
*/
|
|
829
|
+
declare interface ExistingDocumentRequest {
|
|
830
|
+
documentId: string
|
|
831
|
+
}
|
|
832
|
+
|
|
770
833
|
/** @public */
|
|
771
834
|
export declare type FilterDefault = (props: {
|
|
772
835
|
/**
|
|
@@ -893,6 +956,143 @@ export declare type InsertPatch =
|
|
|
893
956
|
items: Any[]
|
|
894
957
|
}
|
|
895
958
|
|
|
959
|
+
/** @beta */
|
|
960
|
+
export declare type InstructAsyncInstruction<
|
|
961
|
+
T extends Record<string, Any_2> = Record<string, Any_2>,
|
|
962
|
+
> = (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Async
|
|
963
|
+
|
|
964
|
+
/** @beta */
|
|
965
|
+
export declare interface InstructConstantInstructionParam {
|
|
966
|
+
type: 'constant'
|
|
967
|
+
value: string
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
*
|
|
972
|
+
* Includes a LLM-friendly version of the field value in the instruction
|
|
973
|
+
* @beta
|
|
974
|
+
* */
|
|
975
|
+
export declare interface InstructFieldInstructionParam {
|
|
976
|
+
type: 'field'
|
|
977
|
+
/**
|
|
978
|
+
* Examples: 'title', 'array[_key=="key"].field'
|
|
979
|
+
*/
|
|
980
|
+
path: string
|
|
981
|
+
/**
|
|
982
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
983
|
+
*/
|
|
984
|
+
documentId?: string
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Includes a LLM-friendly version of GROQ query result in the instruction
|
|
989
|
+
* @beta
|
|
990
|
+
* */
|
|
991
|
+
export declare interface InstructGroqInstructionParam {
|
|
992
|
+
type: 'groq'
|
|
993
|
+
query: string
|
|
994
|
+
params?: Record<string, string>
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/** @beta */
|
|
998
|
+
export declare type InstructInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
|
|
999
|
+
| InstructSyncInstruction<T>
|
|
1000
|
+
| InstructAsyncInstruction<T>
|
|
1001
|
+
|
|
1002
|
+
/** @beta */
|
|
1003
|
+
export declare type InstructInstructionParam =
|
|
1004
|
+
| string
|
|
1005
|
+
| InstructConstantInstructionParam
|
|
1006
|
+
| InstructFieldInstructionParam
|
|
1007
|
+
| DocumentInstructionParam
|
|
1008
|
+
| InstructGroqInstructionParam
|
|
1009
|
+
|
|
1010
|
+
/** @beta */
|
|
1011
|
+
export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
|
|
1012
|
+
|
|
1013
|
+
declare interface InstructRequestBase {
|
|
1014
|
+
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
1015
|
+
schemaId: string
|
|
1016
|
+
/** string template using $variable – more on this below under "Dynamic instruction" */
|
|
1017
|
+
instruction: string
|
|
1018
|
+
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
1019
|
+
instructionParams?: InstructInstructionParams
|
|
1020
|
+
/**
|
|
1021
|
+
* Optional document path output target for the instruction.
|
|
1022
|
+
* When provided, the instruction will apply to this path in the document and its children.
|
|
1023
|
+
*
|
|
1024
|
+
* ## Examples
|
|
1025
|
+
* - `path: 'title'` will output to the title field in the document
|
|
1026
|
+
* - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
|
|
1027
|
+
*/
|
|
1028
|
+
path?: string
|
|
1029
|
+
/**
|
|
1030
|
+
* Controls sub-paths in the document that can be output to.
|
|
1031
|
+
*
|
|
1032
|
+
* The string-paths are relative to the `path` param
|
|
1033
|
+
*
|
|
1034
|
+
* Note: these path strings are less strictly validated than the `path` param itself:
|
|
1035
|
+
* if an relative-path does not exist or is invalid, it will be silently ignored.
|
|
1036
|
+
*
|
|
1037
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1038
|
+
* @see InstructRequestBase#outputTypes
|
|
1039
|
+
*/
|
|
1040
|
+
relativeOutputPaths?:
|
|
1041
|
+
| {
|
|
1042
|
+
include: string[]
|
|
1043
|
+
}
|
|
1044
|
+
| {
|
|
1045
|
+
exclude: string[]
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Controls which types the instruction is allowed to output to.
|
|
1049
|
+
*
|
|
1050
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1051
|
+
* @see InstructRequestBase#conditionalPaths
|
|
1052
|
+
*/
|
|
1053
|
+
outputTypes?:
|
|
1054
|
+
| {
|
|
1055
|
+
include: string[]
|
|
1056
|
+
}
|
|
1057
|
+
| {
|
|
1058
|
+
exclude: string[]
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
|
|
1062
|
+
*
|
|
1063
|
+
* By default, AI Instruct will not output to conditional `readOnly` and `hidden` fields,
|
|
1064
|
+
* ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
|
|
1065
|
+
*
|
|
1066
|
+
* `conditionalPaths` param allows setting the default conditional value for
|
|
1067
|
+
* `hidden` and `readOnly` to false,
|
|
1068
|
+
* or individually set `hidden` and `readOnly` state for individual document paths.
|
|
1069
|
+
*
|
|
1070
|
+
*
|
|
1071
|
+
* Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Instruct,
|
|
1072
|
+
* and cannot be changed via conditionalPaths.
|
|
1073
|
+
*
|
|
1074
|
+
* conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
|
|
1075
|
+
*
|
|
1076
|
+
* @see InstructRequestBase#relativeOutputPaths
|
|
1077
|
+
* @see InstructRequestBase#outputTypes
|
|
1078
|
+
*/
|
|
1079
|
+
conditionalPaths?: {
|
|
1080
|
+
defaultReadOnly?: boolean
|
|
1081
|
+
defaultHidden?: boolean
|
|
1082
|
+
paths?: {
|
|
1083
|
+
/** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
|
|
1084
|
+
path: string
|
|
1085
|
+
readOnly: boolean
|
|
1086
|
+
hidden: boolean
|
|
1087
|
+
}[]
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/** @beta */
|
|
1092
|
+
export declare type InstructSyncInstruction<
|
|
1093
|
+
T extends Record<string, Any_2> = Record<string, Any_2>,
|
|
1094
|
+
> = (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Sync
|
|
1095
|
+
|
|
896
1096
|
/**
|
|
897
1097
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
898
1098
|
*
|
|
@@ -964,7 +1164,7 @@ export declare interface ListenOptions {
|
|
|
964
1164
|
includePreviousRevision?: boolean
|
|
965
1165
|
/**
|
|
966
1166
|
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
967
|
-
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/
|
|
1167
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
|
|
968
1168
|
* If you need events from drafts and versions, set this to `true`.
|
|
969
1169
|
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
970
1170
|
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
@@ -1253,6 +1453,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1253
1453
|
[key: string]: Any
|
|
1254
1454
|
}
|
|
1255
1455
|
|
|
1456
|
+
/** @public */
|
|
1457
|
+
declare class ObservableAiClient {
|
|
1458
|
+
#private
|
|
1459
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1460
|
+
instruct(request: InstructAsyncInstruction): Observable<{
|
|
1461
|
+
_id: string
|
|
1462
|
+
}>
|
|
1463
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
1464
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
1465
|
+
): Observable<IdentifiedSanityDocumentStub & DocumentShape>
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1256
1468
|
/** @internal */
|
|
1257
1469
|
export declare class ObservableAssetsClient {
|
|
1258
1470
|
#private
|
|
@@ -1430,6 +1642,7 @@ export declare class ObservableSanityClient {
|
|
|
1430
1642
|
live: LiveClient
|
|
1431
1643
|
projects: ObservableProjectsClient
|
|
1432
1644
|
users: ObservableUsersClient
|
|
1645
|
+
ai: ObservableAiClient
|
|
1433
1646
|
/**
|
|
1434
1647
|
* Instance properties
|
|
1435
1648
|
*/
|
|
@@ -2349,6 +2562,7 @@ export declare class SanityClient {
|
|
|
2349
2562
|
live: LiveClient
|
|
2350
2563
|
projects: ProjectsClient
|
|
2351
2564
|
users: UsersClient
|
|
2565
|
+
ai: AiClient
|
|
2352
2566
|
/**
|
|
2353
2567
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2354
2568
|
*/
|
|
@@ -2887,6 +3101,13 @@ export declare type SanityDocumentStub<T extends Record<string, Any> = Record<st
|
|
|
2887
3101
|
_type: string
|
|
2888
3102
|
}
|
|
2889
3103
|
|
|
3104
|
+
/** @public */
|
|
3105
|
+
declare type SanityDocumentStub_2<T extends Record<string, Any_2> = Record<string, Any_2>> = {
|
|
3106
|
+
[P in keyof T]: T[P]
|
|
3107
|
+
} & {
|
|
3108
|
+
_type: string
|
|
3109
|
+
}
|
|
3110
|
+
|
|
2890
3111
|
/** @internal */
|
|
2891
3112
|
export declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
2892
3113
|
metadata: {
|
|
@@ -3063,6 +3284,29 @@ export {StudioBaseUrl}
|
|
|
3063
3284
|
|
|
3064
3285
|
export {StudioUrl}
|
|
3065
3286
|
|
|
3287
|
+
declare interface Sync {
|
|
3288
|
+
/**
|
|
3289
|
+
* By default, skipWrite: false.
|
|
3290
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3291
|
+
*
|
|
3292
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3293
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3294
|
+
*
|
|
3295
|
+
* skipWrite: true is incompatible with async: true,
|
|
3296
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3297
|
+
*/
|
|
3298
|
+
skipWrite?: boolean
|
|
3299
|
+
/**
|
|
3300
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3301
|
+
* The instruction operation will carry on in the background.
|
|
3302
|
+
*
|
|
3303
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3304
|
+
*
|
|
3305
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3306
|
+
*/
|
|
3307
|
+
async?: false
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3066
3310
|
/** @public */
|
|
3067
3311
|
export declare type SyncTag = `s1:${string}`
|
|
3068
3312
|
|