@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/index.d.ts CHANGED
@@ -118,110 +118,6 @@ export declare class AssetsClient {
118
118
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
119
119
  }
120
120
 
121
- /** @beta */
122
- export declare type AssistAsyncInstruction<
123
- T extends Record<string, Any_2> = Record<string, Any_2>,
124
- > = (ExistingDocumentRequest | CreateDocumentRequest<T>) & AssistRequestBase & Async
125
-
126
- /** @public */
127
- declare class AssistClient {
128
- #private
129
- constructor(client: SanityClient, httpRequest: HttpRequest)
130
- instruct(request: AssistAsyncInstruction): Promise<{
131
- _id: string
132
- }>
133
- instruct<DocumentShape extends Record<string, Any>>(
134
- request: AssistSyncInstruction<DocumentShape>,
135
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
136
- }
137
-
138
- /** @beta */
139
- export declare type AssistInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
140
- | AssistSyncInstruction<T>
141
- | AssistAsyncInstruction<T>
142
-
143
- declare interface AssistRequestBase {
144
- /** schemaId as reported by sanity deploy / sanity schema store */
145
- schemaId: string
146
- /** string template using $variable – more on this below under "Dynamic instruction" */
147
- instruction: string
148
- /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
149
- instructionParams?: InstructionParams
150
- /**
151
- * Optional document path output target for the instruction.
152
- * When provided, the instruction will apply to this path in the document and its children.
153
- *
154
- * ## Examples
155
- * - `path: 'title'` will output to the title field in the document
156
- * - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
157
- */
158
- path?: string
159
- /**
160
- * Controls sub-paths in the document that can be output to.
161
- *
162
- * The string-paths are relative to the `path` param
163
- *
164
- * Note: these path strings are less strictly validated than the `path` param itself:
165
- * if an relative-path does not exist or is invalid, it will be silently ignored.
166
- *
167
- * @see AssistRequestBase#conditionalPaths
168
- * @see AssistRequestBase#outputTypes
169
- */
170
- relativeOutputPaths?:
171
- | {
172
- include: string[]
173
- }
174
- | {
175
- exclude: string[]
176
- }
177
- /**
178
- * Controls which types the instruction is allowed to output to.
179
- *
180
- * @see AssistRequestBase#relativeOutputPaths
181
- * @see AssistRequestBase#conditionalPaths
182
- */
183
- outputTypes?:
184
- | {
185
- include: string[]
186
- }
187
- | {
188
- exclude: string[]
189
- }
190
- /**
191
- * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
192
- *
193
- * By default, AI Assist will not output to conditional `readOnly` and `hidden` fields,
194
- * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
195
- *
196
- * `conditionalPaths` param allows setting the default conditional value for
197
- * `hidden` and `readOnly` to false,
198
- * or individually set `hidden` and `readOnly` state for individual document paths.
199
- *
200
- *
201
- * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Assist,
202
- * and cannot be changed via conditionalPaths.
203
- *
204
- * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
205
- *
206
- * @see AssistRequestBase#relativeOutputPaths
207
- * @see AssistRequestBase#outputTypes
208
- */
209
- conditionalPaths?: {
210
- defaultReadOnly?: boolean
211
- defaultHidden?: boolean
212
- paths?: {
213
- /** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
214
- path: string
215
- readOnly: boolean
216
- hidden: boolean
217
- }[]
218
- }
219
- }
220
-
221
- /** @beta */
222
- export declare type AssistSyncInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
223
- (ExistingDocumentRequest | CreateDocumentRequest<T>) & AssistRequestBase & Sync
224
-
225
121
  declare interface Async {
226
122
  /**
227
123
  * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
@@ -573,12 +469,6 @@ export declare class ConnectionFailedError extends Error {
573
469
  readonly name = 'ConnectionFailedError'
574
470
  }
575
471
 
576
- /** @beta */
577
- export declare interface ConstantInstructionParam {
578
- type: 'constant'
579
- value: string
580
- }
581
-
582
472
  /** @public */
583
473
  export declare interface ContentSourceMap {
584
474
  mappings: ContentSourceMapMappings
@@ -928,23 +818,6 @@ declare interface ExistingDocumentRequest {
928
818
  documentId: string
929
819
  }
930
820
 
931
- /**
932
- *
933
- * Includes a LLM-friendly version of the field value in the instruction
934
- * @beta
935
- * */
936
- export declare interface FieldInstructionParam {
937
- type: 'field'
938
- /**
939
- * Examples: 'title', 'array[_key=="key"].field
940
- */
941
- path: string
942
- /**
943
- * If omitted, implicitly uses the documentId of the instruction target
944
- */
945
- documentId?: string
946
- }
947
-
948
821
  /** @public */
949
822
  export declare type FilterDefault = (props: {
950
823
  /**
@@ -1011,13 +884,6 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1011
884
  returnDocuments?: true
1012
885
  }
1013
886
 
1014
- /** @beta */
1015
- export declare interface GroqInstructionParam {
1016
- type: 'groq'
1017
- query: string
1018
- params?: Record<string, string>
1019
- }
1020
-
1021
887
  /** @public */
1022
888
  export declare type HttpRequest = {
1023
889
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1079,15 +945,141 @@ export declare type InsertPatch =
1079
945
  }
1080
946
 
1081
947
  /** @beta */
1082
- export declare type InstructionParam =
948
+ export declare type InstructAsyncInstruction<
949
+ T extends Record<string, Any_2> = Record<string, Any_2>,
950
+ > = (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Async
951
+
952
+ /** @beta */
953
+ export declare interface InstructConstantInstructionParam {
954
+ type: 'constant'
955
+ value: string
956
+ }
957
+
958
+ /**
959
+ *
960
+ * Includes a LLM-friendly version of the field value in the instruction
961
+ * @beta
962
+ * */
963
+ export declare interface InstructFieldInstructionParam {
964
+ type: 'field'
965
+ /**
966
+ * Examples: 'title', 'array[_key=="key"].field'
967
+ */
968
+ path: string
969
+ /**
970
+ * If omitted, implicitly uses the documentId of the instruction target
971
+ */
972
+ documentId?: string
973
+ }
974
+
975
+ /**
976
+ * Includes a LLM-friendly version of GROQ query result in the instruction
977
+ * @beta
978
+ * */
979
+ export declare interface InstructGroqInstructionParam {
980
+ type: 'groq'
981
+ query: string
982
+ params?: Record<string, string>
983
+ }
984
+
985
+ /** @beta */
986
+ export declare type InstructInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
987
+ | InstructSyncInstruction<T>
988
+ | InstructAsyncInstruction<T>
989
+
990
+ /** @beta */
991
+ export declare type InstructInstructionParam =
1083
992
  | string
1084
- | ConstantInstructionParam
1085
- | FieldInstructionParam
993
+ | InstructConstantInstructionParam
994
+ | InstructFieldInstructionParam
1086
995
  | DocumentInstructionParam
1087
- | GroqInstructionParam
996
+ | InstructGroqInstructionParam
1088
997
 
1089
998
  /** @beta */
1090
- export declare type InstructionParams = Record<string, InstructionParam>
999
+ export declare type InstructInstructionParams = Record<string, InstructInstructionParam>
1000
+
1001
+ declare interface InstructRequestBase {
1002
+ /** schemaId as reported by sanity deploy / sanity schema store */
1003
+ schemaId: string
1004
+ /** string template using $variable – more on this below under "Dynamic instruction" */
1005
+ instruction: string
1006
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
1007
+ instructionParams?: InstructInstructionParams
1008
+ /**
1009
+ * Optional document path output target for the instruction.
1010
+ * When provided, the instruction will apply to this path in the document and its children.
1011
+ *
1012
+ * ## Examples
1013
+ * - `path: 'title'` will output to the title field in the document
1014
+ * - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
1015
+ */
1016
+ path?: string
1017
+ /**
1018
+ * Controls sub-paths in the document that can be output to.
1019
+ *
1020
+ * The string-paths are relative to the `path` param
1021
+ *
1022
+ * Note: these path strings are less strictly validated than the `path` param itself:
1023
+ * if an relative-path does not exist or is invalid, it will be silently ignored.
1024
+ *
1025
+ * @see InstructRequestBase#conditionalPaths
1026
+ * @see InstructRequestBase#outputTypes
1027
+ */
1028
+ relativeOutputPaths?:
1029
+ | {
1030
+ include: string[]
1031
+ }
1032
+ | {
1033
+ exclude: string[]
1034
+ }
1035
+ /**
1036
+ * Controls which types the instruction is allowed to output to.
1037
+ *
1038
+ * @see InstructRequestBase#relativeOutputPaths
1039
+ * @see InstructRequestBase#conditionalPaths
1040
+ */
1041
+ outputTypes?:
1042
+ | {
1043
+ include: string[]
1044
+ }
1045
+ | {
1046
+ exclude: string[]
1047
+ }
1048
+ /**
1049
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
1050
+ *
1051
+ * By default, AI Instruct will not output to conditional `readOnly` and `hidden` fields,
1052
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
1053
+ *
1054
+ * `conditionalPaths` param allows setting the default conditional value for
1055
+ * `hidden` and `readOnly` to false,
1056
+ * or individually set `hidden` and `readOnly` state for individual document paths.
1057
+ *
1058
+ *
1059
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to AI Instruct,
1060
+ * and cannot be changed via conditionalPaths.
1061
+ *
1062
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
1063
+ *
1064
+ * @see InstructRequestBase#relativeOutputPaths
1065
+ * @see InstructRequestBase#outputTypes
1066
+ */
1067
+ conditionalPaths?: {
1068
+ defaultReadOnly?: boolean
1069
+ defaultHidden?: boolean
1070
+ paths?: {
1071
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param on the request itself */
1072
+ path: string
1073
+ readOnly: boolean
1074
+ hidden: boolean
1075
+ }[]
1076
+ }
1077
+ }
1078
+
1079
+ /** @beta */
1080
+ export declare type InstructSyncInstruction<
1081
+ T extends Record<string, Any_2> = Record<string, Any_2>,
1082
+ > = (ExistingDocumentRequest | CreateDocumentRequest<T>) & InstructRequestBase & Sync
1091
1083
 
1092
1084
  /**
1093
1085
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
@@ -1503,18 +1495,6 @@ export declare class ObservableAssetsClient {
1503
1495
  >
1504
1496
  }
1505
1497
 
1506
- /** @public */
1507
- declare class ObservableAssistClient {
1508
- #private
1509
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1510
- instruct(request: AssistAsyncInstruction): Observable<{
1511
- _id: string
1512
- }>
1513
- instruct<DocumentShape extends Record<string, Any>>(
1514
- request: AssistSyncInstruction<DocumentShape>,
1515
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1516
- }
1517
-
1518
1498
  /** @internal */
1519
1499
  export declare class ObservableDatasetsClient {
1520
1500
  #private
@@ -1638,7 +1618,6 @@ export declare class ObservableSanityClient {
1638
1618
  live: LiveClient
1639
1619
  projects: ObservableProjectsClient
1640
1620
  users: ObservableUsersClient
1641
- assist: ObservableAssistClient
1642
1621
  /**
1643
1622
  * Instance properties
1644
1623
  */
@@ -2133,6 +2112,12 @@ export declare class ObservableSanityClient {
2133
2112
  * @param path - Path to append after the operation
2134
2113
  */
2135
2114
  getDataUrl(operation: string, path?: string): string
2115
+ instruct(request: InstructAsyncInstruction): Observable<{
2116
+ _id: string
2117
+ }>
2118
+ instruct<DocumentShape extends Record<string, Any>>(
2119
+ request: InstructSyncInstruction<DocumentShape>,
2120
+ ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
2136
2121
  }
2137
2122
 
2138
2123
  /** @public */
@@ -2558,7 +2543,6 @@ export declare class SanityClient {
2558
2543
  live: LiveClient
2559
2544
  projects: ProjectsClient
2560
2545
  users: UsersClient
2561
- assist: AssistClient
2562
2546
  /**
2563
2547
  * Observable version of the Sanity client, with the same configuration as the promise-based one
2564
2548
  */
@@ -3073,6 +3057,12 @@ export declare class SanityClient {
3073
3057
  * @param path - Path to append after the operation
3074
3058
  */
3075
3059
  getDataUrl(operation: string, path?: string): string
3060
+ instruct(request: InstructAsyncInstruction): Promise<{
3061
+ _id: string
3062
+ }>
3063
+ instruct<DocumentShape extends Record<string, Any>>(
3064
+ request: InstructSyncInstruction<DocumentShape>,
3065
+ ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
3076
3066
  }
3077
3067
 
3078
3068
  /** @internal */
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.token || config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
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,
@@ -837,42 +837,6 @@ function optionsFromFile(opts, file) {
837
837
  opts
838
838
  );
839
839
  }
840
- function _instruct(client, httpRequest, request) {
841
- const dataset2 = hasDataset(client.config());
842
- return _request(client, httpRequest, {
843
- method: "POST",
844
- uri: `/assist/tasks/instruct/${dataset2}`,
845
- body: request
846
- });
847
- }
848
- class ObservableAssistClient {
849
- #client;
850
- #httpRequest;
851
- constructor(client, httpRequest) {
852
- this.#client = client, this.#httpRequest = httpRequest;
853
- }
854
- /**
855
- * Run an ad-hoc instruction for a target document.
856
- * @param request instruction request
857
- */
858
- instruct(request) {
859
- return _instruct(this.#client, this.#httpRequest, request);
860
- }
861
- }
862
- class AssistClient {
863
- #client;
864
- #httpRequest;
865
- constructor(client, httpRequest) {
866
- this.#client = client, this.#httpRequest = httpRequest;
867
- }
868
- /**
869
- * Run an ad-hoc instruction for a target document.
870
- * @param request instruction request
871
- */
872
- instruct(request) {
873
- return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
874
- }
875
- }
876
840
  var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = typeof obj[prop] > "u" ? defaults2[prop] : obj[prop], target), {});
877
841
  const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => import("@sanity/eventsource")).pipe(
878
842
  map(({ default: EventSource2 }) => EventSource2),
@@ -901,7 +865,7 @@ function _listen(query, params, opts = {}) {
901
865
  if (uri.length > MAX_URL_LENGTH)
902
866
  return throwError(() => new Error("Query too large for listener"));
903
867
  const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
904
- return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
868
+ return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
905
869
  Authorization: `Bearer ${token}`
906
870
  }), connectEventSource(() => (
907
871
  // use polyfill if there is no global EventSource or if we need to set headers
@@ -1124,6 +1088,14 @@ function _modify(client, httpRequest, method, name2, options) {
1124
1088
  tag: null
1125
1089
  });
1126
1090
  }
1091
+ function _instruct(client, httpRequest, request) {
1092
+ const dataset2 = hasDataset(client.config());
1093
+ return _request(client, httpRequest, {
1094
+ method: "POST",
1095
+ uri: `/assist/tasks/instruct/${dataset2}`,
1096
+ body: request
1097
+ });
1098
+ }
1127
1099
  class ObservableProjectsClient {
1128
1100
  #client;
1129
1101
  #httpRequest;
@@ -1208,7 +1180,6 @@ class ObservableSanityClient {
1208
1180
  live;
1209
1181
  projects;
1210
1182
  users;
1211
- assist;
1212
1183
  /**
1213
1184
  * Private properties
1214
1185
  */
@@ -1219,7 +1190,7 @@ class ObservableSanityClient {
1219
1190
  */
1220
1191
  listen = _listen;
1221
1192
  constructor(httpRequest, config = defaultConfig) {
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.assist = new ObservableAssistClient(this, this.#httpRequest);
1193
+ 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);
1223
1194
  }
1224
1195
  /**
1225
1196
  * Clone the client - returns a new instance
@@ -1351,6 +1322,13 @@ class ObservableSanityClient {
1351
1322
  getDataUrl(operation, path) {
1352
1323
  return _getDataUrl(this, operation, path);
1353
1324
  }
1325
+ /**
1326
+ * Run an ad-hoc instruction for a target document.
1327
+ * @param request instruction request
1328
+ */
1329
+ instruct(request) {
1330
+ return _instruct(this, this.#httpRequest, request);
1331
+ }
1354
1332
  }
1355
1333
  class SanityClient {
1356
1334
  assets;
@@ -1358,7 +1336,6 @@ class SanityClient {
1358
1336
  live;
1359
1337
  projects;
1360
1338
  users;
1361
- assist;
1362
1339
  /**
1363
1340
  * Observable version of the Sanity client, with the same configuration as the promise-based one
1364
1341
  */
@@ -1373,7 +1350,7 @@ class SanityClient {
1373
1350
  */
1374
1351
  listen = _listen;
1375
1352
  constructor(httpRequest, config = defaultConfig) {
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.assist = new AssistClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
1353
+ 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);
1377
1354
  }
1378
1355
  /**
1379
1356
  * Clone the client - returns a new instance
@@ -1529,6 +1506,13 @@ class SanityClient {
1529
1506
  getDataUrl(operation, path) {
1530
1507
  return _getDataUrl(this, operation, path);
1531
1508
  }
1509
+ /**
1510
+ * Run an ad-hoc instruction for a target document.
1511
+ * @param request instruction request
1512
+ */
1513
+ instruct(request) {
1514
+ return lastValueFrom(_instruct(this, this.#httpRequest, request));
1515
+ }
1532
1516
  }
1533
1517
  function defineCreateClientExports(envMiddleware, ClassConstructor) {
1534
1518
  return { requester: defineHttpRequest(envMiddleware), createClient: (config) => {
@@ -1549,7 +1533,7 @@ function defineDeprecatedCreateClient(createClient2) {
1549
1533
  return printNoDefaultExport(), createClient2(config);
1550
1534
  };
1551
1535
  }
1552
- var name = "@sanity/client", version = "6.28.3-instruct.0";
1536
+ var name = "@sanity/client", version = "6.28.3-instruct.2";
1553
1537
  const middleware = [
1554
1538
  debug({ verbose: !0, namespace: "sanity:client" }),
1555
1539
  headers({ "User-Agent": `${name} ${version}` }),