@sanity/client 8.3.0 → 8.5.0

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.
Files changed (54) hide show
  1. package/README.md +80 -4
  2. package/dist/{browserUpload-2tz6Sdqp.js → browserUpload-C7PwCs-C.js} +6 -9
  3. package/dist/browserUpload-C7PwCs-C.js.map +1 -0
  4. package/dist/{browserUpload-CwpNx7Vl.js → browserUpload-D-2Rmfjo.js} +6 -9
  5. package/dist/browserUpload-D-2Rmfjo.js.map +1 -0
  6. package/dist/{config-3wiPP-sZ.js → config-CgJ16jET.js} +4 -2
  7. package/dist/config-CgJ16jET.js.map +1 -0
  8. package/dist/csm.js +1 -1
  9. package/dist/{dist-C9ExSk2R.js → dist-C5K_YcEU.js} +3 -2
  10. package/dist/{dist-C9ExSk2R.js.map → dist-C5K_YcEU.js.map} +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +1111 -80
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.node.d.ts +3561 -53
  15. package/dist/index.node.js +983 -30
  16. package/dist/index.node.js.map +1 -1
  17. package/dist/media-library.d.ts +1 -1
  18. package/dist/rolldown-runtime-4YWMqDIC.js +9 -0
  19. package/dist/stega.js +2 -2
  20. package/dist/{dist-Z8cIRxoB.js → stegaClean-YZRATV86.js} +19 -2
  21. package/dist/stegaClean-YZRATV86.js.map +1 -0
  22. package/dist/{stegaEncodeSourceMap-DbM2fTN4.js → stegaEncodeSourceMap-CO1HKnm2.js} +2 -2
  23. package/dist/{stegaEncodeSourceMap-DbM2fTN4.js.map → stegaEncodeSourceMap-CO1HKnm2.js.map} +1 -1
  24. package/dist/{stegaEncodeSourceMap-YR3NQ3iz.js → stegaEncodeSourceMap-Dj29aWKG.js} +2 -2
  25. package/dist/{stegaEncodeSourceMap-YR3NQ3iz.js.map → stegaEncodeSourceMap-Dj29aWKG.js.map} +1 -1
  26. package/dist/{types-0x2hPfhJ.d.ts → types-CtHEe8SF.d.ts} +3562 -54
  27. package/package.json +18 -15
  28. package/src/SanityClient.ts +183 -9
  29. package/src/agent/actions/AgentActionsClient.ts +8 -2
  30. package/src/assets/AssetsClient.ts +13 -2
  31. package/src/config.ts +1 -0
  32. package/src/context/ContextClient.ts +1006 -0
  33. package/src/context/openapi.json +5345 -0
  34. package/src/context/reads.ts +206 -0
  35. package/src/context/store.ts +100 -0
  36. package/src/context/types.gen.ts +2428 -0
  37. package/src/context/types.ts +228 -0
  38. package/src/data/dataMethods.ts +4 -1
  39. package/src/data/live.ts +1 -0
  40. package/src/datasets/DatasetsClient.ts +8 -2
  41. package/src/defineCreateClient.ts +1 -0
  42. package/src/http/browserUpload.ts +0 -12
  43. package/src/mediaLibrary/MediaLibraryVideoClient.ts +8 -2
  44. package/src/projects/ProjectsClient.ts +8 -2
  45. package/src/releases/ReleasesClient.ts +8 -2
  46. package/src/types.ts +68 -4
  47. package/src/users/UsersClient.ts +8 -2
  48. package/src/validators.ts +1 -0
  49. package/dist/browserUpload-2tz6Sdqp.js.map +0 -1
  50. package/dist/browserUpload-CwpNx7Vl.js.map +0 -1
  51. package/dist/config-3wiPP-sZ.js.map +0 -1
  52. package/dist/dist-Z8cIRxoB.js.map +0 -1
  53. package/dist/stegaClean-C18wLWau.js +0 -21
  54. package/dist/stegaClean-C18wLWau.js.map +0 -1
@@ -1,6 +1,7 @@
1
- import { t as require_dist } from "./dist-C9ExSk2R.js";
1
+ import { n as __exportAll } from "./rolldown-runtime-4YWMqDIC.js";
2
2
  import { a as ServerError, c as isHttpError, i as CorsOriginError, l as isQueryParseError, o as formatQueryParseError, r as ClientError, t as defineRequester } from "./request-SnMg7nUX.js";
3
3
  import { t as isRecord } from "./isRecord-Kfmt-nk-.js";
4
+ import { t as require_dist } from "./dist-C5K_YcEU.js";
4
5
  import { isTimeoutError } from "get-it";
5
6
  import { debug } from "get-it/middleware";
6
7
  import { Observable, catchError, concat, defer, finalize, isObservable, lastValueFrom, map, merge, mergeMap, of, share, tap, throwError, timer } from "rxjs";
@@ -66,6 +67,7 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = [
66
67
  if (id.split(".").length !== 2) throw Error("Dataset resource ID must be in the format \"project.dataset\"");
67
68
  return;
68
69
  case "dashboard":
70
+ case "knowledge-base":
69
71
  case "media-library":
70
72
  case "canvas": return;
71
73
  default: throw Error(`Unsupported resource type: ${type.toString()}`);
@@ -114,7 +116,8 @@ const initConfig = (config, prevConfig) => {
114
116
  specifiedConfig.apiVersion || printNoApiVersionSpecifiedWarning();
115
117
  let newConfig = {
116
118
  ...defaultConfig,
117
- ...specifiedConfig
119
+ ...specifiedConfig,
120
+ apiHost: specifiedConfig.apiHost ?? defaultConfig.apiHost
118
121
  };
119
122
  newConfig["~experimental_resource"] && !newConfig.resource && (printDeprecatedResourceConfigWarning(), newConfig.resource = newConfig["~experimental_resource"]);
120
123
  let resourceConfig$1 = newConfig.resource, projectBased = newConfig.useProjectHostname && !resourceConfig$1;
@@ -611,7 +614,15 @@ var BaseTransaction = class {
611
614
  ...patchOps
612
615
  } });
613
616
  }
614
- };
617
+ }, types_exports = /* @__PURE__ */ __exportAll({ possibleStoreRequestOptions: () => possibleStoreRequestOptions });
618
+ /** @internal */
619
+ const possibleStoreRequestOptions = [
620
+ "headers",
621
+ "signal",
622
+ "tag",
623
+ "timeout",
624
+ "token"
625
+ ];
615
626
  /**
616
627
  * Project the public request options (`timeout: 0` to disable,
617
628
  * `withCredentials`, `maxRedirects`, the function/object-form `fetch`, ...)
@@ -725,7 +736,7 @@ function _fetchRequest(_stega, _params, options) {
725
736
  }
726
737
  /** @internal */
727
738
  function _fetchObservable(client, httpRequest, _stega, query, _params = {}, options = {}) {
728
- return _observe(options.signal, (signal) => _fetch$1(client, httpRequest, _stega, query, _params, {
739
+ return _observe(options.signal, (signal) => _fetch$2(client, httpRequest, _stega, query, _params, {
729
740
  ...options,
730
741
  signal
731
742
  }));
@@ -735,12 +746,12 @@ function _fetchObservable(client, httpRequest, _stega, query, _params = {}, opti
735
746
  *
736
747
  * @internal
737
748
  */
738
- function _fetch$1(client, httpRequest, _stega, query, _params = {}, options = {}) {
749
+ function _fetch$2(client, httpRequest, _stega, query, _params = {}, options = {}) {
739
750
  let { stega, params, mapResponse, reqOpts } = _fetchRequest(_stega, _params, options), request = _dataRequest(client, httpRequest, "query", {
740
751
  query,
741
752
  params
742
753
  }, reqOpts);
743
- return stega.enabled ? Promise.all([request, import("./stegaEncodeSourceMap-DbM2fTN4.js")]).then(([res, { stegaEncodeSourceMap }]) => {
754
+ return stega.enabled ? Promise.all([request, import("./stegaEncodeSourceMap-CO1HKnm2.js")]).then(([res, { stegaEncodeSourceMap }]) => {
744
755
  let result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
745
756
  return mapResponse({
746
757
  ...res,
@@ -1297,6 +1308,7 @@ const resourceDataBase = (config) => {
1297
1308
  return `/projects/${segments[0]}/datasets/${segments[1]}`;
1298
1309
  }
1299
1310
  case "canvas": return `/canvases/${id}`;
1311
+ case "knowledge-base": return `/knowledge-bases/${id}`;
1300
1312
  case "media-library": return `/media-libraries/${id}`;
1301
1313
  case "dashboard": return `/dashboards/${id}`;
1302
1314
  default: throw Error(`Unsupported resource type: ${type.toString()}`);
@@ -1361,7 +1373,10 @@ function _translate(client, httpRequest, request) {
1361
1373
  body: request
1362
1374
  });
1363
1375
  }
1364
- /** @public */
1376
+ /**
1377
+ * @public
1378
+ * @inline
1379
+ */
1365
1380
  var ObservableAgentsActionClient = class {
1366
1381
  #client;
1367
1382
  #httpRequest;
@@ -1490,7 +1505,7 @@ function _upload(client, _httpRequest, assetType, body, opts = {}) {
1490
1505
  body
1491
1506
  };
1492
1507
  return typeof XMLHttpRequest < "u" ? defer(async () => {
1493
- let { uploadWithProgress } = await import("./browserUpload-2tz6Sdqp.js"), req = _prepareRequest(client, { ...baseRequest });
1508
+ let { uploadWithProgress } = await import("./browserUpload-C7PwCs-C.js"), req = _prepareRequest(client, { ...baseRequest });
1494
1509
  return uploadWithProgress({
1495
1510
  url: appendQuery(req.url, req.query),
1496
1511
  method: req.method ?? "POST",
@@ -1514,6 +1529,7 @@ function buildAssetUploadUrl(config, assetType) {
1514
1529
  switch (type) {
1515
1530
  case "dataset": throw Error("Assets are not supported for dataset resources, yet. Configure the client with `{projectId: <projectId>, dataset: <datasetId>}` instead.");
1516
1531
  case "canvas": return `/canvases/${id}/assets/${assetTypeEndpoint}`;
1532
+ case "knowledge-base": throw Error("Assets are not supported for knowledge-base resources. Use `client.context.imports` to add content instead.");
1517
1533
  case "media-library": return `/media-libraries/${id}/upload`;
1518
1534
  case "dashboard": return `/dashboards/${id}/assets/${assetTypeEndpoint}`;
1519
1535
  default: throw Error(`Unsupported resource type: ${type.toString()}`);
@@ -1600,7 +1616,7 @@ const possibleOptions = [
1600
1616
  "tag"
1601
1617
  ], defaultOptions = { includeResult: !0 };
1602
1618
  /** @public */
1603
- function _listen$1(query, params, opts = {}) {
1619
+ function _listen$2(query, params, opts = {}) {
1604
1620
  let { url, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = {
1605
1621
  ...defaults_default(opts, defaultOptions),
1606
1622
  tag
@@ -1719,7 +1735,7 @@ function _removeReaction(client, httpRequest, id, shortName, options) {
1719
1735
  return writeDocument(id, client, httpRequest, "DELETE", `${commentUrl(id)}/reactions/${encodeURIComponent(shortName)}`, void 0, options);
1720
1736
  }
1721
1737
  /** @internal */
1722
- function _fetch(client, httpRequest, query, params, options) {
1738
+ function _fetch$1(client, httpRequest, query, params, options) {
1723
1739
  let search = resourceQuery(client);
1724
1740
  return _requestObservable(client, httpRequest, {
1725
1741
  ...encodeQueryString({
@@ -1745,7 +1761,7 @@ function _fetch(client, httpRequest, query, params, options) {
1745
1761
  }).pipe(map$1((response) => response.result));
1746
1762
  }
1747
1763
  /** @internal */
1748
- function _listen(client, query, params, options) {
1764
+ function _listen$1(client, query, params, options) {
1749
1765
  let opts = options ?? {}, { requestTagPrefix } = client.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, listenOpts = pick({
1750
1766
  ...defaults_default(opts, defaultOptions),
1751
1767
  tag
@@ -1868,10 +1884,10 @@ var ObservableCollaborationCommentsClient = class {
1868
1884
  * @param options - Optional request options
1869
1885
  */
1870
1886
  fetch(query, params, options) {
1871
- return _fetch(this.#client, this.#httpRequest, query, params, options);
1887
+ return _fetch$1(this.#client, this.#httpRequest, query, params, options);
1872
1888
  }
1873
1889
  listen(query, params, options) {
1874
- return _listen(this.#client, query, params, options);
1890
+ return _listen$1(this.#client, query, params, options);
1875
1891
  }
1876
1892
  }, CollaborationCommentsClient = class {
1877
1893
  #client;
@@ -1974,12 +1990,811 @@ var ObservableCollaborationCommentsClient = class {
1974
1990
  * @param params - Optional query parameters
1975
1991
  * @param options - Optional request options
1976
1992
  */
1993
+ fetch(query, params, options) {
1994
+ return lastValueFrom(_fetch$1(this.#client, this.#httpRequest, query, params, options));
1995
+ }
1996
+ listen(query, params, options) {
1997
+ return _listen$1(this.#client, query, params, options);
1998
+ }
1999
+ };
2000
+ /** @internal */
2001
+ function _organizationId(client) {
2002
+ let organizationId = client.config().context?.organizationId;
2003
+ if (!organizationId) throw Error("`context.organizationId` must be configured to query Context documents");
2004
+ return organizationId;
2005
+ }
2006
+ function storeUrl(client, suffix) {
2007
+ return `/context/organizations/${encodeURIComponent(_organizationId(client))}/${suffix}`;
2008
+ }
2009
+ /** @internal */
2010
+ function _fetch(client, httpRequest, query, params, options) {
2011
+ let url = storeUrl(client, "query");
2012
+ return _requestObservable(client, httpRequest, {
2013
+ ...encodeQueryString({
2014
+ query,
2015
+ params
2016
+ }).length < 11264 ? {
2017
+ method: "GET",
2018
+ url: `${url}${encodeQueryString({
2019
+ query,
2020
+ params
2021
+ })}`
2022
+ } : {
2023
+ method: "POST",
2024
+ url,
2025
+ body: {
2026
+ query,
2027
+ params: params ?? {}
2028
+ }
2029
+ },
2030
+ ...pick(options || {}, possibleStoreRequestOptions)
2031
+ }).pipe(map$1((response) => response.result));
2032
+ }
2033
+ /** @internal */
2034
+ function _listen(client, query, params, options) {
2035
+ let opts = options ?? {}, { requestTagPrefix } = client.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, listenOpts = pick({
2036
+ ...defaults_default(opts, defaultOptions),
2037
+ tag
2038
+ }, possibleOptions), qs = encodeQueryString({
2039
+ query,
2040
+ params,
2041
+ options: listenOpts
2042
+ }), uri = `${client.getUrl(storeUrl(client, "listen"))}${qs}`;
2043
+ return uri.length > 14800 ? throwError(() => /* @__PURE__ */ Error("Query too large for listener")) : _connectListenEventSource(client, uri, opts.events ? opts.events : ["mutation"]);
2044
+ }
2045
+ const ENTRY_TYPE = "sanity.context.entry", ISSUE_TYPE = "sanity.context.issue", MCP_TYPE = "sanity.context.mcp";
2046
+ function _one(client, httpRequest, query, params, options) {
2047
+ return lastValueFrom(_fetch(client, httpRequest, query, params, options));
2048
+ }
2049
+ /**
2050
+ * Drain every page of a `(_createdAt, _id)`-keyset read. Termination keys on
2051
+ * the raw page length before anything looks at the rows: a short page means
2052
+ * the store had nothing more to give, and filtering must never shorten a
2053
+ * full page into a false stop.
2054
+ */
2055
+ async function _drainByCreatedAt(client, httpRequest, filter, params, options) {
2056
+ let all = [], cursor;
2057
+ for (;;) {
2058
+ let query = `*[${cursor ? `${filter} && (_createdAt > \$c || (_createdAt == \$c && _id > \$i))` : filter}] | order(_createdAt asc, _id asc) [0...200]`, page = await lastValueFrom(_fetch(client, httpRequest, query, cursor ? {
2059
+ ...params,
2060
+ ...cursor
2061
+ } : params, options));
2062
+ if (all.push(...page), page.length < 200) return all;
2063
+ let last = page[page.length - 1];
2064
+ cursor = {
2065
+ c: last._createdAt,
2066
+ i: last._id
2067
+ };
2068
+ }
2069
+ }
2070
+ /** @internal */
2071
+ function _readEntry(client, httpRequest, knowledgeBaseId, path, options) {
2072
+ return _one(client, httpRequest, `*[_type == "${ENTRY_TYPE}" && knowledgeBaseId == $kb && path == $path][0]`, {
2073
+ kb: knowledgeBaseId,
2074
+ path
2075
+ }, options);
2076
+ }
2077
+ /** @internal */
2078
+ async function _listEntries(client, httpRequest, knowledgeBaseId, options) {
2079
+ let all = [], after = "";
2080
+ for (;;) {
2081
+ let page = await lastValueFrom(_fetch(client, httpRequest, `*[_type == "${ENTRY_TYPE}" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...200] {_id, path, title, tldr, status}`, {
2082
+ kb: knowledgeBaseId,
2083
+ after
2084
+ }, options));
2085
+ if (all.push(...page), page.length < 200) return all;
2086
+ after = page[page.length - 1].path;
2087
+ }
2088
+ }
2089
+ /** @internal */
2090
+ function _listIssues(client, httpRequest, knowledgeBaseId, status, options) {
2091
+ return _drainByCreatedAt(client, httpRequest, `_type == "${ISSUE_TYPE}" && knowledgeBaseId == $kb${status === void 0 ? "" : " && status == $status"}`, status === void 0 ? { kb: knowledgeBaseId } : {
2092
+ kb: knowledgeBaseId,
2093
+ status
2094
+ }, options);
2095
+ }
2096
+ /** @internal */
2097
+ function _readIssue(client, httpRequest, knowledgeBaseId, issueId, options) {
2098
+ return _one(client, httpRequest, `*[_type == "${ISSUE_TYPE}" && knowledgeBaseId == $kb && _id == $id][0]`, {
2099
+ kb: knowledgeBaseId,
2100
+ id: issueId
2101
+ }, options);
2102
+ }
2103
+ /** @internal */
2104
+ function _listInstructions(client, httpRequest, knowledgeBaseId, options) {
2105
+ return _drainByCreatedAt(client, httpRequest, "_type == \"sanity.context.instruction\" && knowledgeBaseId == $kb && schemaVersion == 1", { kb: knowledgeBaseId }, options);
2106
+ }
2107
+ /** @internal */
2108
+ function _listMcpEndpoints(client, httpRequest, options) {
2109
+ return lastValueFrom(_fetch(client, httpRequest, `*[_type == "${MCP_TYPE}" && organizationId == $org] | order(_createdAt asc, _id asc) [0...500]`, { org: _organizationId(client) }, options));
2110
+ }
2111
+ /** @internal */
2112
+ function _readMcpEndpoint(client, httpRequest, name, options) {
2113
+ return _one(client, httpRequest, `*[_type == "${MCP_TYPE}" && organizationId == $org && name == $name][0]`, {
2114
+ org: _organizationId(client),
2115
+ name
2116
+ }, options);
2117
+ }
2118
+ /** @internal */
2119
+ function _readConversation(client, httpRequest, threadId, options) {
2120
+ return _one(client, httpRequest, "*[_type == \"sanity.context.conversation\" && organizationId == $org && threadId == $threadId][0]", {
2121
+ org: _organizationId(client),
2122
+ threadId
2123
+ }, options);
2124
+ }
2125
+ const COLLECTION_URL = "/context/knowledge-bases";
2126
+ /**
2127
+ * The knowledge base every scoped method operates on comes from the client's
2128
+ * `resource` configuration, matching how media libraries and canvases are
2129
+ * addressed. Resolved per call so `withConfig` clones behave.
2130
+ */
2131
+ function _resolveKnowledgeBaseId(client) {
2132
+ let resource = client.config().resource;
2133
+ if (resource?.type !== "knowledge-base") throw Error("`resource` of type `knowledge-base` must be configured to use knowledge-base methods");
2134
+ return resource.id;
2135
+ }
2136
+ function _knowledgeBaseUrl(knowledgeBaseId, suffix = "") {
2137
+ return `${COLLECTION_URL}/${encodeURIComponent(knowledgeBaseId)}${suffix}`;
2138
+ }
2139
+ /** Serialize defined values into query params, dropping the undefined ones. */
2140
+ function _conversationUrl(client, threadId) {
2141
+ let organizationId = client.config().context?.organizationId;
2142
+ if (!organizationId) throw Error("`context.organizationId` must be configured to record conversations");
2143
+ if (!threadId) throw Error("`threadId` must be provided");
2144
+ return `/context/organizations/${encodeURIComponent(organizationId)}/conversations/${encodeURIComponent(threadId)}`;
2145
+ }
2146
+ function _query(entries) {
2147
+ return Object.fromEntries(Object.entries(entries).flatMap(([key, value]) => value === void 0 ? [] : [[key, `${value}`]]));
2148
+ }
2149
+ function _fetchBody(file) {
2150
+ return ArrayBuffer.isView(file) ? file.buffer instanceof ArrayBuffer ? new Uint8Array(file.buffer, file.byteOffset, file.byteLength) : Uint8Array.from(file) : file;
2151
+ }
2152
+ /**
2153
+ * `client.context` — knowledge bases and everything scoped to them.
2154
+ *
2155
+ * Collection-level management (create, list, get, edit, delete) addresses
2156
+ * knowledge bases per call, like `client.projects`. Everything scoped to one
2157
+ * knowledge base (imports, builds, issues, entries, ...) operates on the
2158
+ * client's configured `resource`, like media libraries:
2159
+ *
2160
+ * @example Full lifecycle
2161
+ * ```ts
2162
+ * const created = await client.context.knowledgeBases.create({
2163
+ * organizationId: 'org123',
2164
+ * title: 'Support docs',
2165
+ * description: 'Product docs and troubleshooting guides',
2166
+ * })
2167
+ *
2168
+ * const kb = createClient({
2169
+ * apiVersion: '2026-08-25',
2170
+ * token,
2171
+ * resource: {type: 'knowledge-base', id: created.publicId},
2172
+ * })
2173
+ *
2174
+ * await kb.context.imports.create({type: 'text', title: 'Refund policy', content: refundMd})
2175
+ * const {jobId} = await kb.context.build()
2176
+ * ```
2177
+ *
2178
+ * @beta
2179
+ */
2180
+ var ContextClient = class {
2181
+ #client;
2182
+ #httpRequest;
2183
+ constructor(client, httpRequest) {
2184
+ this.#client = client, this.#httpRequest = httpRequest;
2185
+ }
2186
+ /** Request against the configured knowledge base. */
2187
+ #request(suffix, reqOptions = {}) {
2188
+ return _request(this.#client, this.#httpRequest, {
2189
+ url: _knowledgeBaseUrl(_resolveKnowledgeBaseId(this.#client), suffix),
2190
+ ...reqOptions
2191
+ });
2192
+ }
2193
+ /** Shared shape of every paginated list endpoint scoped to the knowledge base. */
2194
+ #list(suffix, params, extraQuery) {
2195
+ return this.#request(suffix, {
2196
+ query: _query({
2197
+ cursor: params?.cursor,
2198
+ limit: params?.limit,
2199
+ ...extraQuery
2200
+ }),
2201
+ signal: params?.signal,
2202
+ tag: params?.tag
2203
+ });
2204
+ }
2205
+ async #uploadFile(params, options) {
2206
+ let staged = await this.#request("/imports/uploads", {
2207
+ method: "POST",
2208
+ body: {
2209
+ filename: params.filename,
2210
+ ...params.contentType && { contentType: params.contentType }
2211
+ },
2212
+ ...options
2213
+ }), config = this.#client.config(), putResponse = await (config.resolveFetch?.(config.proxy) ?? globalThis.fetch)(staged.uploadUrl, {
2214
+ method: "PUT",
2215
+ body: _fetchBody(params.file),
2216
+ ...params.contentType && { headers: { "content-type": params.contentType } },
2217
+ signal: options?.signal
2218
+ });
2219
+ if (!putResponse.ok) throw Error(`File upload failed: ${putResponse.status} ${putResponse.statusText}`);
2220
+ return this.#request(`/imports/uploads/${encodeURIComponent(staged.importId)}/complete`, {
2221
+ method: "POST",
2222
+ body: {},
2223
+ ...options
2224
+ });
2225
+ }
2226
+ /** The knowledge base collection: management addressed per call. */
2227
+ knowledgeBases = {
2228
+ /** Create a knowledge base. Requires the org-level knowledge-base create grant. */
2229
+ create: (params, options) => _request(this.#client, this.#httpRequest, {
2230
+ url: COLLECTION_URL,
2231
+ method: "POST",
2232
+ body: params,
2233
+ ...options
2234
+ }),
2235
+ /** List the organization's knowledge bases. */
2236
+ list: (params) => _request(this.#client, this.#httpRequest, {
2237
+ url: COLLECTION_URL,
2238
+ query: _query({
2239
+ organizationId: params.organizationId,
2240
+ cursor: params.cursor,
2241
+ limit: params.limit
2242
+ }),
2243
+ signal: params.signal,
2244
+ tag: params.tag
2245
+ }),
2246
+ /** Fetch a knowledge base by its id. */
2247
+ get: (knowledgeBaseId, options) => _request(this.#client, this.#httpRequest, {
2248
+ url: _knowledgeBaseUrl(knowledgeBaseId),
2249
+ ...options
2250
+ }),
2251
+ /** Edit a knowledge base's configuration. */
2252
+ edit: (knowledgeBaseId, params, options) => _request(this.#client, this.#httpRequest, {
2253
+ url: _knowledgeBaseUrl(knowledgeBaseId),
2254
+ method: "PATCH",
2255
+ body: params,
2256
+ ...options
2257
+ }),
2258
+ /** Delete a knowledge base and its generated content. */
2259
+ delete: async (knowledgeBaseId, options) => {
2260
+ await _request(this.#client, this.#httpRequest, {
2261
+ url: _knowledgeBaseUrl(knowledgeBaseId),
2262
+ method: "DELETE",
2263
+ ...options
2264
+ });
2265
+ }
2266
+ };
2267
+ /**
2268
+ * GROQ over the organization's Context documents (conversation telemetry
2269
+ * today; the store holds every Context family and the caller's access
2270
+ * decides what a query returns, so filter on `_type`).
2271
+ *
2272
+ * Requires `context.organizationId` in the client configuration.
2273
+ */
1977
2274
  fetch(query, params, options) {
1978
2275
  return lastValueFrom(_fetch(this.#client, this.#httpRequest, query, params, options));
1979
2276
  }
2277
+ /**
2278
+ * Listen for changes to the organization's Context documents. Mirrors
2279
+ * `client.listen(query, params, options)` and emits mutation events by
2280
+ * default.
2281
+ */
2282
+ listen(query, params, options) {
2283
+ return _listen(this.#client, query, params, options);
2284
+ }
2285
+ /**
2286
+ * Conversation telemetry. `threadId` identifies the conversation within
2287
+ * the organization — reuse means the same conversation. Beyond the canned
2288
+ * `get`, reads go through {@link fetch} and {@link listen} with GROQ
2289
+ * (`_type == "sanity.context.conversation"`).
2290
+ *
2291
+ * Requires `context.organizationId` in the client configuration.
2292
+ */
2293
+ conversations = {
2294
+ /**
2295
+ * Record a conversation. Messages replace the stored transcript
2296
+ * wholesale; `metadata` and model fields only overwrite when present.
2297
+ * Last write per thread wins — retries are safe.
2298
+ */
2299
+ save: (params, options) => {
2300
+ let { threadId, ...body } = params;
2301
+ return _request(this.#client, this.#httpRequest, {
2302
+ url: _conversationUrl(this.#client, threadId),
2303
+ method: "PUT",
2304
+ body,
2305
+ ...options
2306
+ });
2307
+ },
2308
+ /**
2309
+ * Record the classification your own model produced for one thread:
2310
+ * exactly one of `coreMetrics` (a verdict) or `classificationError`
2311
+ * (why classification failed).
2312
+ */
2313
+ classify: (params, options) => {
2314
+ let { threadId, ...body } = params;
2315
+ return _request(this.#client, this.#httpRequest, {
2316
+ url: _conversationUrl(this.#client, threadId),
2317
+ method: "PATCH",
2318
+ body,
2319
+ ...options
2320
+ });
2321
+ },
2322
+ /**
2323
+ * One recorded conversation by its thread id, or `null` when the thread
2324
+ * was never recorded. Runs:
2325
+ *
2326
+ * `*[_type == "sanity.context.conversation" && organizationId == $org && threadId == $threadId][0]`
2327
+ *
2328
+ * For anything more, use {@link fetch}.
2329
+ */
2330
+ get: (params, options) => _readConversation(this.#client, this.#httpRequest, params.threadId, options)
2331
+ };
2332
+ /**
2333
+ * Build the configured knowledge base. The server waits for pending import
2334
+ * processing before assembling, so importing and building back to back is
2335
+ * safe. Track the returned job with {@link jobs}.
2336
+ */
2337
+ build(options) {
2338
+ return this.#request("/build", {
2339
+ method: "POST",
2340
+ ...options
2341
+ });
2342
+ }
2343
+ /** Cancel the running build, if any. */
2344
+ cancelBuild(options) {
2345
+ return this.#request("/build/cancel", {
2346
+ method: "POST",
2347
+ ...options
2348
+ });
2349
+ }
2350
+ /** Run an incremental refresh: re-check sources and apply what changed. */
2351
+ refresh(options) {
2352
+ return this.#request("/refresh", {
2353
+ method: "POST",
2354
+ ...options
2355
+ });
2356
+ }
2357
+ /** Imports: feed content into the configured knowledge base. */
2358
+ imports = {
2359
+ /**
2360
+ * Import content. One entry point, discriminated on `type`: inline
2361
+ * `text`, a website `crawl`, a Sanity `dataset` bind, or a `file`
2362
+ * upload. Processing queues automatically. The file variant stages the
2363
+ * upload, PUTs the bytes to a signed storage URL, and confirms; the
2364
+ * bytes never pass through the Context API.
2365
+ */
2366
+ create: (params, options) => params.type === "file" ? this.#uploadFile(params, options) : this.#request("/imports", {
2367
+ method: "POST",
2368
+ body: params,
2369
+ ...options
2370
+ }),
2371
+ list: (params) => this.#list("/imports", params),
2372
+ get: (params, options) => this.#request(`/imports/${encodeURIComponent(params.importId)}`, options),
2373
+ /** A short-lived signed URL for the original uploaded bytes. */
2374
+ download: (params, options) => this.#request(`/imports/${encodeURIComponent(params.importId)}/download`, options),
2375
+ delete: async (params, options) => {
2376
+ await this.#request(`/imports/${encodeURIComponent(params.importId)}`, {
2377
+ method: "DELETE",
2378
+ ...options
2379
+ });
2380
+ }
2381
+ };
2382
+ /** Jobs: poll async work (builds, imports) to a terminal state. */
2383
+ jobs = { get: (params, options) => this.#request(`/jobs/${encodeURIComponent(params.jobId)}`, options) };
2384
+ /**
2385
+ * Issues: findings from builds awaiting triage. Reads are canned GROQ
2386
+ * queries against the organization's document store; for anything more,
2387
+ * use {@link fetch}. Reads require `context.organizationId` alongside the
2388
+ * knowledge-base `resource` in the client configuration.
2389
+ */
2390
+ issues = {
2391
+ /**
2392
+ * Every issue on the knowledge base, oldest first, optionally narrowed
2393
+ * to one status. Drains keyset pages internally and resolves with the
2394
+ * complete set. Runs:
2395
+ *
2396
+ * `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && status == $status] | order(_createdAt asc, _id asc)`
2397
+ *
2398
+ * (the status clause only when given). For anything more, use {@link fetch}.
2399
+ */
2400
+ list: (params, options) => _listIssues(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), params?.status, options),
2401
+ /**
2402
+ * One issue by its document id, or `null` when it does not exist. Runs:
2403
+ *
2404
+ * `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && _id == $id][0]`
2405
+ *
2406
+ * For anything more, use {@link fetch}.
2407
+ */
2408
+ get: (params, options) => _readIssue(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), params.issueId, options),
2409
+ /** Resolve a conflict issue. Mints the standing instruction, same as the dashboard. */
2410
+ resolve: (params, options) => {
2411
+ let { issueId, ...body } = params;
2412
+ return this.#request(`/issues/${encodeURIComponent(issueId)}/resolve`, {
2413
+ method: "POST",
2414
+ body,
2415
+ ...options
2416
+ });
2417
+ },
2418
+ dismiss: (params, options) => this.#request(`/issues/${encodeURIComponent(params.issueId)}/dismiss`, {
2419
+ method: "POST",
2420
+ ...options
2421
+ }),
2422
+ reopen: (params, options) => this.#request(`/issues/${encodeURIComponent(params.issueId)}/reopen`, {
2423
+ method: "POST",
2424
+ ...options
2425
+ }),
2426
+ /** Apply already-accepted issues to the knowledge base in one batch. */
2427
+ apply: (params, options) => this.#request("/issues/apply", {
2428
+ method: "POST",
2429
+ body: params,
2430
+ ...options
2431
+ })
2432
+ };
2433
+ /** Instructions: standing decisions that steer every build. */
2434
+ instructions = {
2435
+ create: (params, options) => this.#request("/instructions", {
2436
+ method: "POST",
2437
+ body: params,
2438
+ ...options
2439
+ }),
2440
+ /**
2441
+ * Every current-schema instruction on the knowledge base, oldest first.
2442
+ * Drains keyset pages internally and resolves with the complete set.
2443
+ * Runs:
2444
+ *
2445
+ * `*[_type == "sanity.context.instruction" && knowledgeBaseId == $kb && schemaVersion == 1] | order(_createdAt asc, _id asc)`
2446
+ *
2447
+ * For anything more, use {@link fetch}. Requires `context.organizationId`
2448
+ * alongside the knowledge-base `resource` in the client configuration.
2449
+ */
2450
+ list: (options) => _listInstructions(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), options),
2451
+ edit: (params, options) => {
2452
+ let { instructionId, ...body } = params;
2453
+ return this.#request(`/instructions/${encodeURIComponent(instructionId)}`, {
2454
+ method: "PATCH",
2455
+ body,
2456
+ ...options
2457
+ });
2458
+ },
2459
+ delete: async (params, options) => {
2460
+ await this.#request(`/instructions/${encodeURIComponent(params.instructionId)}`, {
2461
+ method: "DELETE",
2462
+ ...options
2463
+ });
2464
+ }
2465
+ };
2466
+ /**
2467
+ * Entries: the built outline, one entry per node. Reads are canned GROQ
2468
+ * queries against the organization's document store; for anything more,
2469
+ * use {@link fetch}. Requires `context.organizationId` alongside the
2470
+ * knowledge-base `resource` in the client configuration.
2471
+ */
2472
+ entries = {
2473
+ /**
2474
+ * Every entry, path-ordered, as a metadata view (`_id`, `path`,
2475
+ * `title`, `tldr`, `status`) with bodies excluded. Drains keyset pages
2476
+ * internally and resolves with the complete set. Runs:
2477
+ *
2478
+ * `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...200] {_id, path, title, tldr, status}`
2479
+ *
2480
+ * For bodies, use `entries.get` or {@link fetch}.
2481
+ */
2482
+ list: (options) => _listEntries(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), options),
2483
+ /**
2484
+ * One entry with its full body and citations, by outline path (e.g.
2485
+ * `billing/refunds`), or `null` when no entry sits at that path. Runs:
2486
+ *
2487
+ * `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path == $path][0]`
2488
+ *
2489
+ * For anything more, use {@link fetch}.
2490
+ */
2491
+ get: (params, options) => _readEntry(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), params.path, options),
2492
+ /**
2493
+ * Rebuild one entry from its already-placed sources, by outline path.
2494
+ * Poll the returned job with {@link jobs}; `affectedEntries` lists every
2495
+ * entry the rebuild touches.
2496
+ */
2497
+ rebuild: (params, options) => this.#request(`/entries/${encodeURIComponent(params.path)}/rebuild`, {
2498
+ method: "POST",
2499
+ ...options
2500
+ })
2501
+ };
2502
+ /**
2503
+ * MCP endpoint configurations, org-owned documents read with canned GROQ
2504
+ * queries. Requires `context.organizationId` in the client configuration.
2505
+ */
2506
+ mcpEndpoints = {
2507
+ /**
2508
+ * The organization's MCP endpoint configurations, oldest first. Runs:
2509
+ *
2510
+ * `*[_type == "sanity.context.mcp" && organizationId == $org] | order(_createdAt asc, _id asc) [0...500]`
2511
+ *
2512
+ * For anything more, use {@link fetch}.
2513
+ */
2514
+ list: (options) => _listMcpEndpoints(this.#client, this.#httpRequest, options),
2515
+ /**
2516
+ * One MCP endpoint configuration by its URL name, or `null` when none
2517
+ * carries that name. Runs:
2518
+ *
2519
+ * `*[_type == "sanity.context.mcp" && organizationId == $org && name == $name][0]`
2520
+ *
2521
+ * For anything more, use {@link fetch}.
2522
+ */
2523
+ get: (params, options) => _readMcpEndpoint(this.#client, this.#httpRequest, params.name, options)
2524
+ };
2525
+ /** Sources: the distilled units builds cite. */
2526
+ sources = {
2527
+ /**
2528
+ * List sources, optionally filtered by `status` or the `importId` they
2529
+ * came from. `ids` is a lookup mode: it resolves those exact sources
2530
+ * (e.g. from an entry's citations) and overrides `status` and `cursor`.
2531
+ */
2532
+ list: (params) => this.#list("/sources", params, {
2533
+ status: params?.status,
2534
+ importId: params?.importId,
2535
+ ids: params?.ids?.join(",")
2536
+ }),
2537
+ get: (params, options) => this.#request(`/sources/${encodeURIComponent(params.sourceId)}`, options),
2538
+ /**
2539
+ * Distilled source content, optionally a line range: the evidence behind
2540
+ * a citation or an issue.
2541
+ */
2542
+ content: (params, options) => this.#request(`/sources/${encodeURIComponent(params.sourceId)}/content`, {
2543
+ query: _query({
2544
+ startLine: params.startLine,
2545
+ endLine: params.endLine
2546
+ }),
2547
+ ...options
2548
+ }),
2549
+ delete: async (params, options) => {
2550
+ await this.#request(`/sources/${encodeURIComponent(params.sourceId)}`, {
2551
+ method: "DELETE",
2552
+ ...options
2553
+ });
2554
+ }
2555
+ };
2556
+ }, ObservableContextClient = class {
2557
+ #client;
2558
+ #httpRequest;
2559
+ constructor(client, httpRequest) {
2560
+ this.#client = client, this.#httpRequest = httpRequest;
2561
+ }
2562
+ /** The knowledge base collection: management addressed per call. */
2563
+ knowledgeBases = {
2564
+ /** Create a knowledge base. Requires the org-level knowledge-base create grant. */
2565
+ create: (params, options) => _observe(options?.signal, (signal) => _request(this.#client, this.#httpRequest, {
2566
+ url: COLLECTION_URL,
2567
+ method: "POST",
2568
+ body: params,
2569
+ tag: options?.tag,
2570
+ signal
2571
+ })),
2572
+ /** List the organization's knowledge bases. */
2573
+ list: (params) => _observe(params.signal, (signal) => _request(this.#client, this.#httpRequest, {
2574
+ url: COLLECTION_URL,
2575
+ query: _query({
2576
+ organizationId: params.organizationId,
2577
+ cursor: params.cursor,
2578
+ limit: params.limit
2579
+ }),
2580
+ tag: params.tag,
2581
+ signal
2582
+ })),
2583
+ /** Fetch a knowledge base by its id. */
2584
+ get: (knowledgeBaseId, options) => _observe(options?.signal, (signal) => _request(this.#client, this.#httpRequest, {
2585
+ url: _knowledgeBaseUrl(knowledgeBaseId),
2586
+ tag: options?.tag,
2587
+ signal
2588
+ })),
2589
+ /** Edit a knowledge base's configuration. */
2590
+ edit: (knowledgeBaseId, params, options) => _observe(options?.signal, (signal) => _request(this.#client, this.#httpRequest, {
2591
+ url: _knowledgeBaseUrl(knowledgeBaseId),
2592
+ method: "PATCH",
2593
+ body: params,
2594
+ tag: options?.tag,
2595
+ signal
2596
+ })),
2597
+ /** Delete a knowledge base and its generated content. */
2598
+ delete: (knowledgeBaseId, options) => _observe(options?.signal, (signal) => _request(this.#client, this.#httpRequest, {
2599
+ url: _knowledgeBaseUrl(knowledgeBaseId),
2600
+ method: "DELETE",
2601
+ tag: options?.tag,
2602
+ signal
2603
+ }))
2604
+ };
2605
+ /**
2606
+ * GROQ over the organization's Context documents (conversation telemetry
2607
+ * today; the store holds every Context family and the caller's access
2608
+ * decides what a query returns, so filter on `_type`).
2609
+ *
2610
+ * Requires `context.organizationId` in the client configuration.
2611
+ */
2612
+ fetch(query, params, options) {
2613
+ return _fetch(this.#client, this.#httpRequest, query, params, options);
2614
+ }
2615
+ /**
2616
+ * Listen for changes to the organization's Context documents. Mirrors
2617
+ * `client.listen(query, params, options)` and emits mutation events by
2618
+ * default.
2619
+ */
1980
2620
  listen(query, params, options) {
1981
2621
  return _listen(this.#client, query, params, options);
1982
2622
  }
2623
+ /**
2624
+ * Conversation telemetry. `threadId` identifies the conversation within
2625
+ * the organization — reuse means the same conversation. Beyond the canned
2626
+ * `get`, reads go through {@link fetch} and {@link listen} with GROQ
2627
+ * (`_type == "sanity.context.conversation"`).
2628
+ *
2629
+ * Requires `context.organizationId` in the client configuration.
2630
+ */
2631
+ conversations = {
2632
+ /**
2633
+ * Record a conversation. Messages replace the stored transcript
2634
+ * wholesale; `metadata` and model fields only overwrite when present.
2635
+ * Last write per thread wins — retries are safe.
2636
+ */
2637
+ save: (params, options) => {
2638
+ let { threadId, ...body } = params;
2639
+ return _observe(options?.signal, (signal) => _request(this.#client, this.#httpRequest, {
2640
+ url: _conversationUrl(this.#client, threadId),
2641
+ method: "PUT",
2642
+ body,
2643
+ tag: options?.tag,
2644
+ signal
2645
+ }));
2646
+ },
2647
+ /**
2648
+ * Record the classification your own model produced for one thread:
2649
+ * exactly one of `coreMetrics` (a verdict) or `classificationError`
2650
+ * (why classification failed).
2651
+ */
2652
+ classify: (params, options) => {
2653
+ let { threadId, ...body } = params;
2654
+ return _observe(options?.signal, (signal) => _request(this.#client, this.#httpRequest, {
2655
+ url: _conversationUrl(this.#client, threadId),
2656
+ method: "PATCH",
2657
+ body,
2658
+ tag: options?.tag,
2659
+ signal
2660
+ }));
2661
+ },
2662
+ /**
2663
+ * One recorded conversation by its thread id, or `null` when the thread
2664
+ * was never recorded. Runs:
2665
+ *
2666
+ * `*[_type == "sanity.context.conversation" && organizationId == $org && threadId == $threadId][0]`
2667
+ *
2668
+ * For anything more, use {@link fetch}.
2669
+ */
2670
+ get: (params, options) => _observe(options?.signal, (signal) => _readConversation(this.#client, this.#httpRequest, params.threadId, {
2671
+ ...options,
2672
+ signal
2673
+ }))
2674
+ };
2675
+ /**
2676
+ * Entries: the built outline, one entry per node. Reads are canned GROQ
2677
+ * queries against the organization's document store; for anything more,
2678
+ * use {@link fetch}. Requires `context.organizationId` alongside the
2679
+ * knowledge-base `resource` in the client configuration.
2680
+ */
2681
+ entries = {
2682
+ /**
2683
+ * Every entry, path-ordered, as a metadata view (`_id`, `path`,
2684
+ * `title`, `tldr`, `status`) with bodies excluded. Drains keyset pages
2685
+ * internally and emits the complete set. Runs:
2686
+ *
2687
+ * `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...200] {_id, path, title, tldr, status}`
2688
+ *
2689
+ * For bodies, use `entries.get` or {@link fetch}.
2690
+ */
2691
+ list: (options) => _observe(options?.signal, (signal) => _listEntries(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), {
2692
+ ...options,
2693
+ signal
2694
+ })),
2695
+ /**
2696
+ * One entry with its full body and citations, by outline path (e.g.
2697
+ * `billing/refunds`), or `null` when no entry sits at that path. Runs:
2698
+ *
2699
+ * `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path == $path][0]`
2700
+ *
2701
+ * For anything more, use {@link fetch}.
2702
+ */
2703
+ get: (params, options) => _observe(options?.signal, (signal) => _readEntry(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), params.path, {
2704
+ ...options,
2705
+ signal
2706
+ })),
2707
+ /**
2708
+ * Rebuild one entry from its already-placed sources, by outline path.
2709
+ * Poll the returned job with the promise client's `jobs`;
2710
+ * `affectedEntries` lists every entry the rebuild touches.
2711
+ */
2712
+ rebuild: (params, options) => _observe(options?.signal, (signal) => _request(this.#client, this.#httpRequest, {
2713
+ url: _knowledgeBaseUrl(_resolveKnowledgeBaseId(this.#client), `/entries/${encodeURIComponent(params.path)}/rebuild`),
2714
+ method: "POST",
2715
+ tag: options?.tag,
2716
+ signal
2717
+ }))
2718
+ };
2719
+ /**
2720
+ * Issues: findings from builds awaiting triage. Reads are canned GROQ
2721
+ * queries against the organization's document store; for anything more,
2722
+ * use {@link fetch}. Requires `context.organizationId` alongside the
2723
+ * knowledge-base `resource` in the client configuration.
2724
+ */
2725
+ issues = {
2726
+ /**
2727
+ * Every issue on the knowledge base, oldest first, optionally narrowed
2728
+ * to one status. Drains keyset pages internally and emits the complete
2729
+ * set. Runs:
2730
+ *
2731
+ * `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && status == $status] | order(_createdAt asc, _id asc)`
2732
+ *
2733
+ * (the status clause only when given). For anything more, use {@link fetch}.
2734
+ */
2735
+ list: (params, options) => _observe(options?.signal, (signal) => _listIssues(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), params?.status, {
2736
+ ...options,
2737
+ signal
2738
+ })),
2739
+ /**
2740
+ * One issue by its document id, or `null` when it does not exist. Runs:
2741
+ *
2742
+ * `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && _id == $id][0]`
2743
+ *
2744
+ * For anything more, use {@link fetch}.
2745
+ */
2746
+ get: (params, options) => _observe(options?.signal, (signal) => _readIssue(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), params.issueId, {
2747
+ ...options,
2748
+ signal
2749
+ }))
2750
+ };
2751
+ /**
2752
+ * Instructions: standing decisions that steer every build. The canned
2753
+ * GROQ read; writes are promise-based on `client.context`.
2754
+ */
2755
+ instructions = {
2756
+ /**
2757
+ * Every current-schema instruction on the knowledge base, oldest first.
2758
+ * Drains keyset pages internally and emits the complete set. Runs:
2759
+ *
2760
+ * `*[_type == "sanity.context.instruction" && knowledgeBaseId == $kb && schemaVersion == 1] | order(_createdAt asc, _id asc)`
2761
+ *
2762
+ * For anything more, use {@link fetch}. Requires `context.organizationId`
2763
+ * alongside the knowledge-base `resource` in the client configuration.
2764
+ */
2765
+ list: (options) => _observe(options?.signal, (signal) => _listInstructions(this.#client, this.#httpRequest, _resolveKnowledgeBaseId(this.#client), {
2766
+ ...options,
2767
+ signal
2768
+ })) };
2769
+ /**
2770
+ * MCP endpoint configurations, org-owned documents read with canned GROQ
2771
+ * queries. Requires `context.organizationId` in the client configuration.
2772
+ */
2773
+ mcpEndpoints = {
2774
+ /**
2775
+ * The organization's MCP endpoint configurations, oldest first. Runs:
2776
+ *
2777
+ * `*[_type == "sanity.context.mcp" && organizationId == $org] | order(_createdAt asc, _id asc) [0...500]`
2778
+ *
2779
+ * For anything more, use {@link fetch}.
2780
+ */
2781
+ list: (options) => _observe(options?.signal, (signal) => _listMcpEndpoints(this.#client, this.#httpRequest, {
2782
+ ...options,
2783
+ signal
2784
+ })),
2785
+ /**
2786
+ * One MCP endpoint configuration by its URL name, or `null` when none
2787
+ * carries that name. Runs:
2788
+ *
2789
+ * `*[_type == "sanity.context.mcp" && organizationId == $org && name == $name][0]`
2790
+ *
2791
+ * For anything more, use {@link fetch}.
2792
+ */
2793
+ get: (params, options) => _observe(options?.signal, (signal) => _readMcpEndpoint(this.#client, this.#httpRequest, params.name, {
2794
+ ...options,
2795
+ signal
2796
+ }))
2797
+ };
1983
2798
  };
1984
2799
  /**
1985
2800
  * A variant of share that takes a predicate function to determine which value to replay to new subscribers
@@ -2007,6 +2822,7 @@ function _shareReplayLatest(config) {
2007
2822
  const requiredApiVersion = "2021-03-25";
2008
2823
  /**
2009
2824
  * @public
2825
+ * @inline
2010
2826
  */
2011
2827
  var LiveClient = class {
2012
2828
  #client;
@@ -2133,7 +2949,10 @@ function checkCorsObservable(url, projectId, requireCredentials, fetcher) {
2133
2949
  * resolver — `undefined` covers the `globalThis.fetch` fallback.
2134
2950
  */
2135
2951
  const eventsCache = /* @__PURE__ */ new Map();
2136
- /** @internal */
2952
+ /**
2953
+ * @internal
2954
+ * @inline
2955
+ */
2137
2956
  var ObservableDatasetsClient = class {
2138
2957
  #client;
2139
2958
  #httpRequest;
@@ -2448,7 +3267,10 @@ function buildQueryParams(options) {
2448
3267
  }
2449
3268
  return options.expiration && (params.expiration = options.expiration), params;
2450
3269
  }
2451
- /** @internal */
3270
+ /**
3271
+ * @internal
3272
+ * @inline
3273
+ */
2452
3274
  var ObservableProjectsClient = class {
2453
3275
  #client;
2454
3276
  #httpRequest;
@@ -2575,7 +3397,10 @@ const getArgs = (releaseOrOptions, maybeOptions) => {
2575
3397
  options
2576
3398
  };
2577
3399
  };
2578
- /** @public */
3400
+ /**
3401
+ * @public
3402
+ * @inline
3403
+ */
2579
3404
  var ObservableReleasesClient = class {
2580
3405
  #client;
2581
3406
  #httpRequest;
@@ -3030,30 +3855,73 @@ var ObservableReleasesClient = class {
3030
3855
  return _request(this.#client, this.#httpRequest, { url: `/users/${id}` });
3031
3856
  }
3032
3857
  }, ObservableSanityClient = class ObservableSanityClient {
3858
+ /**
3859
+ * Upload, fetch and delete assets (images and files) in the configured dataset
3860
+ *
3861
+ * @category Assets
3862
+ */
3033
3863
  assets;
3864
+ /**
3865
+ * Create, list, edit and delete datasets in the configured project
3866
+ *
3867
+ * @category Projects & Datasets
3868
+ */
3034
3869
  datasets;
3870
+ /**
3871
+ * Subscribe to live content updates through the Live Content API
3872
+ *
3873
+ * @category Real-time
3874
+ */
3035
3875
  live;
3876
+ /**
3877
+ * Interact with Media Library assets
3878
+ *
3879
+ * @category Assets
3880
+ */
3036
3881
  mediaLibrary;
3882
+ /**
3883
+ * Fetch information about the projects the authenticated user has access to
3884
+ *
3885
+ * @category Projects & Datasets
3886
+ */
3037
3887
  projects;
3888
+ /**
3889
+ * Fetch information about users in the configured project
3890
+ *
3891
+ * @category Projects & Datasets
3892
+ */
3038
3893
  users;
3894
+ /**
3895
+ * Run Agent Actions - AI-powered operations to generate, transform, translate, prompt and patch documents
3896
+ *
3897
+ * @category Agent Actions
3898
+ */
3039
3899
  agent;
3040
3900
  collaboration;
3041
3901
  functions;
3042
- releases;
3043
3902
  /**
3044
- * Private properties
3903
+ * Create and manage content releases and their scheduled publishing
3904
+ *
3905
+ * @category Releases
3045
3906
  */
3907
+ releases;
3908
+ /** @beta */
3909
+ context;
3046
3910
  #clientConfig;
3047
3911
  #httpRequest;
3048
3912
  /**
3049
- * Instance properties
3913
+ * Listen to document changes matching a GROQ query, delivered as server-sent events
3914
+ *
3915
+ * @category Real-time
3050
3916
  */
3051
- listen = _listen$1;
3917
+ listen = _listen$2;
3052
3918
  constructor(httpRequest, config = defaultConfig) {
3053
- 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.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = { action: new ObservableAgentsActionClient(this, this.#httpRequest) }, this.collaboration = { comments: new ObservableCollaborationCommentsClient(this, this.#httpRequest) }, this.functions = new ObservableFunctionsClient(this, this.#httpRequest), this.releases = new ObservableReleasesClient(this, this.#httpRequest);
3919
+ 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.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = { action: new ObservableAgentsActionClient(this, this.#httpRequest) }, this.collaboration = { comments: new ObservableCollaborationCommentsClient(this, this.#httpRequest) }, this.functions = new ObservableFunctionsClient(this, this.#httpRequest), this.releases = new ObservableReleasesClient(this, this.#httpRequest), this.context = new ObservableContextClient(this, this.#httpRequest);
3054
3920
  }
3055
3921
  /**
3056
3922
  * Clone the client - returns a new instance
3923
+ *
3924
+ * @category Configuration
3057
3925
  */
3058
3926
  clone() {
3059
3927
  return new ObservableSanityClient(this.#httpRequest, this.config());
@@ -3066,6 +3934,8 @@ var ObservableReleasesClient = class {
3066
3934
  /**
3067
3935
  * Clone the client with a new (partial) configuration.
3068
3936
  *
3937
+ * @category Configuration
3938
+ *
3069
3939
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3070
3940
  */
3071
3941
  withConfig(newConfig) {
@@ -3101,6 +3971,8 @@ var ObservableReleasesClient = class {
3101
3971
  * The order/position of documents is preserved based on the original array of IDs.
3102
3972
  * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3103
3973
  *
3974
+ * @category Querying
3975
+ *
3104
3976
  * @param ids - Document IDs to fetch
3105
3977
  * @param options - Request options
3106
3978
  */
@@ -3111,6 +3983,8 @@ var ObservableReleasesClient = class {
3111
3983
  * Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
3112
3984
  * Returns a set of the IDs that exist.
3113
3985
  *
3986
+ * @category Querying
3987
+ *
3114
3988
  * @param ids - Document IDs to check
3115
3989
  * @param options - Request options
3116
3990
  */
@@ -3150,6 +4024,8 @@ var ObservableReleasesClient = class {
3150
4024
  * * Discarding a version with no `releaseId` will discard the draft version of the published document.
3151
4025
  * * If the draft or release version does not exist, any error will throw.
3152
4026
  *
4027
+ * @category Versions
4028
+ *
3153
4029
  * @param params - Version action parameters:
3154
4030
  * - `releaseId` - The ID of the release to discard the document from.
3155
4031
  * - `publishedId` - The published ID of the document to discard.
@@ -3193,6 +4069,8 @@ var ObservableReleasesClient = class {
3193
4069
  * @remarks
3194
4070
  * * If the published document does not exist, an error will be thrown.
3195
4071
  *
4072
+ * @category Versions
4073
+ *
3196
4074
  * @param params - Version action parameters:
3197
4075
  * - `releaseId` - The ID of the release to unpublish the document from.
3198
4076
  * - `publishedId` - The published ID of the document to unpublish.
@@ -3225,6 +4103,8 @@ var ObservableReleasesClient = class {
3225
4103
  /**
3226
4104
  * Create a new transaction of mutations
3227
4105
  *
4106
+ * @category Mutations
4107
+ *
3228
4108
  * @param operations - Optional array of mutation operations to initialize the transaction instance with
3229
4109
  */
3230
4110
  transaction(operations) {
@@ -3233,6 +4113,8 @@ var ObservableReleasesClient = class {
3233
4113
  /**
3234
4114
  * Perform action operations against the configured dataset
3235
4115
  *
4116
+ * @category Mutations
4117
+ *
3236
4118
  * @param operations - Action operation(s) to execute
3237
4119
  * @param options - Action options
3238
4120
  */
@@ -3242,6 +4124,8 @@ var ObservableReleasesClient = class {
3242
4124
  /**
3243
4125
  * Perform an HTTP request against the Sanity API
3244
4126
  *
4127
+ * @category HTTP
4128
+ *
3245
4129
  * @param options - Request options
3246
4130
  */
3247
4131
  request(options) {
@@ -3250,6 +4134,8 @@ var ObservableReleasesClient = class {
3250
4134
  /**
3251
4135
  * Get a Sanity API URL for the URI provided
3252
4136
  *
4137
+ * @category HTTP
4138
+ *
3253
4139
  * @param uri - URI/path to build URL for
3254
4140
  * @param canUseCdn - Whether or not to allow using the API CDN for this route
3255
4141
  */
@@ -3259,6 +4145,8 @@ var ObservableReleasesClient = class {
3259
4145
  /**
3260
4146
  * Get a Sanity API URL for the data operation and path provided
3261
4147
  *
4148
+ * @category HTTP
4149
+ *
3262
4150
  * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3263
4151
  * @param path - Path to append after the operation
3264
4152
  */
@@ -3266,34 +4154,79 @@ var ObservableReleasesClient = class {
3266
4154
  return _getDataUrl(this, operation, path);
3267
4155
  }
3268
4156
  }, SanityClient = class SanityClient {
4157
+ /**
4158
+ * Upload, fetch and delete assets (images and files) in the configured dataset
4159
+ *
4160
+ * @category Assets
4161
+ */
3269
4162
  assets;
4163
+ /**
4164
+ * Create, list, edit and delete datasets in the configured project
4165
+ *
4166
+ * @category Projects & Datasets
4167
+ */
3270
4168
  datasets;
4169
+ /**
4170
+ * Subscribe to live content updates through the Live Content API
4171
+ *
4172
+ * @category Real-time
4173
+ */
3271
4174
  live;
4175
+ /**
4176
+ * Interact with Media Library assets
4177
+ *
4178
+ * @category Assets
4179
+ */
3272
4180
  mediaLibrary;
4181
+ /**
4182
+ * Fetch information about the projects the authenticated user has access to
4183
+ *
4184
+ * @category Projects & Datasets
4185
+ */
3273
4186
  projects;
4187
+ /**
4188
+ * Fetch information about users in the configured project
4189
+ *
4190
+ * @category Projects & Datasets
4191
+ */
3274
4192
  users;
4193
+ /**
4194
+ * Run Agent Actions - AI-powered operations to generate, transform, translate, prompt and patch documents
4195
+ *
4196
+ * @category Agent Actions
4197
+ */
3275
4198
  agent;
3276
4199
  collaboration;
3277
4200
  functions;
4201
+ /**
4202
+ * Create and manage content releases and their scheduled publishing
4203
+ *
4204
+ * @category Releases
4205
+ */
3278
4206
  releases;
4207
+ /** @beta */
4208
+ context;
3279
4209
  /**
3280
4210
  * Observable version of the Sanity client, with the same configuration as the promise-based one
4211
+ *
4212
+ * @category Configuration
3281
4213
  */
3282
4214
  observable;
3283
- /**
3284
- * Private properties
3285
- */
3286
4215
  #clientConfig;
3287
4216
  #httpRequest;
3288
4217
  /**
3289
- * Instance properties
4218
+ * Listen to document changes matching a GROQ query, delivered as server-sent events
4219
+ *
4220
+ * @category Real-time
3290
4221
  */
3291
- listen = _listen$1;
4222
+ listen = _listen$2;
3292
4223
  constructor(httpRequest, config = defaultConfig) {
3293
- 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.mediaLibrary = { video: new MediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = { action: new AgentActionsClient(this, this.#httpRequest) }, this.collaboration = { comments: new CollaborationCommentsClient(this, this.#httpRequest) }, this.functions = new FunctionsClient(this, this.#httpRequest), this.releases = new ReleasesClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
4224
+ 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.mediaLibrary = { video: new MediaLibraryVideoClient(this, this.#httpRequest) }, this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = { action: new AgentActionsClient(this, this.#httpRequest) }, this.collaboration = { comments: new CollaborationCommentsClient(this, this.#httpRequest) }, this.functions = new FunctionsClient(this, this.#httpRequest), this.releases = new ReleasesClient(this, this.#httpRequest), this.context = new ContextClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
3294
4225
  }
3295
4226
  /**
3296
4227
  * Clone the client - returns a new instance
4228
+ *
4229
+ * @category Configuration
3297
4230
  */
3298
4231
  clone() {
3299
4232
  return new SanityClient(this.#httpRequest, this.config());
@@ -3306,6 +4239,8 @@ var ObservableReleasesClient = class {
3306
4239
  /**
3307
4240
  * Clone the client with a new (partial) configuration.
3308
4241
  *
4242
+ * @category Configuration
4243
+ *
3309
4244
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3310
4245
  */
3311
4246
  withConfig(newConfig) {
@@ -3320,7 +4255,7 @@ var ObservableReleasesClient = class {
3320
4255
  });
3321
4256
  }
3322
4257
  fetch(query, params, options) {
3323
- return _fetch$1(this, this.#httpRequest, this.#clientConfig.stega, query, params, options);
4258
+ return _fetch$2(this, this.#httpRequest, this.#clientConfig.stega, query, params, options);
3324
4259
  }
3325
4260
  getDocument(id, options) {
3326
4261
  if (options?.includeAllVersions === !0) return _getDocument(this, this.#httpRequest, id, {
@@ -3341,6 +4276,8 @@ var ObservableReleasesClient = class {
3341
4276
  * The order/position of documents is preserved based on the original array of IDs.
3342
4277
  * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3343
4278
  *
4279
+ * @category Querying
4280
+ *
3344
4281
  * @param ids - Document IDs to fetch
3345
4282
  * @param options - Request options
3346
4283
  */
@@ -3351,6 +4288,8 @@ var ObservableReleasesClient = class {
3351
4288
  * Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
3352
4289
  * Returns a set of the IDs that exist.
3353
4290
  *
4291
+ * @category Querying
4292
+ *
3354
4293
  * @param ids - Document IDs to check
3355
4294
  * @param options - Request options
3356
4295
  */
@@ -3390,6 +4329,8 @@ var ObservableReleasesClient = class {
3390
4329
  * * Discarding a version with no `releaseId` will discard the draft version of the published document.
3391
4330
  * * If the draft or release version does not exist, any error will throw.
3392
4331
  *
4332
+ * @category Versions
4333
+ *
3393
4334
  * @param params - Version action parameters:
3394
4335
  * - `releaseId` - The ID of the release to discard the document from.
3395
4336
  * - `publishedId` - The published ID of the document to discard.
@@ -3433,6 +4374,8 @@ var ObservableReleasesClient = class {
3433
4374
  * @remarks
3434
4375
  * * If the published document does not exist, an error will be thrown.
3435
4376
  *
4377
+ * @category Versions
4378
+ *
3436
4379
  * @param params - Version action parameters:
3437
4380
  * - `releaseId` - The ID of the release to unpublish the document from.
3438
4381
  * - `publishedId` - The published ID of the document to unpublish.
@@ -3465,6 +4408,8 @@ var ObservableReleasesClient = class {
3465
4408
  /**
3466
4409
  * Create a new transaction of mutations
3467
4410
  *
4411
+ * @category Mutations
4412
+ *
3468
4413
  * @param operations - Optional array of mutation operations to initialize the transaction instance with
3469
4414
  */
3470
4415
  transaction(operations) {
@@ -3474,6 +4419,8 @@ var ObservableReleasesClient = class {
3474
4419
  * Perform action operations against the configured dataset
3475
4420
  * Returns a promise that resolves to the transaction result
3476
4421
  *
4422
+ * @category Mutations
4423
+ *
3477
4424
  * @param operations - Action operation(s) to execute
3478
4425
  * @param options - Action options
3479
4426
  */
@@ -3484,6 +4431,8 @@ var ObservableReleasesClient = class {
3484
4431
  * Perform a request against the Sanity API
3485
4432
  * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
3486
4433
  *
4434
+ * @category HTTP
4435
+ *
3487
4436
  * @param options - Request options
3488
4437
  * @returns Promise resolving to the response body
3489
4438
  */
@@ -3506,6 +4455,8 @@ var ObservableReleasesClient = class {
3506
4455
  /**
3507
4456
  * Get a Sanity API URL for the URI provided
3508
4457
  *
4458
+ * @category HTTP
4459
+ *
3509
4460
  * @param uri - URI/path to build URL for
3510
4461
  * @param canUseCdn - Whether or not to allow using the API CDN for this route
3511
4462
  */
@@ -3515,6 +4466,8 @@ var ObservableReleasesClient = class {
3515
4466
  /**
3516
4467
  * Get a Sanity API URL for the data operation and path provided
3517
4468
  *
4469
+ * @category HTTP
4470
+ *
3518
4471
  * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3519
4472
  * @param path - Path to append after the operation
3520
4473
  */
@@ -3552,7 +4505,7 @@ function defineDeprecatedCreateClient(createClient) {
3552
4505
  return printNoDefaultExport(), createClient(config);
3553
4506
  };
3554
4507
  }
3555
- var name = "@sanity/client", version = "8.3.0";
4508
+ var name = "@sanity/client", version = "8.5.0";
3556
4509
  const log = createDebug("sanity:client");
3557
4510
  function isNodeReadableStream(value) {
3558
4511
  return typeof value != "object" || !value || !("pipe" in value) ? !1 : typeof value.pipe == "function";
@@ -3609,6 +4562,6 @@ const middleware = [
3609
4562
  middleware,
3610
4563
  resolveFetch
3611
4564
  }, SanityClient), requester = exp.requester, createClient = exp.createClient, deprecatedCreateClient = defineDeprecatedCreateClient(createClient);
3612
- export { BasePatch, BaseTransaction, ChannelError, ClientError, ConnectionFailedError, CorsOriginError, DisconnectError, EXPERIMENTAL_API_WARNING, MessageError, MessageParseError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, isTimeoutError, requester, validateApiPerspective };
4565
+ export { BasePatch, BaseTransaction, ChannelError, ClientError, ConnectionFailedError, types_exports as Context, CorsOriginError, DisconnectError, EXPERIMENTAL_API_WARNING, MessageError, MessageParseError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, isTimeoutError, requester, validateApiPerspective };
3613
4566
 
3614
4567
  //# sourceMappingURL=index.node.js.map