@sanity/client 6.28.3-instruct.0 → 6.28.3-instruct.2

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/stega.d.ts CHANGED
@@ -110,117 +110,6 @@ export declare class AssetsClient {
110
110
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
111
111
  }
112
112
 
113
- /** @beta */
114
- export declare type AssistAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
115
- | ExistingDocumentRequest
116
- | CreateDocumentRequest<T>
117
- ) &
118
- AssistRequestBase &
119
- Async
120
-
121
- /** @public */
122
- declare class AssistClient {
123
- #private
124
- constructor(client: SanityClient, httpRequest: HttpRequest)
125
- instruct(request: AssistAsyncInstruction): Promise<{
126
- _id: string
127
- }>
128
- instruct<DocumentShape extends Record<string, Any>>(
129
- request: AssistSyncInstruction<DocumentShape>,
130
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
131
- }
132
-
133
- /** @beta */
134
- export declare type AssistInstruction<T extends Record<string, Any> = Record<string, Any>> =
135
- | AssistSyncInstruction<T>
136
- | AssistAsyncInstruction<T>
137
-
138
- declare interface AssistRequestBase {
139
- /** schemaId as reported by sanity deploy / sanity schema store */
140
- schemaId: string
141
- /** string template using $variable – more on this below under "Dynamic instruction" */
142
- instruction: string
143
- /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
144
- instructionParams?: InstructionParams
145
- /**
146
- * Optional document path output target for the instruction.
147
- * When provided, the instruction will apply to this path in the document and its children.
148
- *
149
- * ## Examples
150
- * - `path: 'title'` will output to the title field in the document
151
- * - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
152
- */
153
- path?: string
154
- /**
155
- * Controls sub-paths in the document that can be output to.
156
- *
157
- * The string-paths are relative to the `path` param
158
- *
159
- * Note: these path strings are less strictly validated than the `path` param itself:
160
- * if an relative-path does not exist or is invalid, it will be silently ignored.
161
- *
162
- * @see AssistRequestBase#conditionalPaths
163
- * @see AssistRequestBase#outputTypes
164
- */
165
- relativeOutputPaths?:
166
- | {
167
- include: string[]
168
- }
169
- | {
170
- exclude: string[]
171
- }
172
- /**
173
- * Controls which types the instruction is allowed to output to.
174
- *
175
- * @see AssistRequestBase#relativeOutputPaths
176
- * @see AssistRequestBase#conditionalPaths
177
- */
178
- outputTypes?:
179
- | {
180
- include: string[]
181
- }
182
- | {
183
- exclude: string[]
184
- }
185
- /**
186
- * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
187
- *
188
- * By default, AI Assist will not output to conditional `readOnly` and `hidden` fields,
189
- * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
190
- *
191
- * `conditionalPaths` param allows setting the default conditional value for
192
- * `hidden` and `readOnly` to false,
193
- * or individually set `hidden` and `readOnly` state for individual document paths.
194
- *
195
- *
196
- * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Assist,
197
- * and cannot be changed via conditionalPaths.
198
- *
199
- * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
200
- *
201
- * @see AssistRequestBase#relativeOutputPaths
202
- * @see AssistRequestBase#outputTypes
203
- */
204
- conditionalPaths?: {
205
- defaultReadOnly?: boolean
206
- defaultHidden?: boolean
207
- paths?: {
208
- /** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
209
- path: string
210
- readOnly: boolean
211
- hidden: boolean
212
- }[]
213
- }
214
- }
215
-
216
- /** @beta */
217
- export declare type AssistSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
218
- | ExistingDocumentRequest
219
- | CreateDocumentRequest<T>
220
- ) &
221
- AssistRequestBase &
222
- Sync
223
-
224
113
  declare interface Async {
225
114
  /**
226
115
  * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
@@ -578,12 +467,6 @@ export declare class ConnectionFailedError extends Error {
578
467
  readonly name = 'ConnectionFailedError'
579
468
  }
580
469
 
581
- /** @beta */
582
- export declare interface ConstantInstructionParam {
583
- type: 'constant'
584
- value: string
585
- }
586
-
587
470
  /** @public */
588
471
  export declare interface ContentSourceMap {
589
472
  mappings: ContentSourceMapMappings
@@ -1040,23 +923,6 @@ declare interface ExistingDocumentRequest {
1040
923
  documentId: string
1041
924
  }
1042
925
 
1043
- /**
1044
- *
1045
- * Includes a LLM-friendly version of the field value in the instruction
1046
- * @beta
1047
- * */
1048
- export declare interface FieldInstructionParam {
1049
- type: 'field'
1050
- /**
1051
- * Examples: 'title', 'array[_key=="key"].field
1052
- */
1053
- path: string
1054
- /**
1055
- * If omitted, implicitly uses the documentId of the instruction target
1056
- */
1057
- documentId?: string
1058
- }
1059
-
1060
926
  /** @public */
1061
927
  export declare type FilterDefault = (props: {
1062
928
  /**
@@ -1172,13 +1038,6 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1172
1038
  returnDocuments?: true
1173
1039
  }
1174
1040
 
1175
- /** @beta */
1176
- export declare interface GroqInstructionParam {
1177
- type: 'groq'
1178
- query: string
1179
- params?: Record<string, string>
1180
- }
1181
-
1182
1041
  /** @public */
1183
1042
  export declare type HttpRequest = {
1184
1043
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1250,15 +1109,143 @@ export declare type InsertPatch =
1250
1109
  }
1251
1110
 
1252
1111
  /** @beta */
1253
- export declare type InstructionParam =
1112
+ export declare type InstructAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> =
1113
+ (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Async
1114
+
1115
+ /** @beta */
1116
+ export declare interface InstructConstantInstructionParam {
1117
+ type: 'constant'
1118
+ value: string
1119
+ }
1120
+
1121
+ /**
1122
+ *
1123
+ * Includes a LLM-friendly version of the field value in the instruction
1124
+ * @beta
1125
+ * */
1126
+ export declare interface InstructFieldInstructionParam {
1127
+ type: 'field'
1128
+ /**
1129
+ * Examples: 'title', 'array[_key=="key"].field'
1130
+ */
1131
+ path: string
1132
+ /**
1133
+ * If omitted, implicitly uses the documentId of the instruction target
1134
+ */
1135
+ documentId?: string
1136
+ }
1137
+
1138
+ /**
1139
+ * Includes a LLM-friendly version of GROQ query result in the instruction
1140
+ * @beta
1141
+ * */
1142
+ export declare interface InstructGroqInstructionParam {
1143
+ type: 'groq'
1144
+ query: string
1145
+ params?: Record<string, string>
1146
+ }
1147
+
1148
+ /** @beta */
1149
+ export declare type InstructInstruction<T extends Record<string, Any> = Record<string, Any>> =
1150
+ | InstructSyncInstruction<T>
1151
+ | InstructAsyncInstruction<T>
1152
+
1153
+ /** @beta */
1154
+ export declare type InstructInstructionParam =
1254
1155
  | string
1255
- | ConstantInstructionParam
1256
- | FieldInstructionParam
1156
+ | InstructConstantInstructionParam
1157
+ | InstructFieldInstructionParam
1257
1158
  | DocumentInstructionParam
1258
- | GroqInstructionParam
1159
+ | InstructGroqInstructionParam
1259
1160
 
1260
1161
  /** @beta */
1261
- export declare type InstructionParams = Record<string, InstructionParam>
1162
+ export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
1163
+
1164
+ declare interface InstructRequestBase {
1165
+ /** schemaId as reported by sanity deploy / sanity schema store */
1166
+ schemaId: string
1167
+ /** string template using $variable – more on this below under "Dynamic instruction" */
1168
+ instruction: string
1169
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
1170
+ instructionParams?: InstructInstructionParams
1171
+ /**
1172
+ * Optional document path output target for the instruction.
1173
+ * When provided, the instruction will apply to this path in the document and its children.
1174
+ *
1175
+ * ## Examples
1176
+ * - `path: 'title'` will output to the title field in the document
1177
+ * - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
1178
+ */
1179
+ path?: string
1180
+ /**
1181
+ * Controls sub-paths in the document that can be output to.
1182
+ *
1183
+ * The string-paths are relative to the `path` param
1184
+ *
1185
+ * Note: these path strings are less strictly validated than the `path` param itself:
1186
+ * if an relative-path does not exist or is invalid, it will be silently ignored.
1187
+ *
1188
+ * @see InstructRequestBase#conditionalPaths
1189
+ * @see InstructRequestBase#outputTypes
1190
+ */
1191
+ relativeOutputPaths?:
1192
+ | {
1193
+ include: string[]
1194
+ }
1195
+ | {
1196
+ exclude: string[]
1197
+ }
1198
+ /**
1199
+ * Controls which types the instruction is allowed to output to.
1200
+ *
1201
+ * @see InstructRequestBase#relativeOutputPaths
1202
+ * @see InstructRequestBase#conditionalPaths
1203
+ */
1204
+ outputTypes?:
1205
+ | {
1206
+ include: string[]
1207
+ }
1208
+ | {
1209
+ exclude: string[]
1210
+ }
1211
+ /**
1212
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
1213
+ *
1214
+ * By default, AI Instruct will not output to conditional `readOnly` and `hidden` fields,
1215
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
1216
+ *
1217
+ * `conditionalPaths` param allows setting the default conditional value for
1218
+ * `hidden` and `readOnly` to false,
1219
+ * or individually set `hidden` and `readOnly` state for individual document paths.
1220
+ *
1221
+ *
1222
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Instruct,
1223
+ * and cannot be changed via conditionalPaths.
1224
+ *
1225
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
1226
+ *
1227
+ * @see InstructRequestBase#relativeOutputPaths
1228
+ * @see InstructRequestBase#outputTypes
1229
+ */
1230
+ conditionalPaths?: {
1231
+ defaultReadOnly?: boolean
1232
+ defaultHidden?: boolean
1233
+ paths?: {
1234
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
1235
+ path: string
1236
+ readOnly: boolean
1237
+ hidden: boolean
1238
+ }[]
1239
+ }
1240
+ }
1241
+
1242
+ /** @beta */
1243
+ export declare type InstructSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1244
+ | ExistingDocumentRequest
1245
+ | CreateDocumentRequest<T>
1246
+ ) &
1247
+ InstructRequestBase &
1248
+ Sync
1262
1249
 
1263
1250
  /**
1264
1251
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
@@ -1681,18 +1668,6 @@ export declare class ObservableAssetsClient {
1681
1668
  >
1682
1669
  }
1683
1670
 
1684
- /** @public */
1685
- declare class ObservableAssistClient {
1686
- #private
1687
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1688
- instruct(request: AssistAsyncInstruction): Observable<{
1689
- _id: string
1690
- }>
1691
- instruct<DocumentShape extends Record<string, Any>>(
1692
- request: AssistSyncInstruction<DocumentShape>,
1693
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1694
- }
1695
-
1696
1671
  /** @internal */
1697
1672
  export declare class ObservableDatasetsClient {
1698
1673
  #private
@@ -1816,7 +1791,6 @@ export declare class ObservableSanityClient {
1816
1791
  live: LiveClient
1817
1792
  projects: ObservableProjectsClient
1818
1793
  users: ObservableUsersClient
1819
- assist: ObservableAssistClient
1820
1794
  /**
1821
1795
  * Instance properties
1822
1796
  */
@@ -2311,6 +2285,12 @@ export declare class ObservableSanityClient {
2311
2285
  * @param path - Path to append after the operation
2312
2286
  */
2313
2287
  getDataUrl(operation: string, path?: string): string
2288
+ instruct(request: InstructAsyncInstruction): Observable<{
2289
+ _id: string
2290
+ }>
2291
+ instruct<DocumentShape extends Record<string, Any>>(
2292
+ request: InstructSyncInstruction<DocumentShape>,
2293
+ ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
2314
2294
  }
2315
2295
 
2316
2296
  /**
@@ -2748,7 +2728,6 @@ export declare class SanityClient {
2748
2728
  live: LiveClient
2749
2729
  projects: ProjectsClient
2750
2730
  users: UsersClient
2751
- assist: AssistClient
2752
2731
  /**
2753
2732
  * Observable version of the Sanity client, with the same configuration as the promise-based one
2754
2733
  */
@@ -3263,6 +3242,12 @@ export declare class SanityClient {
3263
3242
  * @param path - Path to append after the operation
3264
3243
  */
3265
3244
  getDataUrl(operation: string, path?: string): string
3245
+ instruct(request: InstructAsyncInstruction): Promise<{
3246
+ _id: string
3247
+ }>
3248
+ instruct<DocumentShape extends Record<string, Any>>(
3249
+ request: InstructSyncInstruction<DocumentShape>,
3250
+ ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
3266
3251
  }
3267
3252
 
3268
3253
  /** @internal */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.28.3-instruct.0",
3
+ "version": "6.28.3-instruct.2",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -125,39 +125,39 @@
125
125
  "devDependencies": {
126
126
  "@edge-runtime/types": "^4.0.0",
127
127
  "@edge-runtime/vm": "^5.0.0",
128
- "@eslint/eslintrc": "^3.2.0",
129
- "@eslint/js": "^9.20.0",
130
- "@rollup/plugin-commonjs": "^28.0.2",
131
- "@rollup/plugin-node-resolve": "^16.0.0",
128
+ "@eslint/eslintrc": "^3.3.0",
129
+ "@eslint/js": "^9.22.0",
130
+ "@rollup/plugin-commonjs": "^28.0.3",
131
+ "@rollup/plugin-node-resolve": "^16.0.1",
132
132
  "@sanity/client-latest": "npm:@sanity/client@latest",
133
- "@sanity/pkg-utils": "^7.0.4",
133
+ "@sanity/pkg-utils": "^7.1.1",
134
134
  "@types/json-diff": "^1.0.3",
135
135
  "@types/node": "^22.9.0",
136
- "@typescript-eslint/eslint-plugin": "^8.24.0",
137
- "@typescript-eslint/parser": "^8.24.0",
136
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
137
+ "@typescript-eslint/parser": "^8.26.1",
138
138
  "@vercel/stega": "0.1.2",
139
- "@vitest/coverage-v8": "3.0.5",
140
- "eslint": "^9.20.0",
141
- "eslint-config-prettier": "^10.0.1",
139
+ "@vitest/coverage-v8": "3.0.9",
140
+ "eslint": "^9.22.0",
141
+ "eslint-config-prettier": "^10.1.1",
142
142
  "eslint-formatter-compact": "^8.40.0",
143
143
  "eslint-plugin-prettier": "^5.2.3",
144
144
  "eslint-plugin-simple-import-sort": "^12.1.1",
145
145
  "faucet": "^0.0.4",
146
- "globals": "^15.14.0",
146
+ "globals": "^15.15.0",
147
147
  "happy-dom": "^12.10.3",
148
148
  "json-diff": "^1.0.6",
149
149
  "ls-engines": "^0.9.3",
150
- "msw": "^2.7.0",
151
- "next": "^15.1.7",
150
+ "msw": "^2.7.3",
151
+ "next": "^15.2.3",
152
152
  "nock": "^13.5.6",
153
- "prettier": "^3.5.0",
154
- "prettier-plugin-packagejson": "^2.5.8",
153
+ "prettier": "^3.5.3",
154
+ "prettier-plugin-packagejson": "^2.5.10",
155
155
  "rimraf": "^5.0.7",
156
- "rollup": "^4.34.6",
156
+ "rollup": "^4.36.0",
157
157
  "sse-channel": "^4.0.0",
158
- "terser": "^5.38.2",
159
- "typescript": "5.7.3",
160
- "vitest": "3.0.5"
158
+ "terser": "^5.39.0",
159
+ "typescript": "5.8.2",
160
+ "vitest": "3.0.9"
161
161
  },
162
162
  "packageManager": "npm@11.0.0",
163
163
  "engines": {
@@ -1,7 +1,6 @@
1
1
  import {lastValueFrom, Observable} from 'rxjs'
2
2
 
3
3
  import {AssetsClient, ObservableAssetsClient} from './assets/AssetsClient'
4
- import {AssistClient, ObservableAssistClient} from './assist/AssistClient'
5
4
  import {defaultConfig, initConfig} from './config'
6
5
  import * as dataMethods from './data/dataMethods'
7
6
  import {_listen} from './data/listen'
@@ -9,6 +8,7 @@ import {LiveClient} from './data/live'
9
8
  import {ObservablePatch, Patch} from './data/patch'
10
9
  import {ObservableTransaction, Transaction} from './data/transaction'
11
10
  import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient'
11
+ import {_instruct} from './instruct/instruct'
12
12
  import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClient'
13
13
  import type {
14
14
  Action,
@@ -25,6 +25,9 @@ import type {
25
25
  HttpRequest,
26
26
  IdentifiedSanityDocumentStub,
27
27
  InitializedClientConfig,
28
+ InstructAsyncInstruction,
29
+ InstructInstruction,
30
+ InstructSyncInstruction,
28
31
  MultipleActionResult,
29
32
  MultipleMutationResult,
30
33
  Mutation,
@@ -66,7 +69,6 @@ export class ObservableSanityClient {
66
69
  live: LiveClient
67
70
  projects: ObservableProjectsClient
68
71
  users: ObservableUsersClient
69
- assist: ObservableAssistClient
70
72
  /**
71
73
  * Private properties
72
74
  */
@@ -88,7 +90,6 @@ export class ObservableSanityClient {
88
90
  this.live = new LiveClient(this)
89
91
  this.projects = new ObservableProjectsClient(this, this.#httpRequest)
90
92
  this.users = new ObservableUsersClient(this, this.#httpRequest)
91
- this.assist = new ObservableAssistClient(this, this.#httpRequest)
92
93
  }
93
94
 
94
95
  /**
@@ -726,6 +727,27 @@ export class ObservableSanityClient {
726
727
  getDataUrl(operation: string, path?: string): string {
727
728
  return dataMethods._getDataUrl(this, operation, path)
728
729
  }
730
+
731
+ instruct(request: InstructAsyncInstruction): Observable<{_id: string}>
732
+
733
+ instruct<DocumentShape extends Record<string, Any>>(
734
+ request: InstructSyncInstruction<DocumentShape>,
735
+ ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
736
+
737
+ /**
738
+ * Run an ad-hoc instruction for a target document.
739
+ * @param request instruction request
740
+ */
741
+ instruct<
742
+ DocumentShape extends Record<string, Any>,
743
+ Req extends InstructInstruction<DocumentShape>,
744
+ >(
745
+ request: Req,
746
+ ): Observable<
747
+ Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
748
+ > {
749
+ return _instruct(this, this.#httpRequest, request)
750
+ }
729
751
  }
730
752
 
731
753
  /** @public */
@@ -735,7 +757,6 @@ export class SanityClient {
735
757
  live: LiveClient
736
758
  projects: ProjectsClient
737
759
  users: UsersClient
738
- assist: AssistClient
739
760
 
740
761
  /**
741
762
  * Observable version of the Sanity client, with the same configuration as the promise-based one
@@ -763,7 +784,6 @@ export class SanityClient {
763
784
  this.live = new LiveClient(this)
764
785
  this.projects = new ProjectsClient(this, this.#httpRequest)
765
786
  this.users = new UsersClient(this, this.#httpRequest)
766
- this.assist = new AssistClient(this, this.#httpRequest)
767
787
 
768
788
  this.observable = new ObservableSanityClient(httpRequest, config)
769
789
  }
@@ -1432,4 +1452,25 @@ export class SanityClient {
1432
1452
  getDataUrl(operation: string, path?: string): string {
1433
1453
  return dataMethods._getDataUrl(this, operation, path)
1434
1454
  }
1455
+
1456
+ instruct(request: InstructAsyncInstruction): Promise<{_id: string}>
1457
+
1458
+ instruct<DocumentShape extends Record<string, Any>>(
1459
+ request: InstructSyncInstruction<DocumentShape>,
1460
+ ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
1461
+
1462
+ /**
1463
+ * Run an ad-hoc instruction for a target document.
1464
+ * @param request instruction request
1465
+ */
1466
+ instruct<
1467
+ DocumentShape extends Record<string, Any>,
1468
+ Req extends InstructInstruction<DocumentShape>,
1469
+ >(
1470
+ request: Req,
1471
+ ): Promise<
1472
+ Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
1473
+ > {
1474
+ return lastValueFrom(_instruct(this, this.#httpRequest, request))
1475
+ }
1435
1476
  }
package/src/config.ts CHANGED
@@ -28,30 +28,15 @@ function validateApiVersion(apiVersion: string) {
28
28
  }
29
29
  }
30
30
 
31
- const VALID_PERSPECTIVE = /^[a-z0-9_]+$/i
32
-
33
31
  /**
34
32
  * @internal - it may have breaking changes in any release
35
33
  */
36
34
  export function validateApiPerspective(
37
35
  perspective: unknown,
38
36
  ): asserts perspective is ClientPerspective {
39
- if (Array.isArray(perspective)) {
40
- if (perspective.includes('raw')) {
41
- throw new TypeError(
42
- `Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives`,
43
- )
44
- }
45
- }
46
-
47
- const invalid = (Array.isArray(perspective) ? perspective : [perspective]).filter(
48
- (perspectiveName) =>
49
- typeof perspectiveName !== 'string' || !VALID_PERSPECTIVE.test(perspectiveName),
50
- )
51
- if (invalid.length > 0) {
52
- const formatted = invalid.map((v) => JSON.stringify(v))
37
+ if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes('raw')) {
53
38
  throw new TypeError(
54
- `Invalid API perspective value${invalid.length === 1 ? '' : 's'}: ${formatted.join(', ')}, expected \`published\`, \`drafts\`, \`raw\` or a release identifier string`,
39
+ `Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives`,
55
40
  )
56
41
  }
57
42
  }
@@ -122,7 +107,13 @@ export const initConfig = (
122
107
  const isBrowser = typeof window !== 'undefined' && window.location && window.location.hostname
123
108
  const isLocalhost = isBrowser && isLocal(window.location.hostname)
124
109
 
125
- if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
110
+ const hasToken = Boolean(newConfig.token)
111
+ if (newConfig.withCredentials && hasToken) {
112
+ warnings.printCredentialedTokenWarning()
113
+ newConfig.withCredentials = false
114
+ }
115
+
116
+ if (isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== true) {
126
117
  warnings.printBrowserTokenWarning()
127
118
  } else if (typeof newConfig.useCdn === 'undefined') {
128
119
  warnings.printCdnWarning()
@@ -84,7 +84,7 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
84
84
  const listenFor = options.events ? options.events : ['mutation']
85
85
 
86
86
  const esOptions: EventSourceInit & {headers?: Record<string, string>} = {}
87
- if (token || withCredentials) {
87
+ if (withCredentials) {
88
88
  esOptions.withCredentials = true
89
89
  }
90
90
 
@@ -18,7 +18,7 @@ export function requestOptions(config: Any, overrides: Any = {}): Omit<RequestOp
18
18
 
19
19
  const withCredentials = Boolean(
20
20
  typeof overrides.withCredentials === 'undefined'
21
- ? config.token || config.withCredentials
21
+ ? config.withCredentials
22
22
  : overrides.withCredentials,
23
23
  )
24
24
 
@@ -0,0 +1,24 @@
1
+ import {type Observable} from 'rxjs'
2
+
3
+ import {_request} from '../data/dataMethods'
4
+ import type {ObservableSanityClient, SanityClient} from '../SanityClient'
5
+ import type {Any, HttpRequest, IdentifiedSanityDocumentStub, InstructInstruction} from '../types'
6
+ import {hasDataset} from '../validators'
7
+
8
+ export function _instruct<
9
+ DocumentShape extends Record<string, Any>,
10
+ Req extends InstructInstruction<DocumentShape>,
11
+ >(
12
+ client: SanityClient | ObservableSanityClient,
13
+ httpRequest: HttpRequest,
14
+ request: Req,
15
+ ): Observable<
16
+ Req['async'] extends true ? {_id: string} : IdentifiedSanityDocumentStub & DocumentShape
17
+ > {
18
+ const dataset = hasDataset(client.config())
19
+ return _request(client, httpRequest, {
20
+ method: 'POST',
21
+ uri: `/assist/tasks/instruct/${dataset}`,
22
+ body: request,
23
+ })
24
+ }