@sanity/client 6.29.0-generate.0 → 6.29.1

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.
@@ -39,18 +39,6 @@ export declare interface ActionErrorItem {
39
39
  index: number
40
40
  }
41
41
 
42
- /** @public */
43
- declare class AgentActionsClient {
44
- #private
45
- constructor(client: SanityClient, httpRequest: HttpRequest)
46
- generate(request: GenerateAsyncInstruction): Promise<{
47
- _id: string
48
- }>
49
- generate<DocumentShape extends Record<string, Any>>(
50
- request: GenerateSyncInstruction<DocumentShape>,
51
- ): Promise<IdentifiedSanityDocumentStub & DocumentShape>
52
- }
53
-
54
42
  /** @internal */
55
43
  export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
56
44
  returnFirst: false
@@ -69,12 +57,6 @@ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
69
57
  */
70
58
  export declare type Any = any
71
59
 
72
- /**
73
- * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
74
- * @internal
75
- */
76
- declare type Any_2 = any
77
-
78
60
  /** @internal */
79
61
  export declare interface ApiError {
80
62
  error: string
@@ -134,18 +116,6 @@ export declare class AssetsClient {
134
116
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
135
117
  }
136
118
 
137
- declare interface Async {
138
- /**
139
- * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
140
- * The instruction operation will carry on in the background.
141
- *
142
- * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
143
- *
144
- * async: true is incompatible with noWrite, as async: true does not return the resulting document
145
- */
146
- async: true
147
- }
148
-
149
119
  /** @internal */
150
120
  export declare type AttributeSet = {
151
121
  [key: string]: Any
@@ -624,19 +594,6 @@ export declare type CreateAction = {
624
594
  /** @public */
625
595
  export declare const createClient: (config: ClientConfig) => SanityClient
626
596
 
627
- /**
628
- * Instruction to create a new document
629
- * @beta
630
- */
631
- declare interface CreateDocumentRequest<T extends Record<string, Any_2> = Record<string, Any_2>> {
632
- createDocument: {
633
- /** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
634
- _id?: string
635
- _type: string
636
- } & SanityDocumentStub_2<T>
637
- documentId?: never
638
- }
639
-
640
597
  /** @public */
641
598
  export declare interface CurrentSanityUser {
642
599
  id: string
@@ -830,15 +787,6 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
830
787
  */
831
788
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
832
789
 
833
- /**
834
- * Instruction for an existing document.
835
- * @beta
836
- */
837
- declare interface ExistingDocumentRequest {
838
- documentId: string
839
- createDocument?: never
840
- }
841
-
842
790
  /** @public */
843
791
  export declare type FilterDefault = (props: {
844
792
  /**
@@ -905,310 +853,6 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
905
853
  returnDocuments?: true
906
854
  }
907
855
 
908
- /** @beta */
909
- export declare type GenerateAsyncInstruction<
910
- T extends Record<string, Any_2> = Record<string, Any_2>,
911
- > = (ExistingDocumentRequest | CreateDocumentRequest<T>) & GenerateRequestBase & Async
912
-
913
- /** @beta */
914
- export declare interface GenerateConstantInstructionParam {
915
- type: 'constant'
916
- value: string
917
- }
918
-
919
- /**
920
- *
921
- * Includes a LLM-friendly version of the document in the instruction
922
- * @beta
923
- * */
924
- declare interface GenerateDocumentInstructionParam {
925
- type: 'document'
926
- /**
927
- * If omitted, implicitly uses the documentId of the instruction target
928
- */
929
- documentId?: string
930
- }
931
-
932
- /**
933
- *
934
- * Includes a LLM-friendly version of the field value in the instruction
935
- * @beta
936
- * */
937
- export declare interface GenerateFieldInstructionParam {
938
- type: 'field'
939
- /**
940
- * Examples: ['title'], ['array', {_key: 'arrayItemKey'}, 'field']
941
- */
942
- path: GeneratePath
943
- /**
944
- * If omitted, implicitly uses the documentId of the instruction target
945
- */
946
- documentId?: string
947
- }
948
-
949
- /**
950
- * Includes a LLM-friendly version of GROQ query result in the instruction
951
- * @beta
952
- * */
953
- export declare interface GenerateGroqInstructionParam {
954
- type: 'groq'
955
- query: string
956
- params?: Record<string, string>
957
- }
958
-
959
- /** @beta */
960
- export declare type GenerateInstruction<T extends Record<string, Any_2> = Record<string, Any_2>> =
961
- | GenerateSyncInstruction<T>
962
- | GenerateAsyncInstruction<T>
963
-
964
- /** @beta */
965
- export declare type GenerateInstructionParam =
966
- | string
967
- | GenerateConstantInstructionParam
968
- | GenerateFieldInstructionParam
969
- | GenerateDocumentInstructionParam
970
- | GenerateGroqInstructionParam
971
-
972
- /** @beta */
973
- export declare type GenerateInstructionParams = Record<string, GenerateInstructionParam>
974
-
975
- declare type GenerateOperation = 'set' | 'append' | 'mixed'
976
-
977
- declare type GeneratePath = GeneratePathSegment[]
978
-
979
- declare type GeneratePathSegment =
980
- | string
981
- | {
982
- _key: string
983
- }
984
-
985
- declare interface GenerateRequestBase {
986
- /** schemaId as reported by sanity deploy / sanity schema store */
987
- schemaId: string
988
- /** string template using $variable – more on this below under "Dynamic instruction" */
989
- instruction: string
990
- /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
991
- instructionParams?: GenerateInstructionParams
992
- /**
993
- * Target defines which parts of the document will be affected by the instruction.
994
- * It can be an array, so multiple parts of the document can be separately configured in detail.
995
- *
996
- * Omitting target implies that the document itself is the root.
997
- *
998
- * Notes:
999
- * - instruction can only affect fields up to `maxPathDepth`
1000
- * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1001
- * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1002
- *
1003
- * @see GenerateRequestBase#conditionalPaths
1004
- */
1005
- target?: GenerateTarget | GenerateTarget[]
1006
- /**
1007
- * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
1008
- *
1009
- * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
1010
- * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
1011
- *
1012
- * `conditionalPaths` param allows setting the default conditional value for
1013
- * `hidden` and `readOnly` to false,
1014
- * or individually set `hidden` and `readOnly` state for individual document paths.
1015
- *
1016
- *
1017
- * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
1018
- * and cannot be changed via conditionalPaths
1019
- *
1020
- * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
1021
- *
1022
- * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
1023
- * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
1024
- *
1025
- * @see GenerateRequestBase#target
1026
- */
1027
- conditionalPaths?: {
1028
- defaultReadOnly?: boolean
1029
- defaultHidden?: boolean
1030
- paths?: {
1031
- /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
1032
- path: GeneratePath
1033
- readOnly: boolean
1034
- hidden: boolean
1035
- }[]
1036
- }
1037
- /**
1038
- * When localeSettings is provided on the request, instruct can write to date and datetime fields.
1039
- * Otherwise, such fields will be ignored.
1040
- */
1041
- localeSettings?: {
1042
- /**
1043
- * A valid Unicode BCP 47 locale identifier used to interpret and format
1044
- * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
1045
- *
1046
- * This affects how phrases like "next Friday" or "in two weeks" are parsed,
1047
- * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
1048
- *
1049
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
1050
- */
1051
- locale: string
1052
- /**
1053
- * A valid IANA time zone identifier used to resolve relative and absolute
1054
- * date expressions to a specific point in time. Examples include
1055
- * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
1056
- *
1057
- * This ensures phrases like "tomorrow at 9am" are interpreted correctly
1058
- * based on the user's local time.
1059
- *
1060
- * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
1061
- */
1062
- timeZone: string
1063
- }
1064
- /**
1065
- * Controls how much variance the instructions will run with.
1066
- *
1067
- * Value must be in the range [0, 1] (inclusive).
1068
- *
1069
- * Default: 0.3
1070
- */
1071
- temperature?: number
1072
- }
1073
-
1074
- /** @beta */
1075
- export declare type GenerateSyncInstruction<
1076
- T extends Record<string, Any_2> = Record<string, Any_2>,
1077
- > = (ExistingDocumentRequest | CreateDocumentRequest<T>) & GenerateRequestBase & Sync
1078
-
1079
- /**
1080
- * @beta
1081
- */
1082
- declare interface GenerateTarget {
1083
- /**
1084
- * Root target path.
1085
- *
1086
- * Use this to have the instruction only affect a part of the document.
1087
- *
1088
- * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
1089
- * and `types.exclude`.
1090
- *
1091
- * Example:
1092
- *
1093
- * `path: ['body', {_key: 'someKey'}, 'nestedObject']`
1094
- *
1095
- * Here, the instruction will only write to fields under the nestedObject.
1096
- *
1097
- * Default: [] = the document itself
1098
- *
1099
- * @see #GeneratePathSegment
1100
- * @see #GeneratePath
1101
- * */
1102
- path?: GeneratePathSegment | GeneratePath
1103
- /**
1104
- * Sets the default operation for all paths in the target.
1105
- * Generate runs in `'mixed'` operation mode by default:
1106
- * Changes are set in all non-array fields, and append to all array fields.
1107
- *
1108
- * ### Operation types
1109
- * - `'set'` – an *overwriting* operation, and replaces the full field value.
1110
- * - `'append'`:
1111
- * – array fields: appends new items to the end of the array,
1112
- * - string fields: '<existing content> <new content>'
1113
- * - text fields: '<existing content>\n<new content>'
1114
- * - number fields: existing + new
1115
- * - other field types not mentioned will set instead (dates, url)
1116
- * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1117
- *
1118
- * The default operation can be overridden on a per-path basis using `include`.
1119
- *
1120
- * Nested fields inherit the operation specified by their parent and falls back to the
1121
- * top level target operation if not otherwise specified.
1122
- *
1123
- * Use `include` to change the `operation` of individual fields or items.
1124
- *
1125
- * #### Appending in the middle of arrays
1126
- * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1127
- *
1128
- * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1129
- * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1130
- *
1131
- * @see #GenerateTargetInclude.operation
1132
- * @see #include
1133
- * @see #GenerateTargetInclude.include
1134
- */
1135
- operation?: GenerateOperation
1136
- /**
1137
- * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
1138
- *
1139
- * Depth is based on path segments:
1140
- * - `title` has depth 1
1141
- * - `array[_key="no"].title` has depth 3
1142
- *
1143
- * Be careful not to set this too high in studios with recursive document schemas, as it could have
1144
- * negative impact on performance; both for runtime and quality of responses.
1145
- *
1146
- * Default: 4
1147
- */
1148
- maxPathDepth?: number
1149
- /**
1150
- * By default, all children up to `target.maxPathDepth` are included.
1151
- *
1152
- * When `include` is specified, only segments explicitly listed will be included.
1153
- *
1154
- * Fields or array items not on the include list, are implicitly excluded.
1155
- */
1156
- include?: (GeneratePathSegment | GenerateTargetInclude)[]
1157
- /**
1158
- * By default, all children up to `target.maxPathDepth` are included.
1159
- * Fields or array items not on the exclude list, are implicitly included.
1160
- */
1161
- exclude?: GeneratePathSegment[]
1162
- /**
1163
- * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1164
- * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1165
- *
1166
- * `types.include` and `types.exclude` are mutually exclusive.
1167
- */
1168
- types?: GenerateTypeConfig
1169
- }
1170
-
1171
- declare interface GenerateTargetInclude {
1172
- path: GeneratePathSegment | GeneratePath
1173
- /**
1174
- * Sets the operation for this path, and all its children.
1175
- * This overrides any operation set parents or the root target.
1176
- * @see #GenerateTarget.operation
1177
- * @see #include
1178
- */
1179
- operation?: GenerateOperation
1180
- /**
1181
- * By default, all children up to `target.maxPathDepth` are included.
1182
- *
1183
- * When `include` is specified, only segments explicitly listed will be included.
1184
- *
1185
- * Fields or array items not on the include list, are implicitly excluded.
1186
- */
1187
- include?: (GeneratePathSegment | GenerateTargetInclude)[]
1188
- /**
1189
- * By default, all children up to `target.maxPathDepth` are included.
1190
- * Fields or array items not on the exclude list, are implicitly included.
1191
- */
1192
- exclude?: GeneratePathSegment[]
1193
- /**
1194
- * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
1195
- * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
1196
- *
1197
- * `types.include` and `types.exclude` are mutually exclusive.
1198
- */
1199
- types?: GenerateTypeConfig
1200
- }
1201
-
1202
- declare type GenerateTypeConfig =
1203
- | {
1204
- include: string[]
1205
- exclude?: never
1206
- }
1207
- | {
1208
- exclude: string[]
1209
- include?: never
1210
- }
1211
-
1212
856
  /** @public */
1213
857
  export declare type HttpRequest = {
1214
858
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1641,18 +1285,6 @@ export declare type MutationSelectionQueryParams = {
1641
1285
  [key: string]: Any
1642
1286
  }
1643
1287
 
1644
- /** @public */
1645
- declare class ObservableAgentsActionClient {
1646
- #private
1647
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1648
- generate(request: GenerateAsyncInstruction): Observable<{
1649
- _id: string
1650
- }>
1651
- generate<DocumentShape extends Record<string, Any>>(
1652
- request: GenerateSyncInstruction<DocumentShape>,
1653
- ): Observable<IdentifiedSanityDocumentStub & DocumentShape>
1654
- }
1655
-
1656
1288
  /** @internal */
1657
1289
  export declare class ObservableAssetsClient {
1658
1290
  #private
@@ -1830,9 +1462,6 @@ export declare class ObservableSanityClient {
1830
1462
  live: LiveClient
1831
1463
  projects: ObservableProjectsClient
1832
1464
  users: ObservableUsersClient
1833
- agent: {
1834
- action: ObservableAgentsActionClient
1835
- }
1836
1465
  /**
1837
1466
  * Instance properties
1838
1467
  */
@@ -2752,9 +2381,6 @@ export declare class SanityClient {
2752
2381
  live: LiveClient
2753
2382
  projects: ProjectsClient
2754
2383
  users: UsersClient
2755
- agent: {
2756
- action: AgentActionsClient
2757
- }
2758
2384
  /**
2759
2385
  * Observable version of the Sanity client, with the same configuration as the promise-based one
2760
2386
  */
@@ -3293,13 +2919,6 @@ export declare type SanityDocumentStub<T extends Record<string, Any> = Record<st
3293
2919
  _type: string
3294
2920
  }
3295
2921
 
3296
- /** @public */
3297
- declare type SanityDocumentStub_2<T extends Record<string, Any_2> = Record<string, Any_2>> = {
3298
- [P in keyof T]: T[P]
3299
- } & {
3300
- _type: string
3301
- }
3302
-
3303
2922
  /** @internal */
3304
2923
  export declare interface SanityImageAssetDocument extends SanityAssetDocument {
3305
2924
  metadata: {
@@ -3476,29 +3095,6 @@ export {StudioBaseUrl}
3476
3095
 
3477
3096
  export {StudioUrl}
3478
3097
 
3479
- declare interface Sync {
3480
- /**
3481
- * By default, noWrite: false.
3482
- * Write enabled operations will mutate the target document, and emit AI presence in the studio.
3483
- *
3484
- * When noWrite: true, the api will not mutate any documents nor emit presence.
3485
- * Ie, when true, no changes will be made to content-lake
3486
- *
3487
- * noWrite: true is incompatible with async: true,
3488
- * as noWrite implies that you will use the return value of the operation
3489
- */
3490
- noWrite?: boolean
3491
- /**
3492
- * When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
3493
- * The instruction operation will carry on in the background.
3494
- *
3495
- * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
3496
- *
3497
- * async: true is incompatible with noWrite: true, as async: true does not return the resulting document
3498
- */
3499
- async?: false
3500
- }
3501
-
3502
3098
  /** @public */
3503
3099
  export declare type SyncTag = `s1:${string}`
3504
3100
 
@@ -963,42 +963,6 @@ const resourceDataBase = (config) => {
963
963
  throw new Error(`Unsupported resource type: ${type.toString()}`);
964
964
  }
965
965
  };
966
- function _generate(client, httpRequest, request) {
967
- const dataset2 = hasDataset(client.config());
968
- return _request(client, httpRequest, {
969
- method: "POST",
970
- uri: `/agent/action/generate/${dataset2}`,
971
- body: request
972
- });
973
- }
974
- class ObservableAgentsActionClient {
975
- #client;
976
- #httpRequest;
977
- constructor(client, httpRequest) {
978
- this.#client = client, this.#httpRequest = httpRequest;
979
- }
980
- /**
981
- * Run an instruction to generate content in a target document.
982
- * @param request instruction request
983
- */
984
- generate(request) {
985
- return _generate(this.#client, this.#httpRequest, request);
986
- }
987
- }
988
- class AgentActionsClient {
989
- #client;
990
- #httpRequest;
991
- constructor(client, httpRequest) {
992
- this.#client = client, this.#httpRequest = httpRequest;
993
- }
994
- /**
995
- * Run an instruction to generate content in a target document.
996
- * @param request instruction request
997
- */
998
- generate(request) {
999
- return lastValueFrom(_generate(this.#client, this.#httpRequest, request));
1000
- }
1001
- }
1002
966
  class ObservableAssetsClient {
1003
967
  #client;
1004
968
  #httpRequest;
@@ -1419,7 +1383,6 @@ class ObservableSanityClient {
1419
1383
  live;
1420
1384
  projects;
1421
1385
  users;
1422
- agent;
1423
1386
  /**
1424
1387
  * Private properties
1425
1388
  */
@@ -1430,9 +1393,7 @@ class ObservableSanityClient {
1430
1393
  */
1431
1394
  listen = _listen;
1432
1395
  constructor(httpRequest, config = defaultConfig) {
1433
- 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.agent = {
1434
- action: new ObservableAgentsActionClient(this, this.#httpRequest)
1435
- };
1396
+ 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);
1436
1397
  }
1437
1398
  /**
1438
1399
  * Clone the client - returns a new instance
@@ -1571,7 +1532,6 @@ class SanityClient {
1571
1532
  live;
1572
1533
  projects;
1573
1534
  users;
1574
- agent;
1575
1535
  /**
1576
1536
  * Observable version of the Sanity client, with the same configuration as the promise-based one
1577
1537
  */
@@ -1586,9 +1546,7 @@ class SanityClient {
1586
1546
  */
1587
1547
  listen = _listen;
1588
1548
  constructor(httpRequest, config = defaultConfig) {
1589
- 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.agent = {
1590
- action: new AgentActionsClient(this, this.#httpRequest)
1591
- }, this.observable = new ObservableSanityClient(httpRequest, config);
1549
+ 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);
1592
1550
  }
1593
1551
  /**
1594
1552
  * Clone the client - returns a new instance