@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.d.cts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type {Any as Any_2} from '@sanity/client'
|
|
1
2
|
import type {ContentSourceMapDocuments as ContentSourceMapDocuments_2} from '@sanity/client/csm'
|
|
2
3
|
import {ContentSourceMapParsedPath} from '@sanity/client/csm'
|
|
3
4
|
import {ContentSourceMapParsedPathKeyedSegment} from '@sanity/client/csm'
|
|
4
5
|
import {Observable} from 'rxjs'
|
|
5
6
|
import {Requester} from 'get-it'
|
|
6
7
|
import type {ResolveStudioUrl} from '@sanity/client/csm'
|
|
8
|
+
import type {SanityDocumentStub as SanityDocumentStub_2} from '@sanity/client'
|
|
7
9
|
import {StudioBaseRoute} from '@sanity/client/csm'
|
|
8
10
|
import {StudioBaseUrl} from '@sanity/client/csm'
|
|
9
11
|
import {StudioUrl} from '@sanity/client/csm'
|
|
@@ -39,6 +41,18 @@ export declare interface ActionErrorItem {
|
|
|
39
41
|
index: number
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
/** @public */
|
|
45
|
+
declare class AiClient {
|
|
46
|
+
#private
|
|
47
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
48
|
+
instruct(request: InstructAsyncInstruction): Promise<{
|
|
49
|
+
_id: string
|
|
50
|
+
}>
|
|
51
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
52
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
53
|
+
): Promise<IdentifiedSanityDocumentStub & DocumentShape>
|
|
54
|
+
}
|
|
55
|
+
|
|
42
56
|
/** @internal */
|
|
43
57
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
44
58
|
returnFirst: false
|
|
@@ -116,6 +130,18 @@ export declare class AssetsClient {
|
|
|
116
130
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
117
131
|
}
|
|
118
132
|
|
|
133
|
+
declare interface Async {
|
|
134
|
+
/**
|
|
135
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
136
|
+
* The instruction operation will carry on in the background.
|
|
137
|
+
*
|
|
138
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
139
|
+
*
|
|
140
|
+
* async: true is incompatible with skipWrite, as async: true does not return the resulting document
|
|
141
|
+
*/
|
|
142
|
+
async: true
|
|
143
|
+
}
|
|
144
|
+
|
|
119
145
|
/** @internal */
|
|
120
146
|
export declare type AttributeSet = {
|
|
121
147
|
[key: string]: Any
|
|
@@ -342,14 +368,14 @@ export declare interface ClientConfig {
|
|
|
342
368
|
/**
|
|
343
369
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
344
370
|
* @remarks
|
|
345
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
371
|
+
* 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
372
|
* @defaultValue 'published'
|
|
347
373
|
*/
|
|
348
374
|
perspective?: ClientPerspective
|
|
349
375
|
apiHost?: string
|
|
350
376
|
/**
|
|
351
377
|
@remarks
|
|
352
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
378
|
+
* 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
379
|
*/
|
|
354
380
|
apiVersion?: string
|
|
355
381
|
proxy?: string
|
|
@@ -573,11 +599,23 @@ export declare type CreateAction = {
|
|
|
573
599
|
|
|
574
600
|
/**
|
|
575
601
|
* @remarks
|
|
576
|
-
* As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
602
|
+
* As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
577
603
|
* @public
|
|
578
604
|
*/
|
|
579
605
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
580
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
|
+
|
|
581
619
|
/** @public */
|
|
582
620
|
export declare interface CurrentSanityUser {
|
|
583
621
|
id: string
|
|
@@ -729,6 +767,19 @@ export declare type DisconnectEvent = {
|
|
|
729
767
|
reason: string
|
|
730
768
|
}
|
|
731
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
|
+
|
|
732
783
|
/**
|
|
733
784
|
* Modifies an existing draft document.
|
|
734
785
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -771,6 +822,14 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
771
822
|
*/
|
|
772
823
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
773
824
|
|
|
825
|
+
/**
|
|
826
|
+
* Instruction for an existing document.
|
|
827
|
+
* @beta
|
|
828
|
+
*/
|
|
829
|
+
declare interface ExistingDocumentRequest {
|
|
830
|
+
documentId: string
|
|
831
|
+
}
|
|
832
|
+
|
|
774
833
|
/** @public */
|
|
775
834
|
export declare type FilterDefault = (props: {
|
|
776
835
|
/**
|
|
@@ -897,6 +956,143 @@ export declare type InsertPatch =
|
|
|
897
956
|
items: Any[]
|
|
898
957
|
}
|
|
899
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
|
+
|
|
900
1096
|
/**
|
|
901
1097
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
902
1098
|
*
|
|
@@ -968,7 +1164,7 @@ export declare interface ListenOptions {
|
|
|
968
1164
|
includePreviousRevision?: boolean
|
|
969
1165
|
/**
|
|
970
1166
|
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
971
|
-
* 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})
|
|
972
1168
|
* If you need events from drafts and versions, set this to `true`.
|
|
973
1169
|
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
974
1170
|
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
@@ -1257,6 +1453,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1257
1453
|
[key: string]: Any
|
|
1258
1454
|
}
|
|
1259
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
|
+
|
|
1260
1468
|
/** @internal */
|
|
1261
1469
|
export declare class ObservableAssetsClient {
|
|
1262
1470
|
#private
|
|
@@ -1434,6 +1642,7 @@ export declare class ObservableSanityClient {
|
|
|
1434
1642
|
live: LiveClient
|
|
1435
1643
|
projects: ObservableProjectsClient
|
|
1436
1644
|
users: ObservableUsersClient
|
|
1645
|
+
ai: ObservableAiClient
|
|
1437
1646
|
/**
|
|
1438
1647
|
* Instance properties
|
|
1439
1648
|
*/
|
|
@@ -2353,6 +2562,7 @@ export declare class SanityClient {
|
|
|
2353
2562
|
live: LiveClient
|
|
2354
2563
|
projects: ProjectsClient
|
|
2355
2564
|
users: UsersClient
|
|
2565
|
+
ai: AiClient
|
|
2356
2566
|
/**
|
|
2357
2567
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2358
2568
|
*/
|
|
@@ -3067,6 +3277,29 @@ export {StudioBaseUrl}
|
|
|
3067
3277
|
|
|
3068
3278
|
export {StudioUrl}
|
|
3069
3279
|
|
|
3280
|
+
declare interface Sync {
|
|
3281
|
+
/**
|
|
3282
|
+
* By default, skipWrite: false.
|
|
3283
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3284
|
+
*
|
|
3285
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3286
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3287
|
+
*
|
|
3288
|
+
* skipWrite: true is incompatible with async: true,
|
|
3289
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3290
|
+
*/
|
|
3291
|
+
skipWrite?: boolean
|
|
3292
|
+
/**
|
|
3293
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3294
|
+
* The instruction operation will carry on in the background.
|
|
3295
|
+
*
|
|
3296
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3297
|
+
*
|
|
3298
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3299
|
+
*/
|
|
3300
|
+
async?: false
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3070
3303
|
/** @public */
|
|
3071
3304
|
export declare type SyncTag = `s1:${string}`
|
|
3072
3305
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type {Any as Any_2} from '@sanity/client'
|
|
1
2
|
import type {ContentSourceMapDocuments as ContentSourceMapDocuments_2} from '@sanity/client/csm'
|
|
2
3
|
import {ContentSourceMapParsedPath} from '@sanity/client/csm'
|
|
3
4
|
import {ContentSourceMapParsedPathKeyedSegment} from '@sanity/client/csm'
|
|
4
5
|
import {Observable} from 'rxjs'
|
|
5
6
|
import {Requester} from 'get-it'
|
|
6
7
|
import type {ResolveStudioUrl} from '@sanity/client/csm'
|
|
8
|
+
import type {SanityDocumentStub as SanityDocumentStub_2} from '@sanity/client'
|
|
7
9
|
import {StudioBaseRoute} from '@sanity/client/csm'
|
|
8
10
|
import {StudioBaseUrl} from '@sanity/client/csm'
|
|
9
11
|
import {StudioUrl} from '@sanity/client/csm'
|
|
@@ -39,6 +41,18 @@ export declare interface ActionErrorItem {
|
|
|
39
41
|
index: number
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
/** @public */
|
|
45
|
+
declare class AiClient {
|
|
46
|
+
#private
|
|
47
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
48
|
+
instruct(request: InstructAsyncInstruction): Promise<{
|
|
49
|
+
_id: string
|
|
50
|
+
}>
|
|
51
|
+
instruct<DocumentShape extends Record<string, Any>>(
|
|
52
|
+
request: InstructSyncInstruction<DocumentShape>,
|
|
53
|
+
): Promise<IdentifiedSanityDocumentStub & DocumentShape>
|
|
54
|
+
}
|
|
55
|
+
|
|
42
56
|
/** @internal */
|
|
43
57
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
44
58
|
returnFirst: false
|
|
@@ -116,6 +130,18 @@ export declare class AssetsClient {
|
|
|
116
130
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
117
131
|
}
|
|
118
132
|
|
|
133
|
+
declare interface Async {
|
|
134
|
+
/**
|
|
135
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
136
|
+
* The instruction operation will carry on in the background.
|
|
137
|
+
*
|
|
138
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
139
|
+
*
|
|
140
|
+
* async: true is incompatible with skipWrite, as async: true does not return the resulting document
|
|
141
|
+
*/
|
|
142
|
+
async: true
|
|
143
|
+
}
|
|
144
|
+
|
|
119
145
|
/** @internal */
|
|
120
146
|
export declare type AttributeSet = {
|
|
121
147
|
[key: string]: Any
|
|
@@ -342,14 +368,14 @@ export declare interface ClientConfig {
|
|
|
342
368
|
/**
|
|
343
369
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
344
370
|
* @remarks
|
|
345
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
371
|
+
* 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
372
|
* @defaultValue 'published'
|
|
347
373
|
*/
|
|
348
374
|
perspective?: ClientPerspective
|
|
349
375
|
apiHost?: string
|
|
350
376
|
/**
|
|
351
377
|
@remarks
|
|
352
|
-
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
378
|
+
* 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
379
|
*/
|
|
354
380
|
apiVersion?: string
|
|
355
381
|
proxy?: string
|
|
@@ -573,11 +599,23 @@ export declare type CreateAction = {
|
|
|
573
599
|
|
|
574
600
|
/**
|
|
575
601
|
* @remarks
|
|
576
|
-
* As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/
|
|
602
|
+
* As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
577
603
|
* @public
|
|
578
604
|
*/
|
|
579
605
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
580
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
|
+
|
|
581
619
|
/** @public */
|
|
582
620
|
export declare interface CurrentSanityUser {
|
|
583
621
|
id: string
|
|
@@ -729,6 +767,19 @@ export declare type DisconnectEvent = {
|
|
|
729
767
|
reason: string
|
|
730
768
|
}
|
|
731
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
|
+
|
|
732
783
|
/**
|
|
733
784
|
* Modifies an existing draft document.
|
|
734
785
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -771,6 +822,14 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
771
822
|
*/
|
|
772
823
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
773
824
|
|
|
825
|
+
/**
|
|
826
|
+
* Instruction for an existing document.
|
|
827
|
+
* @beta
|
|
828
|
+
*/
|
|
829
|
+
declare interface ExistingDocumentRequest {
|
|
830
|
+
documentId: string
|
|
831
|
+
}
|
|
832
|
+
|
|
774
833
|
/** @public */
|
|
775
834
|
export declare type FilterDefault = (props: {
|
|
776
835
|
/**
|
|
@@ -897,6 +956,143 @@ export declare type InsertPatch =
|
|
|
897
956
|
items: Any[]
|
|
898
957
|
}
|
|
899
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
|
+
|
|
900
1096
|
/**
|
|
901
1097
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
902
1098
|
*
|
|
@@ -968,7 +1164,7 @@ export declare interface ListenOptions {
|
|
|
968
1164
|
includePreviousRevision?: boolean
|
|
969
1165
|
/**
|
|
970
1166
|
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
971
|
-
* 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})
|
|
972
1168
|
* If you need events from drafts and versions, set this to `true`.
|
|
973
1169
|
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
974
1170
|
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
@@ -1257,6 +1453,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1257
1453
|
[key: string]: Any
|
|
1258
1454
|
}
|
|
1259
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
|
+
|
|
1260
1468
|
/** @internal */
|
|
1261
1469
|
export declare class ObservableAssetsClient {
|
|
1262
1470
|
#private
|
|
@@ -1434,6 +1642,7 @@ export declare class ObservableSanityClient {
|
|
|
1434
1642
|
live: LiveClient
|
|
1435
1643
|
projects: ObservableProjectsClient
|
|
1436
1644
|
users: ObservableUsersClient
|
|
1645
|
+
ai: ObservableAiClient
|
|
1437
1646
|
/**
|
|
1438
1647
|
* Instance properties
|
|
1439
1648
|
*/
|
|
@@ -2353,6 +2562,7 @@ export declare class SanityClient {
|
|
|
2353
2562
|
live: LiveClient
|
|
2354
2563
|
projects: ProjectsClient
|
|
2355
2564
|
users: UsersClient
|
|
2565
|
+
ai: AiClient
|
|
2356
2566
|
/**
|
|
2357
2567
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2358
2568
|
*/
|
|
@@ -3067,6 +3277,29 @@ export {StudioBaseUrl}
|
|
|
3067
3277
|
|
|
3068
3278
|
export {StudioUrl}
|
|
3069
3279
|
|
|
3280
|
+
declare interface Sync {
|
|
3281
|
+
/**
|
|
3282
|
+
* By default, skipWrite: false.
|
|
3283
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3284
|
+
*
|
|
3285
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3286
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3287
|
+
*
|
|
3288
|
+
* skipWrite: true is incompatible with async: true,
|
|
3289
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3290
|
+
*/
|
|
3291
|
+
skipWrite?: boolean
|
|
3292
|
+
/**
|
|
3293
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3294
|
+
* The instruction operation will carry on in the background.
|
|
3295
|
+
*
|
|
3296
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3297
|
+
*
|
|
3298
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3299
|
+
*/
|
|
3300
|
+
async?: false
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3070
3303
|
/** @public */
|
|
3071
3304
|
export declare type SyncTag = `s1:${string}`
|
|
3072
3305
|
|