@sanity/client 6.28.1 → 6.28.3-instruct.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.
package/dist/index.d.cts CHANGED
@@ -1,9 +1,11 @@
1
+ import type {Any as Any_2} from '@sanity/client'
1
2
  import type {ContentSourceMapDocuments as ContentSourceMapDocuments_2} from '@sanity/client/csm'
2
3
  import {ContentSourceMapParsedPath} from '@sanity/client/csm'
3
4
  import {ContentSourceMapParsedPathKeyedSegment} from '@sanity/client/csm'
4
5
  import {Observable} from 'rxjs'
5
6
  import {Requester} from 'get-it'
6
7
  import type {ResolveStudioUrl} from '@sanity/client/csm'
8
+ import type {SanityDocumentStub as SanityDocumentStub_2} from '@sanity/client'
7
9
  import {StudioBaseRoute} from '@sanity/client/csm'
8
10
  import {StudioBaseUrl} from '@sanity/client/csm'
9
11
  import {StudioUrl} from '@sanity/client/csm'
@@ -116,6 +118,122 @@ export declare class AssetsClient {
116
118
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
117
119
  }
118
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
+ declare interface Async {
226
+ /**
227
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
228
+ * The instruction operation will carry on in the background.
229
+ *
230
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
231
+ *
232
+ * async: true is incompatible with skipWrite, as async: true does not return the resulting document
233
+ */
234
+ async: true
235
+ }
236
+
119
237
  /** @internal */
120
238
  export declare type AttributeSet = {
121
239
  [key: string]: Any
@@ -342,14 +460,14 @@ export declare interface ClientConfig {
342
460
  /**
343
461
  * What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
344
462
  * @remarks
345
- * As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
463
+ * As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
346
464
  * @defaultValue 'published'
347
465
  */
348
466
  perspective?: ClientPerspective
349
467
  apiHost?: string
350
468
  /**
351
469
  @remarks
352
- * As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
470
+ * As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
353
471
  */
354
472
  apiVersion?: string
355
473
  proxy?: string
@@ -455,6 +573,12 @@ export declare class ConnectionFailedError extends Error {
455
573
  readonly name = 'ConnectionFailedError'
456
574
  }
457
575
 
576
+ /** @beta */
577
+ export declare interface ConstantInstructionParam {
578
+ type: 'constant'
579
+ value: string
580
+ }
581
+
458
582
  /** @public */
459
583
  export declare interface ContentSourceMap {
460
584
  mappings: ContentSourceMapMappings
@@ -573,12 +697,24 @@ export declare type CreateAction = {
573
697
 
574
698
  /**
575
699
  * @remarks
576
- * As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog}
700
+ * As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
577
701
  * @public
578
702
  */
579
703
  export declare const createClient: (config: ClientConfig) => SanityClient
580
704
 
581
- /** @internal */
705
+ /**
706
+ * Instruction to create a new document
707
+ * @beta
708
+ */
709
+ declare interface CreateDocumentRequest<T extends Record<string, Any_2> = Record<string, Any_2>> {
710
+ createDocument: {
711
+ /** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
712
+ _id?: string
713
+ _type: string
714
+ } & SanityDocumentStub_2<T>
715
+ }
716
+
717
+ /** @public */
582
718
  export declare interface CurrentSanityUser {
583
719
  id: string
584
720
  name: string
@@ -587,10 +723,10 @@ export declare interface CurrentSanityUser {
587
723
  role: string
588
724
  }
589
725
 
590
- /** @internal */
726
+ /** @public */
591
727
  export declare type DatasetAclMode = 'public' | 'private' | 'custom'
592
728
 
593
- /** @internal */
729
+ /** @public */
594
730
  export declare type DatasetResponse = {
595
731
  datasetName: string
596
732
  aclMode: DatasetAclMode
@@ -638,7 +774,7 @@ export declare class DatasetsClient {
638
774
  list(): Promise<DatasetsResponse>
639
775
  }
640
776
 
641
- /** @internal */
777
+ /** @public */
642
778
  export declare type DatasetsResponse = {
643
779
  name: string
644
780
  aclMode: DatasetAclMode
@@ -729,6 +865,19 @@ export declare type DisconnectEvent = {
729
865
  reason: string
730
866
  }
731
867
 
868
+ /**
869
+ *
870
+ * Includes a LLM-friendly version of the document in the instruction
871
+ * @beta
872
+ * */
873
+ declare interface DocumentInstructionParam {
874
+ type: 'document'
875
+ /**
876
+ * If omitted, implicitly uses the documentId of the instruction target
877
+ */
878
+ documentId?: string
879
+ }
880
+
732
881
  /**
733
882
  * Modifies an existing draft document.
734
883
  * It applies the given patch to the document referenced by draftId.
@@ -771,6 +920,31 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
771
920
  */
772
921
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
773
922
 
923
+ /**
924
+ * Instruction for an existing document.
925
+ * @beta
926
+ */
927
+ declare interface ExistingDocumentRequest {
928
+ documentId: string
929
+ }
930
+
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
+
774
948
  /** @public */
775
949
  export declare type FilterDefault = (props: {
776
950
  /**
@@ -837,6 +1011,13 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
837
1011
  returnDocuments?: true
838
1012
  }
839
1013
 
1014
+ /** @beta */
1015
+ export declare interface GroqInstructionParam {
1016
+ type: 'groq'
1017
+ query: string
1018
+ params?: Record<string, string>
1019
+ }
1020
+
840
1021
  /** @public */
841
1022
  export declare type HttpRequest = {
842
1023
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -897,6 +1078,17 @@ export declare type InsertPatch =
897
1078
  items: Any[]
898
1079
  }
899
1080
 
1081
+ /** @beta */
1082
+ export declare type InstructionParam =
1083
+ | string
1084
+ | ConstantInstructionParam
1085
+ | FieldInstructionParam
1086
+ | DocumentInstructionParam
1087
+ | GroqInstructionParam
1088
+
1089
+ /** @beta */
1090
+ export declare type InstructionParams = Record<string, InstructionParam>
1091
+
900
1092
  /**
901
1093
  * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
902
1094
  *
@@ -968,7 +1160,7 @@ export declare interface ListenOptions {
968
1160
  includePreviousRevision?: boolean
969
1161
  /**
970
1162
  * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
971
- * for published documents will be included by default (see {@link https://www.sanity.io/changelog/e93a2d5a-9cee-4801-829e-8d3394bfed85|Changelog})
1163
+ * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
972
1164
  * If you need events from drafts and versions, set this to `true`.
973
1165
  * Note: Keep in mind that additional document variants may be introduced in the future, so it's
974
1166
  * recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
@@ -1311,6 +1503,18 @@ export declare class ObservableAssetsClient {
1311
1503
  >
1312
1504
  }
1313
1505
 
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
+
1314
1518
  /** @internal */
1315
1519
  export declare class ObservableDatasetsClient {
1316
1520
  #private
@@ -1434,6 +1638,7 @@ export declare class ObservableSanityClient {
1434
1638
  live: LiveClient
1435
1639
  projects: ObservableProjectsClient
1436
1640
  users: ObservableUsersClient
1641
+ assist: ObservableAssistClient
1437
1642
  /**
1438
1643
  * Instance properties
1439
1644
  */
@@ -2353,6 +2558,7 @@ export declare class SanityClient {
2353
2558
  live: LiveClient
2354
2559
  projects: ProjectsClient
2355
2560
  users: UsersClient
2561
+ assist: AssistClient
2356
2562
  /**
2357
2563
  * Observable version of the Sanity client, with the same configuration as the promise-based one
2358
2564
  */
@@ -2934,7 +3140,7 @@ export declare interface SanityImagePalette {
2934
3140
  title: string
2935
3141
  }
2936
3142
 
2937
- /** @internal */
3143
+ /** @public */
2938
3144
  export declare interface SanityProject {
2939
3145
  id: string
2940
3146
  displayName: string
@@ -2962,7 +3168,7 @@ export declare interface SanityProject {
2962
3168
  }
2963
3169
  }
2964
3170
 
2965
- /** @internal */
3171
+ /** @public */
2966
3172
  export declare interface SanityProjectMember {
2967
3173
  id: string
2968
3174
  role: string
@@ -2978,7 +3184,7 @@ export declare interface SanityReference {
2978
3184
  _ref: string
2979
3185
  }
2980
3186
 
2981
- /** @internal */
3187
+ /** @public */
2982
3188
  export declare interface SanityUser {
2983
3189
  id: string
2984
3190
  projectId: string
@@ -3067,6 +3273,29 @@ export {StudioBaseUrl}
3067
3273
 
3068
3274
  export {StudioUrl}
3069
3275
 
3276
+ declare interface Sync {
3277
+ /**
3278
+ * By default, skipWrite: false.
3279
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
3280
+ *
3281
+ * When skipWrite: true, the api will not mutate any documents nor emit presence.
3282
+ * Ie, when true, no changes will be made to content-lake
3283
+ *
3284
+ * skipWrite: true is incompatible with async: true,
3285
+ * as skipWrite implies that you will use the return value of the operation
3286
+ */
3287
+ skipWrite?: boolean
3288
+ /**
3289
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
3290
+ * The instruction operation will carry on in the background.
3291
+ *
3292
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
3293
+ *
3294
+ * async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
3295
+ */
3296
+ async?: false
3297
+ }
3298
+
3070
3299
  /** @public */
3071
3300
  export declare type SyncTag = `s1:${string}`
3072
3301