@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.cjs
CHANGED
|
@@ -570,7 +570,7 @@ const projectHeader = "X-Sanity-Project-ID";
|
|
|
570
570
|
function requestOptions(config2, overrides = {}) {
|
|
571
571
|
const headers = {}, token = overrides.token || config2.token;
|
|
572
572
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config2.useProjectHostname && config2.projectId && (headers[projectHeader] = config2.projectId);
|
|
573
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config2.
|
|
573
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config2.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config2.timeout : overrides.timeout;
|
|
574
574
|
return Object.assign({}, overrides, {
|
|
575
575
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
576
576
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -795,6 +795,42 @@ function _createAbortError(signal) {
|
|
|
795
795
|
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
796
796
|
return error.name = "AbortError", error;
|
|
797
797
|
}
|
|
798
|
+
function _instruct(client, httpRequest, request) {
|
|
799
|
+
const dataset = config.hasDataset(client.config());
|
|
800
|
+
return _request(client, httpRequest, {
|
|
801
|
+
method: "POST",
|
|
802
|
+
uri: `/assist/tasks/instruct/${dataset}`,
|
|
803
|
+
body: request
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
class ObservableAiClient {
|
|
807
|
+
#client;
|
|
808
|
+
#httpRequest;
|
|
809
|
+
constructor(client, httpRequest) {
|
|
810
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Run an ad-hoc instruction for a target document.
|
|
814
|
+
* @param request instruction request
|
|
815
|
+
*/
|
|
816
|
+
instruct(request) {
|
|
817
|
+
return _instruct(this.#client, this.#httpRequest, request);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
class AiClient {
|
|
821
|
+
#client;
|
|
822
|
+
#httpRequest;
|
|
823
|
+
constructor(client, httpRequest) {
|
|
824
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Run an ad-hoc instruction for a target document.
|
|
828
|
+
* @param request instruction request
|
|
829
|
+
*/
|
|
830
|
+
instruct(request) {
|
|
831
|
+
return rxjs.lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
832
|
+
}
|
|
833
|
+
}
|
|
798
834
|
class ObservableAssetsClient {
|
|
799
835
|
#client;
|
|
800
836
|
#httpRequest;
|
|
@@ -882,7 +918,7 @@ function _listen(query, params, opts = {}) {
|
|
|
882
918
|
if (uri.length > MAX_URL_LENGTH)
|
|
883
919
|
return rxjs.throwError(() => new Error("Query too large for listener"));
|
|
884
920
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
885
|
-
return
|
|
921
|
+
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
886
922
|
Authorization: `Bearer ${token}`
|
|
887
923
|
}), connectEventSource(() => (
|
|
888
924
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -915,7 +951,10 @@ function _shareReplayLatest(config2) {
|
|
|
915
951
|
}),
|
|
916
952
|
rxjs.share(shareConfig)
|
|
917
953
|
), emitLatest = new rxjs.Observable((subscriber) => {
|
|
918
|
-
emitted && subscriber.next(
|
|
954
|
+
emitted && subscriber.next(
|
|
955
|
+
// this cast is safe because of the emitted check which asserts that we got T from the source
|
|
956
|
+
latest
|
|
957
|
+
), subscriber.complete();
|
|
919
958
|
});
|
|
920
959
|
return rxjs.merge(wrapped, emitLatest);
|
|
921
960
|
};
|
|
@@ -1186,6 +1225,7 @@ class ObservableSanityClient {
|
|
|
1186
1225
|
live;
|
|
1187
1226
|
projects;
|
|
1188
1227
|
users;
|
|
1228
|
+
ai;
|
|
1189
1229
|
/**
|
|
1190
1230
|
* Private properties
|
|
1191
1231
|
*/
|
|
@@ -1196,7 +1236,7 @@ class ObservableSanityClient {
|
|
|
1196
1236
|
*/
|
|
1197
1237
|
listen = _listen;
|
|
1198
1238
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1199
|
-
this.config(config$1), 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);
|
|
1239
|
+
this.config(config$1), 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);
|
|
1200
1240
|
}
|
|
1201
1241
|
/**
|
|
1202
1242
|
* Clone the client - returns a new instance
|
|
@@ -1335,6 +1375,7 @@ class SanityClient {
|
|
|
1335
1375
|
live;
|
|
1336
1376
|
projects;
|
|
1337
1377
|
users;
|
|
1378
|
+
ai;
|
|
1338
1379
|
/**
|
|
1339
1380
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1340
1381
|
*/
|
|
@@ -1349,7 +1390,7 @@ class SanityClient {
|
|
|
1349
1390
|
*/
|
|
1350
1391
|
listen = _listen;
|
|
1351
1392
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1352
|
-
this.config(config$1), 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$1);
|
|
1393
|
+
this.config(config$1), 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$1);
|
|
1353
1394
|
}
|
|
1354
1395
|
/**
|
|
1355
1396
|
* Clone the client - returns a new instance
|
|
@@ -1525,7 +1566,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1525
1566
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
1526
1567
|
};
|
|
1527
1568
|
}
|
|
1528
|
-
var name = "@sanity/client", version = "6.28.
|
|
1569
|
+
var name = "@sanity/client", version = "6.28.3-instruct.1";
|
|
1529
1570
|
const middleware = [
|
|
1530
1571
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1531
1572
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|