@sanity/client 6.28.1 → 6.28.3-instruct.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/dist/index.browser.cjs +44 -3
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +250 -10
- package/dist/index.browser.d.ts +250 -10
- package/dist/index.browser.js +44 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +45 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +240 -11
- package/dist/index.d.ts +240 -11
- package/dist/index.js +45 -4
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +244 -10
- package/dist/stega.browser.d.ts +244 -10
- package/dist/stega.d.cts +244 -10
- package/dist/stega.d.ts +244 -10
- package/package.json +1 -1
- package/src/SanityClient.ts +5 -1
- package/src/assist/AssistClient.ts +87 -0
- package/src/assist/types.ts +203 -0
- package/src/index.ts +1 -1
- package/src/types.ts +20 -10
- package/src/util/shareReplayLatest.ts +4 -1
- package/umd/sanityClient.js +44 -3
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -57,6 +57,12 @@ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
|
|
|
57
57
|
*/
|
|
58
58
|
export declare type Any = any
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
declare type Any_2 = any
|
|
65
|
+
|
|
60
66
|
/** @internal */
|
|
61
67
|
export declare interface ApiError {
|
|
62
68
|
error: string
|
|
@@ -116,6 +122,122 @@ export declare class AssetsClient {
|
|
|
116
122
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
117
123
|
}
|
|
118
124
|
|
|
125
|
+
/** @beta */
|
|
126
|
+
export declare type AssistAsyncInstruction<
|
|
127
|
+
T extends Record<string, Any_2> = Record<string, Any_2>,
|
|
128
|
+
> = (ExistingDocumentRequest | CreateDocumentRequest<T>) & AssistRequestBase & Async
|
|
129
|
+
|
|
130
|
+
/** @public */
|
|
131
|
+
declare class AssistClient {
|
|
132
|
+
#private
|
|
133
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
134
|
+
instruct(request: AssistAsyncInstruction): Promise<{
|
|
135
|
+
_id: string
|
|
136
|
+
}>
|
|
137
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
138
|
+
request: AssistSyncInstruction<DocumentShape>,
|
|
139
|
+
): Promise<IdentifiedSanityDocumentStub & DocumentShape>
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @beta */
|
|
143
|
+
export declare type AssistInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
|
|
144
|
+
| AssistSyncInstruction<T>
|
|
145
|
+
| AssistAsyncInstruction<T>
|
|
146
|
+
|
|
147
|
+
declare interface AssistRequestBase {
|
|
148
|
+
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
149
|
+
schemaId: string
|
|
150
|
+
/** string template using $variable – more on this below under "Dynamic instruction" */
|
|
151
|
+
instruction: string
|
|
152
|
+
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
153
|
+
instructionParams?: InstructionParams
|
|
154
|
+
/**
|
|
155
|
+
* Optional document path output target for the instruction.
|
|
156
|
+
* When provided, the instruction will apply to this path in the document and its children.
|
|
157
|
+
*
|
|
158
|
+
* ## Examples
|
|
159
|
+
* - `path: 'title'` will output to the title field in the document
|
|
160
|
+
* - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
|
|
161
|
+
*/
|
|
162
|
+
path?: string
|
|
163
|
+
/**
|
|
164
|
+
* Controls sub-paths in the document that can be output to.
|
|
165
|
+
*
|
|
166
|
+
* The string-paths are relative to the `path` param
|
|
167
|
+
*
|
|
168
|
+
* Note: these path strings are less strictly validated than the `path` param itself:
|
|
169
|
+
* if an relative-path does not exist or is invalid, it will be silently ignored.
|
|
170
|
+
*
|
|
171
|
+
* @see AssistRequestBase#conditionalPaths
|
|
172
|
+
* @see AssistRequestBase#outputTypes
|
|
173
|
+
*/
|
|
174
|
+
relativeOutputPaths?:
|
|
175
|
+
| {
|
|
176
|
+
include: string[]
|
|
177
|
+
}
|
|
178
|
+
| {
|
|
179
|
+
exclude: string[]
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Controls which types the instruction is allowed to output to.
|
|
183
|
+
*
|
|
184
|
+
* @see AssistRequestBase#relativeOutputPaths
|
|
185
|
+
* @see AssistRequestBase#conditionalPaths
|
|
186
|
+
*/
|
|
187
|
+
outputTypes?:
|
|
188
|
+
| {
|
|
189
|
+
include: string[]
|
|
190
|
+
}
|
|
191
|
+
| {
|
|
192
|
+
exclude: string[]
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
|
|
196
|
+
*
|
|
197
|
+
* By default, AI Assist will not output to conditional `readOnly` and `hidden` fields,
|
|
198
|
+
* ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
|
|
199
|
+
*
|
|
200
|
+
* `conditionalPaths` param allows setting the default conditional value for
|
|
201
|
+
* `hidden` and `readOnly` to false,
|
|
202
|
+
* or individually set `hidden` and `readOnly` state for individual document paths.
|
|
203
|
+
*
|
|
204
|
+
*
|
|
205
|
+
* Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Assist,
|
|
206
|
+
* and cannot be changed via conditionalPaths.
|
|
207
|
+
*
|
|
208
|
+
* conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
|
|
209
|
+
*
|
|
210
|
+
* @see AssistRequestBase#relativeOutputPaths
|
|
211
|
+
* @see AssistRequestBase#outputTypes
|
|
212
|
+
*/
|
|
213
|
+
conditionalPaths?: {
|
|
214
|
+
defaultReadOnly?: boolean
|
|
215
|
+
defaultHidden?: boolean
|
|
216
|
+
paths?: {
|
|
217
|
+
/** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
|
|
218
|
+
path: string
|
|
219
|
+
readOnly: boolean
|
|
220
|
+
hidden: boolean
|
|
221
|
+
}[]
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** @beta */
|
|
226
|
+
export declare type AssistSyncInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
|
|
227
|
+
(ExistingDocumentRequest | CreateDocumentRequest<T>) & AssistRequestBase & Sync
|
|
228
|
+
|
|
229
|
+
declare interface Async {
|
|
230
|
+
/**
|
|
231
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
232
|
+
* The instruction operation will carry on in the background.
|
|
233
|
+
*
|
|
234
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
235
|
+
*
|
|
236
|
+
* async: true is incompatible with skipWrite, as async: true does not return the resulting document
|
|
237
|
+
*/
|
|
238
|
+
async: true
|
|
239
|
+
}
|
|
240
|
+
|
|
119
241
|
/** @internal */
|
|
120
242
|
export declare type AttributeSet = {
|
|
121
243
|
[key: string]: Any
|
|
@@ -342,14 +464,14 @@ export declare interface ClientConfig {
|
|
|
342
464
|
/**
|
|
343
465
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
344
466
|
* @remarks
|
|
345
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
467
|
+
* 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
468
|
* @defaultValue 'published'
|
|
347
469
|
*/
|
|
348
470
|
perspective?: ClientPerspective
|
|
349
471
|
apiHost?: string
|
|
350
472
|
/**
|
|
351
473
|
@remarks
|
|
352
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
474
|
+
* 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
475
|
*/
|
|
354
476
|
apiVersion?: string
|
|
355
477
|
proxy?: string
|
|
@@ -455,6 +577,12 @@ export declare class ConnectionFailedError extends Error {
|
|
|
455
577
|
readonly name = 'ConnectionFailedError'
|
|
456
578
|
}
|
|
457
579
|
|
|
580
|
+
/** @beta */
|
|
581
|
+
export declare interface ConstantInstructionParam {
|
|
582
|
+
type: 'constant'
|
|
583
|
+
value: string
|
|
584
|
+
}
|
|
585
|
+
|
|
458
586
|
/** @public */
|
|
459
587
|
export declare interface ContentSourceMap {
|
|
460
588
|
mappings: ContentSourceMapMappings
|
|
@@ -574,7 +702,19 @@ export declare type CreateAction = {
|
|
|
574
702
|
/** @public */
|
|
575
703
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
576
704
|
|
|
577
|
-
/**
|
|
705
|
+
/**
|
|
706
|
+
* Instruction to create a new document
|
|
707
|
+
* @beta
|
|
708
|
+
*/
|
|
709
|
+
declare interface CreateDocumentRequest<T extends Record<string, Any_2> = Record<string, Any_2>> {
|
|
710
|
+
createDocument: {
|
|
711
|
+
/** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
|
|
712
|
+
_id?: string
|
|
713
|
+
_type: string
|
|
714
|
+
} & SanityDocumentStub_2<T>
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** @public */
|
|
578
718
|
export declare interface CurrentSanityUser {
|
|
579
719
|
id: string
|
|
580
720
|
name: string
|
|
@@ -583,10 +723,10 @@ export declare interface CurrentSanityUser {
|
|
|
583
723
|
role: string
|
|
584
724
|
}
|
|
585
725
|
|
|
586
|
-
/** @
|
|
726
|
+
/** @public */
|
|
587
727
|
export declare type DatasetAclMode = 'public' | 'private' | 'custom'
|
|
588
728
|
|
|
589
|
-
/** @
|
|
729
|
+
/** @public */
|
|
590
730
|
export declare type DatasetResponse = {
|
|
591
731
|
datasetName: string
|
|
592
732
|
aclMode: DatasetAclMode
|
|
@@ -634,7 +774,7 @@ export declare class DatasetsClient {
|
|
|
634
774
|
list(): Promise<DatasetsResponse>
|
|
635
775
|
}
|
|
636
776
|
|
|
637
|
-
/** @
|
|
777
|
+
/** @public */
|
|
638
778
|
export declare type DatasetsResponse = {
|
|
639
779
|
name: string
|
|
640
780
|
aclMode: DatasetAclMode
|
|
@@ -725,6 +865,19 @@ export declare type DisconnectEvent = {
|
|
|
725
865
|
reason: string
|
|
726
866
|
}
|
|
727
867
|
|
|
868
|
+
/**
|
|
869
|
+
*
|
|
870
|
+
* Includes a LLM-friendly version of the document in the instruction
|
|
871
|
+
* @beta
|
|
872
|
+
* */
|
|
873
|
+
declare interface DocumentInstructionParam {
|
|
874
|
+
type: 'document'
|
|
875
|
+
/**
|
|
876
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
877
|
+
*/
|
|
878
|
+
documentId?: string
|
|
879
|
+
}
|
|
880
|
+
|
|
728
881
|
/**
|
|
729
882
|
* Modifies an existing draft document.
|
|
730
883
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -767,6 +920,31 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
767
920
|
*/
|
|
768
921
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
769
922
|
|
|
923
|
+
/**
|
|
924
|
+
* Instruction for an existing document.
|
|
925
|
+
* @beta
|
|
926
|
+
*/
|
|
927
|
+
declare interface ExistingDocumentRequest {
|
|
928
|
+
documentId: string
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
*
|
|
933
|
+
* Includes a LLM-friendly version of the field value in the instruction
|
|
934
|
+
* @beta
|
|
935
|
+
* */
|
|
936
|
+
export declare interface FieldInstructionParam {
|
|
937
|
+
type: 'field'
|
|
938
|
+
/**
|
|
939
|
+
* Examples: 'title', 'array[_key=="key"].field
|
|
940
|
+
*/
|
|
941
|
+
path: string
|
|
942
|
+
/**
|
|
943
|
+
* If omitted, implicitly uses the documentId of the instruction target
|
|
944
|
+
*/
|
|
945
|
+
documentId?: string
|
|
946
|
+
}
|
|
947
|
+
|
|
770
948
|
/** @public */
|
|
771
949
|
export declare type FilterDefault = (props: {
|
|
772
950
|
/**
|
|
@@ -833,6 +1011,13 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
|
|
|
833
1011
|
returnDocuments?: true
|
|
834
1012
|
}
|
|
835
1013
|
|
|
1014
|
+
/** @beta */
|
|
1015
|
+
export declare interface GroqInstructionParam {
|
|
1016
|
+
type: 'groq'
|
|
1017
|
+
query: string
|
|
1018
|
+
params?: Record<string, string>
|
|
1019
|
+
}
|
|
1020
|
+
|
|
836
1021
|
/** @public */
|
|
837
1022
|
export declare type HttpRequest = {
|
|
838
1023
|
(options: RequestOptions, requester: Requester): ReturnType<Requester>
|
|
@@ -893,6 +1078,17 @@ export declare type InsertPatch =
|
|
|
893
1078
|
items: Any[]
|
|
894
1079
|
}
|
|
895
1080
|
|
|
1081
|
+
/** @beta */
|
|
1082
|
+
export declare type InstructionParam =
|
|
1083
|
+
| string
|
|
1084
|
+
| ConstantInstructionParam
|
|
1085
|
+
| FieldInstructionParam
|
|
1086
|
+
| DocumentInstructionParam
|
|
1087
|
+
| GroqInstructionParam
|
|
1088
|
+
|
|
1089
|
+
/** @beta */
|
|
1090
|
+
export declare type InstructionParams = Record<string, InstructionParam>
|
|
1091
|
+
|
|
896
1092
|
/**
|
|
897
1093
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
898
1094
|
*
|
|
@@ -964,7 +1160,7 @@ export declare interface ListenOptions {
|
|
|
964
1160
|
includePreviousRevision?: boolean
|
|
965
1161
|
/**
|
|
966
1162
|
* 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/
|
|
1163
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
|
|
968
1164
|
* If you need events from drafts and versions, set this to `true`.
|
|
969
1165
|
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
970
1166
|
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
@@ -1307,6 +1503,18 @@ export declare class ObservableAssetsClient {
|
|
|
1307
1503
|
>
|
|
1308
1504
|
}
|
|
1309
1505
|
|
|
1506
|
+
/** @public */
|
|
1507
|
+
declare class ObservableAssistClient {
|
|
1508
|
+
#private
|
|
1509
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1510
|
+
instruct(request: AssistAsyncInstruction): Observable<{
|
|
1511
|
+
_id: string
|
|
1512
|
+
}>
|
|
1513
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
1514
|
+
request: AssistSyncInstruction<DocumentShape>,
|
|
1515
|
+
): Observable<IdentifiedSanityDocumentStub & DocumentShape>
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1310
1518
|
/** @internal */
|
|
1311
1519
|
export declare class ObservableDatasetsClient {
|
|
1312
1520
|
#private
|
|
@@ -1430,6 +1638,7 @@ export declare class ObservableSanityClient {
|
|
|
1430
1638
|
live: LiveClient
|
|
1431
1639
|
projects: ObservableProjectsClient
|
|
1432
1640
|
users: ObservableUsersClient
|
|
1641
|
+
assist: ObservableAssistClient
|
|
1433
1642
|
/**
|
|
1434
1643
|
* Instance properties
|
|
1435
1644
|
*/
|
|
@@ -2349,6 +2558,7 @@ export declare class SanityClient {
|
|
|
2349
2558
|
live: LiveClient
|
|
2350
2559
|
projects: ProjectsClient
|
|
2351
2560
|
users: UsersClient
|
|
2561
|
+
assist: AssistClient
|
|
2352
2562
|
/**
|
|
2353
2563
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2354
2564
|
*/
|
|
@@ -2887,6 +3097,13 @@ export declare type SanityDocumentStub<T extends Record<string, Any> = Record<st
|
|
|
2887
3097
|
_type: string
|
|
2888
3098
|
}
|
|
2889
3099
|
|
|
3100
|
+
/** @public */
|
|
3101
|
+
declare type SanityDocumentStub_2<T extends Record<string, Any_2> = Record<string, Any_2>> = {
|
|
3102
|
+
[P in keyof T]: T[P]
|
|
3103
|
+
} & {
|
|
3104
|
+
_type: string
|
|
3105
|
+
}
|
|
3106
|
+
|
|
2890
3107
|
/** @internal */
|
|
2891
3108
|
export declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
2892
3109
|
metadata: {
|
|
@@ -2930,7 +3147,7 @@ export declare interface SanityImagePalette {
|
|
|
2930
3147
|
title: string
|
|
2931
3148
|
}
|
|
2932
3149
|
|
|
2933
|
-
/** @
|
|
3150
|
+
/** @public */
|
|
2934
3151
|
export declare interface SanityProject {
|
|
2935
3152
|
id: string
|
|
2936
3153
|
displayName: string
|
|
@@ -2958,7 +3175,7 @@ export declare interface SanityProject {
|
|
|
2958
3175
|
}
|
|
2959
3176
|
}
|
|
2960
3177
|
|
|
2961
|
-
/** @
|
|
3178
|
+
/** @public */
|
|
2962
3179
|
export declare interface SanityProjectMember {
|
|
2963
3180
|
id: string
|
|
2964
3181
|
role: string
|
|
@@ -2974,7 +3191,7 @@ export declare interface SanityReference {
|
|
|
2974
3191
|
_ref: string
|
|
2975
3192
|
}
|
|
2976
3193
|
|
|
2977
|
-
/** @
|
|
3194
|
+
/** @public */
|
|
2978
3195
|
export declare interface SanityUser {
|
|
2979
3196
|
id: string
|
|
2980
3197
|
projectId: string
|
|
@@ -3063,6 +3280,29 @@ export {StudioBaseUrl}
|
|
|
3063
3280
|
|
|
3064
3281
|
export {StudioUrl}
|
|
3065
3282
|
|
|
3283
|
+
declare interface Sync {
|
|
3284
|
+
/**
|
|
3285
|
+
* By default, skipWrite: false.
|
|
3286
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3287
|
+
*
|
|
3288
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3289
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3290
|
+
*
|
|
3291
|
+
* skipWrite: true is incompatible with async: true,
|
|
3292
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3293
|
+
*/
|
|
3294
|
+
skipWrite?: boolean
|
|
3295
|
+
/**
|
|
3296
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3297
|
+
* The instruction operation will carry on in the background.
|
|
3298
|
+
*
|
|
3299
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3300
|
+
*
|
|
3301
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3302
|
+
*/
|
|
3303
|
+
async?: false
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3066
3306
|
/** @public */
|
|
3067
3307
|
export declare type SyncTag = `s1:${string}`
|
|
3068
3308
|
|