@sanity/client 6.28.3-instruct.0 → 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 +48 -55
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +157 -153
- package/dist/index.browser.d.ts +157 -153
- package/dist/index.browser.js +48 -55
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +43 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -153
- package/dist/index.d.ts +157 -153
- package/dist/index.js +43 -43
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +159 -160
- package/dist/stega.browser.d.ts +159 -160
- package/dist/stega.d.cts +159 -160
- package/dist/stega.d.ts +159 -160
- package/package.json +20 -20
- package/src/SanityClient.ts +5 -5
- package/src/{assist/AssistClient.ts → ai/AiClient.ts} +18 -12
- package/src/{assist → ai}/types.ts +30 -27
- package/src/config.ts +9 -18
- package/src/data/listen.ts +1 -1
- package/src/http/requestOptions.ts +1 -1
- package/src/types.ts +9 -9
- package/src/warnings.ts +5 -0
- package/umd/sanityClient.js +55 -60
- package/umd/sanityClient.min.js +2 -2
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
|
|
@@ -122,110 +134,6 @@ export declare class AssetsClient {
|
|
|
122
134
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
123
135
|
}
|
|
124
136
|
|
|
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
137
|
declare interface Async {
|
|
230
138
|
/**
|
|
231
139
|
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
@@ -577,12 +485,6 @@ export declare class ConnectionFailedError extends Error {
|
|
|
577
485
|
readonly name = 'ConnectionFailedError'
|
|
578
486
|
}
|
|
579
487
|
|
|
580
|
-
/** @beta */
|
|
581
|
-
export declare interface ConstantInstructionParam {
|
|
582
|
-
type: 'constant'
|
|
583
|
-
value: string
|
|
584
|
-
}
|
|
585
|
-
|
|
586
488
|
/** @public */
|
|
587
489
|
export declare interface ContentSourceMap {
|
|
588
490
|
mappings: ContentSourceMapMappings
|
|
@@ -928,23 +830,6 @@ declare interface ExistingDocumentRequest {
|
|
|
928
830
|
documentId: string
|
|
929
831
|
}
|
|
930
832
|
|
|
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
|
-
|
|
948
833
|
/** @public */
|
|
949
834
|
export declare type FilterDefault = (props: {
|
|
950
835
|
/**
|
|
@@ -1011,13 +896,6 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
|
|
|
1011
896
|
returnDocuments?: true
|
|
1012
897
|
}
|
|
1013
898
|
|
|
1014
|
-
/** @beta */
|
|
1015
|
-
export declare interface GroqInstructionParam {
|
|
1016
|
-
type: 'groq'
|
|
1017
|
-
query: string
|
|
1018
|
-
params?: Record<string, string>
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
899
|
/** @public */
|
|
1022
900
|
export declare type HttpRequest = {
|
|
1023
901
|
(options: RequestOptions, requester: Requester): ReturnType<Requester>
|
|
@@ -1079,15 +957,141 @@ export declare type InsertPatch =
|
|
|
1079
957
|
}
|
|
1080
958
|
|
|
1081
959
|
/** @beta */
|
|
1082
|
-
export declare type
|
|
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 =
|
|
1083
1004
|
| string
|
|
1084
|
-
|
|
|
1085
|
-
|
|
|
1005
|
+
| InstructConstantInstructionParam
|
|
1006
|
+
| InstructFieldInstructionParam
|
|
1086
1007
|
| DocumentInstructionParam
|
|
1087
|
-
|
|
|
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
|
+
}
|
|
1088
1090
|
|
|
1089
1091
|
/** @beta */
|
|
1090
|
-
export declare type
|
|
1092
|
+
export declare type InstructSyncInstruction<
|
|
1093
|
+
T extends Record<string, Any_2> = Record<string, Any_2>,
|
|
1094
|
+
> = (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Sync
|
|
1091
1095
|
|
|
1092
1096
|
/**
|
|
1093
1097
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
@@ -1449,6 +1453,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1449
1453
|
[key: string]: Any
|
|
1450
1454
|
}
|
|
1451
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
|
+
|
|
1452
1468
|
/** @internal */
|
|
1453
1469
|
export declare class ObservableAssetsClient {
|
|
1454
1470
|
#private
|
|
@@ -1503,18 +1519,6 @@ export declare class ObservableAssetsClient {
|
|
|
1503
1519
|
>
|
|
1504
1520
|
}
|
|
1505
1521
|
|
|
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
|
-
|
|
1518
1522
|
/** @internal */
|
|
1519
1523
|
export declare class ObservableDatasetsClient {
|
|
1520
1524
|
#private
|
|
@@ -1638,7 +1642,7 @@ export declare class ObservableSanityClient {
|
|
|
1638
1642
|
live: LiveClient
|
|
1639
1643
|
projects: ObservableProjectsClient
|
|
1640
1644
|
users: ObservableUsersClient
|
|
1641
|
-
|
|
1645
|
+
ai: ObservableAiClient
|
|
1642
1646
|
/**
|
|
1643
1647
|
* Instance properties
|
|
1644
1648
|
*/
|
|
@@ -2558,7 +2562,7 @@ export declare class SanityClient {
|
|
|
2558
2562
|
live: LiveClient
|
|
2559
2563
|
projects: ProjectsClient
|
|
2560
2564
|
users: UsersClient
|
|
2561
|
-
|
|
2565
|
+
ai: AiClient
|
|
2562
2566
|
/**
|
|
2563
2567
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2564
2568
|
*/
|
package/dist/index.browser.js
CHANGED
|
@@ -180,6 +180,9 @@ const createWarningPrinter = (message) => (
|
|
|
180
180
|
`See ${generateHelpUrl(
|
|
181
181
|
"js-client-browser-token"
|
|
182
182
|
)} for more information and how to hide this warning.`
|
|
183
|
+
]), printCredentialedTokenWarning = createWarningPrinter([
|
|
184
|
+
"You have configured Sanity client to use a token, but also provided `withCredentials: true`.",
|
|
185
|
+
"This is no longer supported - only token will be used - remove `withCredentials: true`."
|
|
183
186
|
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
184
187
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
185
188
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
@@ -198,21 +201,11 @@ function validateApiVersion(apiVersion) {
|
|
|
198
201
|
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
199
202
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
200
203
|
}
|
|
201
|
-
const VALID_PERSPECTIVE = /^[a-z0-9_]+$/i;
|
|
202
204
|
function validateApiPerspective(perspective) {
|
|
203
|
-
if (Array.isArray(perspective) && perspective.includes("raw"))
|
|
205
|
+
if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes("raw"))
|
|
204
206
|
throw new TypeError(
|
|
205
207
|
'Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives'
|
|
206
208
|
);
|
|
207
|
-
const invalid = (Array.isArray(perspective) ? perspective : [perspective]).filter(
|
|
208
|
-
(perspectiveName) => typeof perspectiveName != "string" || !VALID_PERSPECTIVE.test(perspectiveName)
|
|
209
|
-
);
|
|
210
|
-
if (invalid.length > 0) {
|
|
211
|
-
const formatted = invalid.map((v) => JSON.stringify(v));
|
|
212
|
-
throw new TypeError(
|
|
213
|
-
`Invalid API perspective value${invalid.length === 1 ? "" : "s"}: ${formatted.join(", ")}, expected \`published\`, \`drafts\`, \`raw\` or a release identifier string`
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
209
|
}
|
|
217
210
|
const initConfig = (config, prevConfig) => {
|
|
218
211
|
const specifiedConfig = {
|
|
@@ -250,8 +243,8 @@ const initConfig = (config, prevConfig) => {
|
|
|
250
243
|
throw new Error(
|
|
251
244
|
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
252
245
|
);
|
|
253
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
254
|
-
|
|
246
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
|
|
247
|
+
newConfig.withCredentials && hasToken && (printCredentialedTokenWarning(), newConfig.withCredentials = !1), isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== !0 ? printBrowserTokenWarning() : typeof newConfig.useCdn > "u" && printCdnWarning(), projectBased && projectId(newConfig.projectId), newConfig.dataset && dataset(newConfig.dataset), "requestTagPrefix" in newConfig && (newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0), newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, ""), newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost, newConfig.useCdn === !0 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
255
248
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
256
249
|
return newConfig.useProjectHostname ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), newConfig;
|
|
257
250
|
};
|
|
@@ -699,7 +692,7 @@ const projectHeader = "X-Sanity-Project-ID";
|
|
|
699
692
|
function requestOptions(config, overrides = {}) {
|
|
700
693
|
const headers = {}, token = overrides.token || config.token;
|
|
701
694
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
702
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
695
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
703
696
|
return Object.assign({}, overrides, {
|
|
704
697
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
705
698
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -922,6 +915,42 @@ function _createAbortError(signal) {
|
|
|
922
915
|
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
923
916
|
return error.name = "AbortError", error;
|
|
924
917
|
}
|
|
918
|
+
function _instruct(client, httpRequest, request) {
|
|
919
|
+
const dataset2 = hasDataset(client.config());
|
|
920
|
+
return _request(client, httpRequest, {
|
|
921
|
+
method: "POST",
|
|
922
|
+
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
923
|
+
body: request
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
class ObservableAiClient {
|
|
927
|
+
#client;
|
|
928
|
+
#httpRequest;
|
|
929
|
+
constructor(client, httpRequest) {
|
|
930
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Run an ad-hoc instruction for a target document.
|
|
934
|
+
* @param request instruction request
|
|
935
|
+
*/
|
|
936
|
+
instruct(request) {
|
|
937
|
+
return _instruct(this.#client, this.#httpRequest, request);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
class AiClient {
|
|
941
|
+
#client;
|
|
942
|
+
#httpRequest;
|
|
943
|
+
constructor(client, httpRequest) {
|
|
944
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Run an ad-hoc instruction for a target document.
|
|
948
|
+
* @param request instruction request
|
|
949
|
+
*/
|
|
950
|
+
instruct(request) {
|
|
951
|
+
return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
952
|
+
}
|
|
953
|
+
}
|
|
925
954
|
class ObservableAssetsClient {
|
|
926
955
|
#client;
|
|
927
956
|
#httpRequest;
|
|
@@ -981,42 +1010,6 @@ function optionsFromFile(opts, file) {
|
|
|
981
1010
|
opts
|
|
982
1011
|
);
|
|
983
1012
|
}
|
|
984
|
-
function _instruct(client, httpRequest, request) {
|
|
985
|
-
const dataset2 = hasDataset(client.config());
|
|
986
|
-
return _request(client, httpRequest, {
|
|
987
|
-
method: "POST",
|
|
988
|
-
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
989
|
-
body: request
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
class ObservableAssistClient {
|
|
993
|
-
#client;
|
|
994
|
-
#httpRequest;
|
|
995
|
-
constructor(client, httpRequest) {
|
|
996
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
* Run an ad-hoc instruction for a target document.
|
|
1000
|
-
* @param request instruction request
|
|
1001
|
-
*/
|
|
1002
|
-
instruct(request) {
|
|
1003
|
-
return _instruct(this.#client, this.#httpRequest, request);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
class AssistClient {
|
|
1007
|
-
#client;
|
|
1008
|
-
#httpRequest;
|
|
1009
|
-
constructor(client, httpRequest) {
|
|
1010
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Run an ad-hoc instruction for a target document.
|
|
1014
|
-
* @param request instruction request
|
|
1015
|
-
*/
|
|
1016
|
-
instruct(request) {
|
|
1017
|
-
return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
1013
|
var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = typeof obj[prop] > "u" ? defaults2[prop] : obj[prop], target), {});
|
|
1021
1014
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => import("@sanity/eventsource")).pipe(
|
|
1022
1015
|
map(({ default: EventSource2 }) => EventSource2),
|
|
@@ -1045,7 +1038,7 @@ function _listen(query, params, opts = {}) {
|
|
|
1045
1038
|
if (uri.length > MAX_URL_LENGTH)
|
|
1046
1039
|
return throwError(() => new Error("Query too large for listener"));
|
|
1047
1040
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
1048
|
-
return
|
|
1041
|
+
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
1049
1042
|
Authorization: `Bearer ${token}`
|
|
1050
1043
|
}), connectEventSource(() => (
|
|
1051
1044
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -1352,7 +1345,7 @@ class ObservableSanityClient {
|
|
|
1352
1345
|
live;
|
|
1353
1346
|
projects;
|
|
1354
1347
|
users;
|
|
1355
|
-
|
|
1348
|
+
ai;
|
|
1356
1349
|
/**
|
|
1357
1350
|
* Private properties
|
|
1358
1351
|
*/
|
|
@@ -1363,7 +1356,7 @@ class ObservableSanityClient {
|
|
|
1363
1356
|
*/
|
|
1364
1357
|
listen = _listen;
|
|
1365
1358
|
constructor(httpRequest, config = defaultConfig) {
|
|
1366
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.
|
|
1359
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.ai = new ObservableAiClient(this, this.#httpRequest);
|
|
1367
1360
|
}
|
|
1368
1361
|
/**
|
|
1369
1362
|
* Clone the client - returns a new instance
|
|
@@ -1502,7 +1495,7 @@ class SanityClient {
|
|
|
1502
1495
|
live;
|
|
1503
1496
|
projects;
|
|
1504
1497
|
users;
|
|
1505
|
-
|
|
1498
|
+
ai;
|
|
1506
1499
|
/**
|
|
1507
1500
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1508
1501
|
*/
|
|
@@ -1517,7 +1510,7 @@ class SanityClient {
|
|
|
1517
1510
|
*/
|
|
1518
1511
|
listen = _listen;
|
|
1519
1512
|
constructor(httpRequest, config = defaultConfig) {
|
|
1520
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.
|
|
1513
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.ai = new AiClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1521
1514
|
}
|
|
1522
1515
|
/**
|
|
1523
1516
|
* Clone the client - returns a new instance
|