@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/stega.d.cts CHANGED
@@ -33,6 +33,18 @@ export declare interface ActionErrorItem {
33
33
  index: number
34
34
  }
35
35
 
36
+ /** @public */
37
+ declare class AgentActionsClient {
38
+ #private
39
+ constructor(client: SanityClient, httpRequest: HttpRequest)
40
+ generate(request: GenerateAsyncInstruction): Promise<{
41
+ _id: string
42
+ }>
43
+ generate<DocumentShape extends Record<string, Any>>(
44
+ request: GenerateSyncInstruction<DocumentShape>,
45
+ ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
46
+ }
47
+
36
48
  /** @internal */
37
49
  export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
38
50
  returnFirst: false
@@ -110,6 +122,18 @@ export declare class AssetsClient {
110
122
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
111
123
  }
112
124
 
125
+ declare interface Async {
126
+ /**
127
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
128
+ * The instruction operation will carry on in the background.
129
+ *
130
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
131
+ *
132
+ * async: true is incompatible with skipWrite, as async: true does not return the resulting document
133
+ */
134
+ async: true
135
+ }
136
+
113
137
  /** @internal */
114
138
  export declare type AttributeSet = {
115
139
  [key: string]: Any
@@ -673,6 +697,19 @@ export declare type CreateAction = {
673
697
  */
674
698
  export declare const createClient: (config: ClientConfig_2) => SanityClient
675
699
 
700
+ /**
701
+ * Instruction to create a new document
702
+ * @beta
703
+ */
704
+ declare interface CreateDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
705
+ createDocument: {
706
+ /** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
707
+ _id?: string
708
+ _type: string
709
+ } & SanityDocumentStub<T>
710
+ documentId?: never
711
+ }
712
+
676
713
  /** @public */
677
714
  export declare interface CurrentSanityUser {
678
715
  id: string
@@ -878,6 +915,15 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
878
915
  */
879
916
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
880
917
 
918
+ /**
919
+ * Instruction for an existing document.
920
+ * @beta
921
+ */
922
+ declare interface ExistingDocumentRequest {
923
+ documentId: string
924
+ createDocument?: never
925
+ }
926
+
881
927
  /** @public */
882
928
  export declare type FilterDefault = (props: {
883
929
  /**
@@ -993,6 +1039,312 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
993
1039
  returnDocuments?: true
994
1040
  }
995
1041
 
1042
+ /** @beta */
1043
+ export declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> =
1044
+ (ExistingDocumentRequest | CreateDocumentRequest<T>) & GenerateRequestBase & Async
1045
+
1046
+ /** @beta */
1047
+ export declare interface GenerateConstantInstructionParam {
1048
+ type: 'constant'
1049
+ value: string
1050
+ }
1051
+
1052
+ /**
1053
+ *
1054
+ * Includes a LLM-friendly version of the document in the instruction
1055
+ * @beta
1056
+ * */
1057
+ declare interface GenerateDocumentInstructionParam {
1058
+ type: 'document'
1059
+ /**
1060
+ * If omitted, implicitly uses the documentId of the instruction target
1061
+ */
1062
+ documentId?: string
1063
+ }
1064
+
1065
+ /**
1066
+ *
1067
+ * Includes a LLM-friendly version of the field value in the instruction
1068
+ * @beta
1069
+ * */
1070
+ export declare interface GenerateFieldInstructionParam {
1071
+ type: 'field'
1072
+ /**
1073
+ * Examples: 'title', 'array[_key=="key"].field'
1074
+ */
1075
+ path: string
1076
+ /**
1077
+ * If omitted, implicitly uses the documentId of the instruction target
1078
+ */
1079
+ documentId?: string
1080
+ }
1081
+
1082
+ /**
1083
+ * Includes a LLM-friendly version of GROQ query result in the instruction
1084
+ * @beta
1085
+ * */
1086
+ export declare interface GenerateGroqInstructionParam {
1087
+ type: 'groq'
1088
+ query: string
1089
+ params?: Record<string, string>
1090
+ }
1091
+
1092
+ /** @beta */
1093
+ export declare type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> =
1094
+ | GenerateSyncInstruction<T>
1095
+ | GenerateAsyncInstruction<T>
1096
+
1097
+ /** @beta */
1098
+ export declare type GenerateInstructionParam =
1099
+ | string
1100
+ | GenerateConstantInstructionParam
1101
+ | GenerateFieldInstructionParam
1102
+ | GenerateDocumentInstructionParam
1103
+ | GenerateGroqInstructionParam
1104
+
1105
+ /** @beta */
1106
+ export declare type GenerateInstructionParams = Record<string, GenerateInstructionParam>
1107
+
1108
+ declare type GenerateOperation = 'set' | 'append' | 'mixed'
1109
+
1110
+ declare type GeneratePath = GeneratePathSegment[]
1111
+
1112
+ declare type GeneratePathSegment =
1113
+ | string
1114
+ | {
1115
+ _key: string
1116
+ }
1117
+
1118
+ declare interface GenerateRequestBase {
1119
+ /** schemaId as reported by sanity deploy / sanity schema store */
1120
+ schemaId: string
1121
+ /** string template using $variable – more on this below under "Dynamic instruction" */
1122
+ instruction: string
1123
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
1124
+ instructionParams?: GenerateInstructionParams
1125
+ /**
1126
+ * Target defines which parts of the document will be affected by the instruction.
1127
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
1128
+ *
1129
+ * Omitting target implies that the document itself is the root.
1130
+ *
1131
+ * Notes:
1132
+ * - instruction can only affect fields up to `maxPathDepth`
1133
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1134
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1135
+ *
1136
+ * @see GenerateRequestBase#conditionalPaths
1137
+ */
1138
+ target?: GenerateTarget | GenerateTarget[]
1139
+ /**
1140
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
1141
+ *
1142
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
1143
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
1144
+ *
1145
+ * `conditionalPaths` param allows setting the default conditional value for
1146
+ * `hidden` and `readOnly` to false,
1147
+ * or individually set `hidden` and `readOnly` state for individual document paths.
1148
+ *
1149
+ *
1150
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
1151
+ * and cannot be changed via conditionalPaths
1152
+ *
1153
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
1154
+ *
1155
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
1156
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
1157
+ *
1158
+ * @see GenerateRequestBase#target
1159
+ */
1160
+ conditionalPaths?: {
1161
+ defaultReadOnly?: boolean
1162
+ defaultHidden?: boolean
1163
+ paths?: {
1164
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
1165
+ path: GeneratePath
1166
+ readOnly: boolean
1167
+ hidden: boolean
1168
+ }[]
1169
+ }
1170
+ /**
1171
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
1172
+ * Otherwise, such fields will be ignored.
1173
+ */
1174
+ localeSettings?: {
1175
+ /**
1176
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
1177
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
1178
+ *
1179
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
1180
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
1181
+ *
1182
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
1183
+ */
1184
+ locale: string
1185
+ /**
1186
+ * A valid IANA time zone identifier used to resolve relative and absolute
1187
+ * date expressions to a specific point in time. Examples include
1188
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
1189
+ *
1190
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
1191
+ * based on the user's local time.
1192
+ *
1193
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
1194
+ */
1195
+ timeZone: string
1196
+ }
1197
+ /**
1198
+ * Controls how much variance the instructions will run with.
1199
+ *
1200
+ * Value must be in the range [0, 1] (inclusive).
1201
+ *
1202
+ * Default: 0.3
1203
+ */
1204
+ temperature?: number
1205
+ }
1206
+
1207
+ /** @beta */
1208
+ export declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1209
+ | ExistingDocumentRequest
1210
+ | CreateDocumentRequest<T>
1211
+ ) &
1212
+ GenerateRequestBase &
1213
+ Sync
1214
+
1215
+ /**
1216
+ * @beta
1217
+ */
1218
+ declare interface GenerateTarget {
1219
+ /**
1220
+ * Root target path.
1221
+ *
1222
+ * Use this to have the instruction only affect a part of the document.
1223
+ *
1224
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
1225
+ * and `types.exclude`.
1226
+ *
1227
+ * Example:
1228
+ *
1229
+ * `path: ['body', {_key: 'someKey'}, 'nestedObject']`
1230
+ *
1231
+ * Here, the instruction will only write to fields under the nestedObject.
1232
+ *
1233
+ * Default: [] = the document itself
1234
+ *
1235
+ * @see #GeneratePathSegment
1236
+ * @see #GeneratePath
1237
+ * */
1238
+ path?: GeneratePathSegment | GeneratePath
1239
+ /**
1240
+ * Sets the default operation for all paths in the target.
1241
+ * Generate runs in `'mixed'` operation mode by default:
1242
+ * Changes are set in all non-array fields, and append to all array fields.
1243
+ *
1244
+ * ### Operation types
1245
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1246
+ * - `'append'`:
1247
+ * – array fields: appends new items to the end of the array,
1248
+ * - string fields: '<existing content> <new content>'
1249
+ * - text fields: '<existing content>\n<new content>'
1250
+ * - number fields: existing + new
1251
+ * - other field types not mentioned will set instead (dates, url)
1252
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1253
+ *
1254
+ * The default operation can be overridden on a per-path basis using `include`.
1255
+ *
1256
+ * Nested fields inherit the operation specified by their parent and falls back to the
1257
+ * top level target operation if not otherwise specified.
1258
+ *
1259
+ * Use `include` to change the `operation` of individual fields or items.
1260
+ *
1261
+ * #### Appending in the middle of arrays
1262
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1263
+ *
1264
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1265
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1266
+ *
1267
+ * @see #GenerateTargetInclude.operation
1268
+ * @see #include
1269
+ * @see #GenerateTargetInclude.include
1270
+ */
1271
+ operation?: GenerateOperation
1272
+ /**
1273
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
1274
+ *
1275
+ * Depth is based on path segments:
1276
+ * - `title` has depth 1
1277
+ * - `array[_key="no"].title` has depth 3
1278
+ *
1279
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
1280
+ * negative impact on performance; both for runtime and quality of responses.
1281
+ *
1282
+ * Default: 4
1283
+ */
1284
+ maxPathDepth?: number
1285
+ /**
1286
+ * By default, all children up to `target.maxPathDepth` are included.
1287
+ *
1288
+ * When `include` is specified, only segments explicitly listed will be included.
1289
+ *
1290
+ * Fields or array items not on the include list, are implicitly excluded.
1291
+ */
1292
+ include?: (GeneratePathSegment | GenerateTargetInclude)[]
1293
+ /**
1294
+ * By default, all children up to `target.maxPathDepth` are included.
1295
+ * Fields or array items not on the exclude list, are implicitly included.
1296
+ */
1297
+ exclude?: GeneratePathSegment[]
1298
+ /**
1299
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1300
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1301
+ *
1302
+ * `types.include` and `types.exclude` are mutually exclusive.
1303
+ */
1304
+ types?: GenerateTypeConfig
1305
+ }
1306
+
1307
+ declare interface GenerateTargetInclude {
1308
+ path: GeneratePathSegment | GeneratePath
1309
+ /**
1310
+ * Sets the operation for this path, and all its children.
1311
+ * This overrides any operation set parents or the root target.
1312
+ * @see #GenerateTarget.operation
1313
+ * @see #include
1314
+ */
1315
+ operation?: GenerateOperation
1316
+ /**
1317
+ * By default, all children up to `target.maxPathDepth` are included.
1318
+ *
1319
+ * When `include` is specified, only segments explicitly listed will be included.
1320
+ *
1321
+ * Fields or array items not on the include list, are implicitly excluded.
1322
+ */
1323
+ include?: (GeneratePathSegment | GenerateTargetInclude)[]
1324
+ /**
1325
+ * By default, all children up to `target.maxPathDepth` are included.
1326
+ * Fields or array items not on the exclude list, are implicitly included.
1327
+ */
1328
+ exclude?: GeneratePathSegment[]
1329
+ /**
1330
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1331
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1332
+ *
1333
+ * `types.include` and `types.exclude` are mutually exclusive.
1334
+ */
1335
+ types?: GenerateTypeConfig
1336
+ }
1337
+
1338
+ declare type GenerateTypeConfig =
1339
+ | {
1340
+ include: string[]
1341
+ exclude?: never
1342
+ }
1343
+ | {
1344
+ exclude: string[]
1345
+ include?: never
1346
+ }
1347
+
996
1348
  /** @public */
997
1349
  export declare type HttpRequest = {
998
1350
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1430,6 +1782,18 @@ export declare type MutationSelectionQueryParams = {
1430
1782
  [key: string]: Any
1431
1783
  }
1432
1784
 
1785
+ /** @public */
1786
+ declare class ObservableAgentsActionClient {
1787
+ #private
1788
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1789
+ generate(request: GenerateAsyncInstruction): Observable<{
1790
+ _id: string
1791
+ }>
1792
+ generate<DocumentShape extends Record<string, Any>>(
1793
+ request: GenerateSyncInstruction<DocumentShape>,
1794
+ ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1795
+ }
1796
+
1433
1797
  /** @internal */
1434
1798
  export declare class ObservableAssetsClient {
1435
1799
  #private
@@ -1607,6 +1971,9 @@ export declare class ObservableSanityClient {
1607
1971
  live: LiveClient
1608
1972
  projects: ObservableProjectsClient
1609
1973
  users: ObservableUsersClient
1974
+ agent: {
1975
+ action: ObservableAgentsActionClient
1976
+ }
1610
1977
  /**
1611
1978
  * Instance properties
1612
1979
  */
@@ -2538,6 +2905,9 @@ export declare class SanityClient {
2538
2905
  live: LiveClient
2539
2906
  projects: ProjectsClient
2540
2907
  users: UsersClient
2908
+ agent: {
2909
+ action: AgentActionsClient
2910
+ }
2541
2911
  /**
2542
2912
  * Observable version of the Sanity client, with the same configuration as the promise-based one
2543
2913
  */
@@ -3321,6 +3691,29 @@ export declare type StudioBaseUrl =
3321
3691
  /** @alpha */
3322
3692
  export declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
3323
3693
 
3694
+ declare interface Sync {
3695
+ /**
3696
+ * By default, skipWrite: false.
3697
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
3698
+ *
3699
+ * When skipWrite: true, the api will not mutate any documents nor emit presence.
3700
+ * Ie, when true, no changes will be made to content-lake
3701
+ *
3702
+ * skipWrite: true is incompatible with async: true,
3703
+ * as skipWrite implies that you will use the return value of the operation
3704
+ */
3705
+ skipWrite?: boolean
3706
+ /**
3707
+ * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
3708
+ * The instruction operation will carry on in the background.
3709
+ *
3710
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
3711
+ *
3712
+ * async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
3713
+ */
3714
+ async?: false
3715
+ }
3716
+
3324
3717
  /** @public */
3325
3718
  export declare type SyncTag = `s1:${string}`
3326
3719