@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.js
CHANGED
|
@@ -555,7 +555,7 @@ const projectHeader = "X-Sanity-Project-ID";
|
|
|
555
555
|
function requestOptions(config, overrides = {}) {
|
|
556
556
|
const headers2 = {}, token = overrides.token || config.token;
|
|
557
557
|
token && (headers2.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers2[projectHeader] = config.projectId);
|
|
558
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
558
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
559
559
|
return Object.assign({}, overrides, {
|
|
560
560
|
headers: Object.assign({}, headers2, overrides.headers || {}),
|
|
561
561
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -778,6 +778,42 @@ function _createAbortError(signal) {
|
|
|
778
778
|
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
779
779
|
return error.name = "AbortError", error;
|
|
780
780
|
}
|
|
781
|
+
function _instruct(client, httpRequest, request) {
|
|
782
|
+
const dataset2 = hasDataset(client.config());
|
|
783
|
+
return _request(client, httpRequest, {
|
|
784
|
+
method: "POST",
|
|
785
|
+
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
786
|
+
body: request
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
class ObservableAiClient {
|
|
790
|
+
#client;
|
|
791
|
+
#httpRequest;
|
|
792
|
+
constructor(client, httpRequest) {
|
|
793
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Run an ad-hoc instruction for a target document.
|
|
797
|
+
* @param request instruction request
|
|
798
|
+
*/
|
|
799
|
+
instruct(request) {
|
|
800
|
+
return _instruct(this.#client, this.#httpRequest, request);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
class AiClient {
|
|
804
|
+
#client;
|
|
805
|
+
#httpRequest;
|
|
806
|
+
constructor(client, httpRequest) {
|
|
807
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Run an ad-hoc instruction for a target document.
|
|
811
|
+
* @param request instruction request
|
|
812
|
+
*/
|
|
813
|
+
instruct(request) {
|
|
814
|
+
return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
815
|
+
}
|
|
816
|
+
}
|
|
781
817
|
class ObservableAssetsClient {
|
|
782
818
|
#client;
|
|
783
819
|
#httpRequest;
|
|
@@ -865,7 +901,7 @@ function _listen(query, params, opts = {}) {
|
|
|
865
901
|
if (uri.length > MAX_URL_LENGTH)
|
|
866
902
|
return throwError(() => new Error("Query too large for listener"));
|
|
867
903
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
868
|
-
return
|
|
904
|
+
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
869
905
|
Authorization: `Bearer ${token}`
|
|
870
906
|
}), connectEventSource(() => (
|
|
871
907
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -898,7 +934,10 @@ function _shareReplayLatest(config) {
|
|
|
898
934
|
}),
|
|
899
935
|
share(shareConfig)
|
|
900
936
|
), emitLatest = new Observable((subscriber) => {
|
|
901
|
-
emitted && subscriber.next(
|
|
937
|
+
emitted && subscriber.next(
|
|
938
|
+
// this cast is safe because of the emitted check which asserts that we got T from the source
|
|
939
|
+
latest
|
|
940
|
+
), subscriber.complete();
|
|
902
941
|
});
|
|
903
942
|
return merge(wrapped, emitLatest);
|
|
904
943
|
};
|
|
@@ -1169,6 +1208,7 @@ class ObservableSanityClient {
|
|
|
1169
1208
|
live;
|
|
1170
1209
|
projects;
|
|
1171
1210
|
users;
|
|
1211
|
+
ai;
|
|
1172
1212
|
/**
|
|
1173
1213
|
* Private properties
|
|
1174
1214
|
*/
|
|
@@ -1179,7 +1219,7 @@ class ObservableSanityClient {
|
|
|
1179
1219
|
*/
|
|
1180
1220
|
listen = _listen;
|
|
1181
1221
|
constructor(httpRequest, config = defaultConfig) {
|
|
1182
|
-
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);
|
|
1222
|
+
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);
|
|
1183
1223
|
}
|
|
1184
1224
|
/**
|
|
1185
1225
|
* Clone the client - returns a new instance
|
|
@@ -1318,6 +1358,7 @@ class SanityClient {
|
|
|
1318
1358
|
live;
|
|
1319
1359
|
projects;
|
|
1320
1360
|
users;
|
|
1361
|
+
ai;
|
|
1321
1362
|
/**
|
|
1322
1363
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1323
1364
|
*/
|
|
@@ -1332,7 +1373,7 @@ class SanityClient {
|
|
|
1332
1373
|
*/
|
|
1333
1374
|
listen = _listen;
|
|
1334
1375
|
constructor(httpRequest, config = defaultConfig) {
|
|
1335
|
-
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.observable = new ObservableSanityClient(httpRequest, config);
|
|
1376
|
+
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);
|
|
1336
1377
|
}
|
|
1337
1378
|
/**
|
|
1338
1379
|
* Clone the client - returns a new instance
|
|
@@ -1508,7 +1549,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1508
1549
|
return printNoDefaultExport(), createClient2(config);
|
|
1509
1550
|
};
|
|
1510
1551
|
}
|
|
1511
|
-
var name = "@sanity/client", version = "6.28.
|
|
1552
|
+
var name = "@sanity/client", version = "6.28.3-instruct.1";
|
|
1512
1553
|
const middleware = [
|
|
1513
1554
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1514
1555
|
headers({ "User-Agent": `${name} ${version}` }),
|