@sanity/client 6.28.4-beta.0 → 6.28.4-generate.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'
@@ -39,6 +41,18 @@ export declare interface ActionErrorItem {
39
41
  index: number
40
42
  }
41
43
 
44
+ /** @public */
45
+ declare class AgentActionsClient {
46
+ #private
47
+ constructor(client: SanityClient, httpRequest: HttpRequest)
48
+ generate(request: GenerateAsyncInstruction): Promise<{
49
+ _id: string
50
+ }>
51
+ generate<DocumentShape extends Record<string, Any>>(
52
+ request: GenerateSyncInstruction<DocumentShape>,
53
+ ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
54
+ }
55
+
42
56
  /** @internal */
43
57
  export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
44
58
  returnFirst: false
@@ -116,6 +130,18 @@ export declare class AssetsClient {
116
130
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
117
131
  }
118
132
 
133
+ declare interface Async {
134
+ /**
135
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
136
+ * The instruction operation will carry on in the background.
137
+ *
138
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
139
+ *
140
+ * async: true is incompatible with skipWrite, as async: true does not return the resulting document
141
+ */
142
+ async: true
143
+ }
144
+
119
145
  /** @internal */
120
146
  export declare type AttributeSet = {
121
147
  [key: string]: Any
@@ -578,6 +604,19 @@ export declare type CreateAction = {
578
604
  */
579
605
  export declare const createClient: (config: ClientConfig) => SanityClient
580
606
 
607
+ /**
608
+ * Instruction to create a new document
609
+ * @beta
610
+ */
611
+ declare interface CreateDocumentRequest<T extends Record<string, Any_2> = Record<string, Any_2>> {
612
+ createDocument: {
613
+ /** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
614
+ _id?: string
615
+ _type: string
616
+ } & SanityDocumentStub_2<T>
617
+ documentId?: never
618
+ }
619
+
581
620
  /** @public */
582
621
  export declare interface CurrentSanityUser {
583
622
  id: string
@@ -771,6 +810,15 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
771
810
  */
772
811
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
773
812
 
813
+ /**
814
+ * Instruction for an existing document.
815
+ * @beta
816
+ */
817
+ declare interface ExistingDocumentRequest {
818
+ documentId: string
819
+ createDocument?: never
820
+ }
821
+
774
822
  /** @public */
775
823
  export declare type FilterDefault = (props: {
776
824
  /**
@@ -837,6 +885,310 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
837
885
  returnDocuments?: true
838
886
  }
839
887
 
888
+ /** @beta */
889
+ export declare type GenerateAsyncInstruction<
890
+ T extends Record<string, Any_2> = Record<string, Any_2>,
891
+ > = (ExistingDocumentRequest | CreateDocumentRequest<T>) & GenerateRequestBase & Async
892
+
893
+ /** @beta */
894
+ export declare interface GenerateConstantInstructionParam {
895
+ type: 'constant'
896
+ value: string
897
+ }
898
+
899
+ /**
900
+ *
901
+ * Includes a LLM-friendly version of the document in the instruction
902
+ * @beta
903
+ * */
904
+ declare interface GenerateDocumentInstructionParam {
905
+ type: 'document'
906
+ /**
907
+ * If omitted, implicitly uses the documentId of the instruction target
908
+ */
909
+ documentId?: string
910
+ }
911
+
912
+ /**
913
+ *
914
+ * Includes a LLM-friendly version of the field value in the instruction
915
+ * @beta
916
+ * */
917
+ export declare interface GenerateFieldInstructionParam {
918
+ type: 'field'
919
+ /**
920
+ * Examples: 'title', 'array[_key=="key"].field'
921
+ */
922
+ path: string
923
+ /**
924
+ * If omitted, implicitly uses the documentId of the instruction target
925
+ */
926
+ documentId?: string
927
+ }
928
+
929
+ /**
930
+ * Includes a LLM-friendly version of GROQ query result in the instruction
931
+ * @beta
932
+ * */
933
+ export declare interface GenerateGroqInstructionParam {
934
+ type: 'groq'
935
+ query: string
936
+ params?: Record<string, string>
937
+ }
938
+
939
+ /** @beta */
940
+ export declare type GenerateInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
941
+ | GenerateSyncInstruction<T>
942
+ | GenerateAsyncInstruction<T>
943
+
944
+ /** @beta */
945
+ export declare type GenerateInstructionParam =
946
+ | string
947
+ | GenerateConstantInstructionParam
948
+ | GenerateFieldInstructionParam
949
+ | GenerateDocumentInstructionParam
950
+ | GenerateGroqInstructionParam
951
+
952
+ /** @beta */
953
+ export declare type GenerateInstructionParams = Record<string, GenerateInstructionParam>
954
+
955
+ declare type GenerateOperation = 'set' | 'append' | 'mixed'
956
+
957
+ declare type GeneratePath = GeneratePathSegment[]
958
+
959
+ declare type GeneratePathSegment =
960
+ | string
961
+ | {
962
+ _key: string
963
+ }
964
+
965
+ declare interface GenerateRequestBase {
966
+ /** schemaId as reported by sanity deploy / sanity schema store */
967
+ schemaId: string
968
+ /** string template using $variable – more on this below under "Dynamic instruction" */
969
+ instruction: string
970
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
971
+ instructionParams?: GenerateInstructionParams
972
+ /**
973
+ * Target defines which parts of the document will be affected by the instruction.
974
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
975
+ *
976
+ * Omitting target implies that the document itself is the root.
977
+ *
978
+ * Notes:
979
+ * - instruction can only affect fields up to `maxPathDepth`
980
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
981
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
982
+ *
983
+ * @see GenerateRequestBase#conditionalPaths
984
+ */
985
+ target?: GenerateTarget | GenerateTarget[]
986
+ /**
987
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
988
+ *
989
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
990
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
991
+ *
992
+ * `conditionalPaths` param allows setting the default conditional value for
993
+ * `hidden` and `readOnly` to false,
994
+ * or individually set `hidden` and `readOnly` state for individual document paths.
995
+ *
996
+ *
997
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
998
+ * and cannot be changed via conditionalPaths
999
+ *
1000
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
1001
+ *
1002
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
1003
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
1004
+ *
1005
+ * @see GenerateRequestBase#target
1006
+ */
1007
+ conditionalPaths?: {
1008
+ defaultReadOnly?: boolean
1009
+ defaultHidden?: boolean
1010
+ paths?: {
1011
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
1012
+ path: GeneratePath
1013
+ readOnly: boolean
1014
+ hidden: boolean
1015
+ }[]
1016
+ }
1017
+ /**
1018
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
1019
+ * Otherwise, such fields will be ignored.
1020
+ */
1021
+ localeSettings?: {
1022
+ /**
1023
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
1024
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
1025
+ *
1026
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
1027
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
1028
+ *
1029
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
1030
+ */
1031
+ locale: string
1032
+ /**
1033
+ * A valid IANA time zone identifier used to resolve relative and absolute
1034
+ * date expressions to a specific point in time. Examples include
1035
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
1036
+ *
1037
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
1038
+ * based on the user's local time.
1039
+ *
1040
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
1041
+ */
1042
+ timeZone: string
1043
+ }
1044
+ /**
1045
+ * Controls how much variance the instructions will run with.
1046
+ *
1047
+ * Value must be in the range [0, 1] (inclusive).
1048
+ *
1049
+ * Default: 0.3
1050
+ */
1051
+ temperature?: number
1052
+ }
1053
+
1054
+ /** @beta */
1055
+ export declare type GenerateSyncInstruction<
1056
+ T extends Record<string, Any_2> = Record<string, Any_2>,
1057
+ > = (ExistingDocumentRequest | CreateDocumentRequest<T>) & GenerateRequestBase & Sync
1058
+
1059
+ /**
1060
+ * @beta
1061
+ */
1062
+ declare interface GenerateTarget {
1063
+ /**
1064
+ * Root target path.
1065
+ *
1066
+ * Use this to have the instruction only affect a part of the document.
1067
+ *
1068
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
1069
+ * and `types.exclude`.
1070
+ *
1071
+ * Example:
1072
+ *
1073
+ * `path: ['body', {_key: 'someKey'}, 'nestedObject']`
1074
+ *
1075
+ * Here, the instruction will only write to fields under the nestedObject.
1076
+ *
1077
+ * Default: [] = the document itself
1078
+ *
1079
+ * @see #GeneratePathSegment
1080
+ * @see #GeneratePath
1081
+ * */
1082
+ path?: GeneratePathSegment | GeneratePath
1083
+ /**
1084
+ * Sets the default operation for all paths in the target.
1085
+ * Generate runs in `'mixed'` operation mode by default:
1086
+ * Changes are set in all non-array fields, and append to all array fields.
1087
+ *
1088
+ * ### Operation types
1089
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1090
+ * - `'append'`:
1091
+ * – array fields: appends new items to the end of the array,
1092
+ * - string fields: '<existing content> <new content>'
1093
+ * - text fields: '<existing content>\n<new content>'
1094
+ * - number fields: existing + new
1095
+ * - other field types not mentioned will set instead (dates, url)
1096
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1097
+ *
1098
+ * The default operation can be overridden on a per-path basis using `include`.
1099
+ *
1100
+ * Nested fields inherit the operation specified by their parent and falls back to the
1101
+ * top level target operation if not otherwise specified.
1102
+ *
1103
+ * Use `include` to change the `operation` of individual fields or items.
1104
+ *
1105
+ * #### Appending in the middle of arrays
1106
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1107
+ *
1108
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1109
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1110
+ *
1111
+ * @see #GenerateTargetInclude.operation
1112
+ * @see #include
1113
+ * @see #GenerateTargetInclude.include
1114
+ */
1115
+ operation?: GenerateOperation
1116
+ /**
1117
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
1118
+ *
1119
+ * Depth is based on path segments:
1120
+ * - `title` has depth 1
1121
+ * - `array[_key="no"].title` has depth 3
1122
+ *
1123
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
1124
+ * negative impact on performance; both for runtime and quality of responses.
1125
+ *
1126
+ * Default: 4
1127
+ */
1128
+ maxPathDepth?: number
1129
+ /**
1130
+ * By default, all children up to `target.maxPathDepth` are included.
1131
+ *
1132
+ * When `include` is specified, only segments explicitly listed will be included.
1133
+ *
1134
+ * Fields or array items not on the include list, are implicitly excluded.
1135
+ */
1136
+ include?: (GeneratePathSegment | GenerateTargetInclude)[]
1137
+ /**
1138
+ * By default, all children up to `target.maxPathDepth` are included.
1139
+ * Fields or array items not on the exclude list, are implicitly included.
1140
+ */
1141
+ exclude?: GeneratePathSegment[]
1142
+ /**
1143
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1144
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1145
+ *
1146
+ * `types.include` and `types.exclude` are mutually exclusive.
1147
+ */
1148
+ types?: GenerateTypeConfig
1149
+ }
1150
+
1151
+ declare interface GenerateTargetInclude {
1152
+ path: GeneratePathSegment | GeneratePath
1153
+ /**
1154
+ * Sets the operation for this path, and all its children.
1155
+ * This overrides any operation set parents or the root target.
1156
+ * @see #GenerateTarget.operation
1157
+ * @see #include
1158
+ */
1159
+ operation?: GenerateOperation
1160
+ /**
1161
+ * By default, all children up to `target.maxPathDepth` are included.
1162
+ *
1163
+ * When `include` is specified, only segments explicitly listed will be included.
1164
+ *
1165
+ * Fields or array items not on the include list, are implicitly excluded.
1166
+ */
1167
+ include?: (GeneratePathSegment | GenerateTargetInclude)[]
1168
+ /**
1169
+ * By default, all children up to `target.maxPathDepth` are included.
1170
+ * Fields or array items not on the exclude list, are implicitly included.
1171
+ */
1172
+ exclude?: GeneratePathSegment[]
1173
+ /**
1174
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1175
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1176
+ *
1177
+ * `types.include` and `types.exclude` are mutually exclusive.
1178
+ */
1179
+ types?: GenerateTypeConfig
1180
+ }
1181
+
1182
+ declare type GenerateTypeConfig =
1183
+ | {
1184
+ include: string[]
1185
+ exclude?: never
1186
+ }
1187
+ | {
1188
+ exclude: string[]
1189
+ include?: never
1190
+ }
1191
+
840
1192
  /** @public */
841
1193
  export declare type HttpRequest = {
842
1194
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1257,6 +1609,18 @@ export declare type MutationSelectionQueryParams = {
1257
1609
  [key: string]: Any
1258
1610
  }
1259
1611
 
1612
+ /** @public */
1613
+ declare class ObservableAgentsActionClient {
1614
+ #private
1615
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1616
+ generate(request: GenerateAsyncInstruction): Observable<{
1617
+ _id: string
1618
+ }>
1619
+ generate<DocumentShape extends Record<string, Any>>(
1620
+ request: GenerateSyncInstruction<DocumentShape>,
1621
+ ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1622
+ }
1623
+
1260
1624
  /** @internal */
1261
1625
  export declare class ObservableAssetsClient {
1262
1626
  #private
@@ -1434,6 +1798,9 @@ export declare class ObservableSanityClient {
1434
1798
  live: LiveClient
1435
1799
  projects: ObservableProjectsClient
1436
1800
  users: ObservableUsersClient
1801
+ agent: {
1802
+ action: ObservableAgentsActionClient
1803
+ }
1437
1804
  /**
1438
1805
  * Instance properties
1439
1806
  */
@@ -2353,6 +2720,9 @@ export declare class SanityClient {
2353
2720
  live: LiveClient
2354
2721
  projects: ProjectsClient
2355
2722
  users: UsersClient
2723
+ agent: {
2724
+ action: AgentActionsClient
2725
+ }
2356
2726
  /**
2357
2727
  * Observable version of the Sanity client, with the same configuration as the promise-based one
2358
2728
  */
@@ -3067,6 +3437,29 @@ export {StudioBaseUrl}
3067
3437
 
3068
3438
  export {StudioUrl}
3069
3439
 
3440
+ declare interface Sync {
3441
+ /**
3442
+ * By default, skipWrite: false.
3443
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
3444
+ *
3445
+ * When skipWrite: true, the api will not mutate any documents nor emit presence.
3446
+ * Ie, when true, no changes will be made to content-lake
3447
+ *
3448
+ * skipWrite: true is incompatible with async: true,
3449
+ * as skipWrite implies that you will use the return value of the operation
3450
+ */
3451
+ skipWrite?: boolean
3452
+ /**
3453
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
3454
+ * The instruction operation will carry on in the background.
3455
+ *
3456
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
3457
+ *
3458
+ * async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
3459
+ */
3460
+ async?: false
3461
+ }
3462
+
3070
3463
  /** @public */
3071
3464
  export declare type SyncTag = `s1:${string}`
3072
3465