@sanity/client 6.28.4-beta.1 → 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/_chunks-cjs/config.cjs +1 -11
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +1 -11
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +45 -13
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +404 -0
- package/dist/index.browser.d.ts +404 -0
- package/dist/index.browser.js +45 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +45 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +393 -0
- package/dist/index.d.ts +393 -0
- package/dist/index.js +45 -3
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +393 -0
- package/dist/stega.browser.d.ts +393 -0
- package/dist/stega.d.cts +393 -0
- package/dist/stega.d.ts +393 -0
- package/package.json +22 -22
- package/src/SanityClient.ts +13 -0
- package/src/agent/actions/AgentActionsClient.ts +74 -0
- package/src/agent/actions/generate.ts +24 -0
- package/src/agent/actions/types.ts +373 -0
- package/src/config.ts +2 -17
- package/src/types.ts +10 -0
- package/umd/sanityClient.js +45 -13
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.ts
CHANGED
|
@@ -39,6 +39,18 @@ 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
|
+
|
|
42
54
|
/** @internal */
|
|
43
55
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
44
56
|
returnFirst: false
|
|
@@ -57,6 +69,12 @@ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
|
|
|
57
69
|
*/
|
|
58
70
|
export declare type Any = any
|
|
59
71
|
|
|
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
|
+
|
|
60
78
|
/** @internal */
|
|
61
79
|
export declare interface ApiError {
|
|
62
80
|
error: string
|
|
@@ -116,6 +134,18 @@ export declare class AssetsClient {
|
|
|
116
134
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
117
135
|
}
|
|
118
136
|
|
|
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 skipWrite, as async: true does not return the resulting document
|
|
145
|
+
*/
|
|
146
|
+
async: true
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
/** @internal */
|
|
120
150
|
export declare type AttributeSet = {
|
|
121
151
|
[key: string]: Any
|
|
@@ -574,6 +604,19 @@ export declare type CreateAction = {
|
|
|
574
604
|
/** @public */
|
|
575
605
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
576
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
|
+
|
|
577
620
|
/** @public */
|
|
578
621
|
export declare interface CurrentSanityUser {
|
|
579
622
|
id: string
|
|
@@ -767,6 +810,15 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
|
|
|
767
810
|
*/
|
|
768
811
|
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
769
812
|
|
|
813
|
+
/**
|
|
814
|
+
* Instruction for an existing document.
|
|
815
|
+
* @beta
|
|
816
|
+
*/
|
|
817
|
+
declare interface ExistingDocumentRequest {
|
|
818
|
+
documentId: string
|
|
819
|
+
createDocument?: never
|
|
820
|
+
}
|
|
821
|
+
|
|
770
822
|
/** @public */
|
|
771
823
|
export declare type FilterDefault = (props: {
|
|
772
824
|
/**
|
|
@@ -833,6 +885,310 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
|
|
|
833
885
|
returnDocuments?: true
|
|
834
886
|
}
|
|
835
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
|
+
|
|
836
1192
|
/** @public */
|
|
837
1193
|
export declare type HttpRequest = {
|
|
838
1194
|
(options: RequestOptions, requester: Requester): ReturnType<Requester>
|
|
@@ -1253,6 +1609,18 @@ export declare type MutationSelectionQueryParams = {
|
|
|
1253
1609
|
[key: string]: Any
|
|
1254
1610
|
}
|
|
1255
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
|
+
|
|
1256
1624
|
/** @internal */
|
|
1257
1625
|
export declare class ObservableAssetsClient {
|
|
1258
1626
|
#private
|
|
@@ -1430,6 +1798,9 @@ export declare class ObservableSanityClient {
|
|
|
1430
1798
|
live: LiveClient
|
|
1431
1799
|
projects: ObservableProjectsClient
|
|
1432
1800
|
users: ObservableUsersClient
|
|
1801
|
+
agent: {
|
|
1802
|
+
action: ObservableAgentsActionClient
|
|
1803
|
+
}
|
|
1433
1804
|
/**
|
|
1434
1805
|
* Instance properties
|
|
1435
1806
|
*/
|
|
@@ -2349,6 +2720,9 @@ export declare class SanityClient {
|
|
|
2349
2720
|
live: LiveClient
|
|
2350
2721
|
projects: ProjectsClient
|
|
2351
2722
|
users: UsersClient
|
|
2723
|
+
agent: {
|
|
2724
|
+
action: AgentActionsClient
|
|
2725
|
+
}
|
|
2352
2726
|
/**
|
|
2353
2727
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2354
2728
|
*/
|
|
@@ -2887,6 +3261,13 @@ export declare type SanityDocumentStub<T extends Record<string, Any> = Record<st
|
|
|
2887
3261
|
_type: string
|
|
2888
3262
|
}
|
|
2889
3263
|
|
|
3264
|
+
/** @public */
|
|
3265
|
+
declare type SanityDocumentStub_2<T extends Record<string, Any_2> = Record<string, Any_2>> = {
|
|
3266
|
+
[P in keyof T]: T[P]
|
|
3267
|
+
} & {
|
|
3268
|
+
_type: string
|
|
3269
|
+
}
|
|
3270
|
+
|
|
2890
3271
|
/** @internal */
|
|
2891
3272
|
export declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
2892
3273
|
metadata: {
|
|
@@ -3063,6 +3444,29 @@ export {StudioBaseUrl}
|
|
|
3063
3444
|
|
|
3064
3445
|
export {StudioUrl}
|
|
3065
3446
|
|
|
3447
|
+
declare interface Sync {
|
|
3448
|
+
/**
|
|
3449
|
+
* By default, skipWrite: false.
|
|
3450
|
+
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
3451
|
+
*
|
|
3452
|
+
* When skipWrite: true, the api will not mutate any documents nor emit presence.
|
|
3453
|
+
* Ie, when true, no changes will be made to content-lake
|
|
3454
|
+
*
|
|
3455
|
+
* skipWrite: true is incompatible with async: true,
|
|
3456
|
+
* as skipWrite implies that you will use the return value of the operation
|
|
3457
|
+
*/
|
|
3458
|
+
skipWrite?: boolean
|
|
3459
|
+
/**
|
|
3460
|
+
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
3461
|
+
* The instruction operation will carry on in the background.
|
|
3462
|
+
*
|
|
3463
|
+
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
3464
|
+
*
|
|
3465
|
+
* async: true is incompatible with skipWrite: true, as async: true does not return the resulting document
|
|
3466
|
+
*/
|
|
3467
|
+
async?: false
|
|
3468
|
+
}
|
|
3469
|
+
|
|
3066
3470
|
/** @public */
|
|
3067
3471
|
export declare type SyncTag = `s1:${string}`
|
|
3068
3472
|
|
package/dist/index.browser.js
CHANGED
|
@@ -201,21 +201,11 @@ function validateApiVersion(apiVersion) {
|
|
|
201
201
|
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
202
202
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
203
203
|
}
|
|
204
|
-
const VALID_PERSPECTIVE = /^[a-z0-9_]+$/i;
|
|
205
204
|
function validateApiPerspective(perspective) {
|
|
206
|
-
if (Array.isArray(perspective) && perspective.includes("raw"))
|
|
205
|
+
if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes("raw"))
|
|
207
206
|
throw new TypeError(
|
|
208
207
|
'Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives'
|
|
209
208
|
);
|
|
210
|
-
const invalid = (Array.isArray(perspective) ? perspective : [perspective]).filter(
|
|
211
|
-
(perspectiveName) => typeof perspectiveName != "string" || !VALID_PERSPECTIVE.test(perspectiveName)
|
|
212
|
-
);
|
|
213
|
-
if (invalid.length > 0) {
|
|
214
|
-
const formatted = invalid.map((v) => JSON.stringify(v));
|
|
215
|
-
throw new TypeError(
|
|
216
|
-
`Invalid API perspective value${invalid.length === 1 ? "" : "s"}: ${formatted.join(", ")}, expected \`published\`, \`drafts\`, \`raw\` or a release identifier string`
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
209
|
}
|
|
220
210
|
const initConfig = (config, prevConfig) => {
|
|
221
211
|
const specifiedConfig = {
|
|
@@ -925,6 +915,42 @@ function _createAbortError(signal) {
|
|
|
925
915
|
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
926
916
|
return error.name = "AbortError", error;
|
|
927
917
|
}
|
|
918
|
+
function _generate(client, httpRequest, request) {
|
|
919
|
+
const dataset2 = hasDataset(client.config());
|
|
920
|
+
return _request(client, httpRequest, {
|
|
921
|
+
method: "POST",
|
|
922
|
+
uri: `/agent/action/generate/${dataset2}`,
|
|
923
|
+
body: request
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
class ObservableAgentsActionClient {
|
|
927
|
+
#client;
|
|
928
|
+
#httpRequest;
|
|
929
|
+
constructor(client, httpRequest) {
|
|
930
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Run an instruction to generate content in a target document.
|
|
934
|
+
* @param request instruction request
|
|
935
|
+
*/
|
|
936
|
+
generate(request) {
|
|
937
|
+
return _generate(this.#client, this.#httpRequest, request);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
class AgentActionsClient {
|
|
941
|
+
#client;
|
|
942
|
+
#httpRequest;
|
|
943
|
+
constructor(client, httpRequest) {
|
|
944
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Run an instruction to generate content in a target document.
|
|
948
|
+
* @param request instruction request
|
|
949
|
+
*/
|
|
950
|
+
generate(request) {
|
|
951
|
+
return lastValueFrom(_generate(this.#client, this.#httpRequest, request));
|
|
952
|
+
}
|
|
953
|
+
}
|
|
928
954
|
class ObservableAssetsClient {
|
|
929
955
|
#client;
|
|
930
956
|
#httpRequest;
|
|
@@ -1319,6 +1345,7 @@ class ObservableSanityClient {
|
|
|
1319
1345
|
live;
|
|
1320
1346
|
projects;
|
|
1321
1347
|
users;
|
|
1348
|
+
agent;
|
|
1322
1349
|
/**
|
|
1323
1350
|
* Private properties
|
|
1324
1351
|
*/
|
|
@@ -1329,7 +1356,9 @@ class ObservableSanityClient {
|
|
|
1329
1356
|
*/
|
|
1330
1357
|
listen = _listen;
|
|
1331
1358
|
constructor(httpRequest, config = defaultConfig) {
|
|
1332
|
-
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)
|
|
1359
|
+
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 = {
|
|
1360
|
+
action: new ObservableAgentsActionClient(this, this.#httpRequest)
|
|
1361
|
+
};
|
|
1333
1362
|
}
|
|
1334
1363
|
/**
|
|
1335
1364
|
* Clone the client - returns a new instance
|
|
@@ -1468,6 +1497,7 @@ class SanityClient {
|
|
|
1468
1497
|
live;
|
|
1469
1498
|
projects;
|
|
1470
1499
|
users;
|
|
1500
|
+
agent;
|
|
1471
1501
|
/**
|
|
1472
1502
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1473
1503
|
*/
|
|
@@ -1482,7 +1512,9 @@ class SanityClient {
|
|
|
1482
1512
|
*/
|
|
1483
1513
|
listen = _listen;
|
|
1484
1514
|
constructor(httpRequest, config = defaultConfig) {
|
|
1485
|
-
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.
|
|
1515
|
+
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 = {
|
|
1516
|
+
action: new AgentActionsClient(this, this.#httpRequest)
|
|
1517
|
+
}, this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1486
1518
|
}
|
|
1487
1519
|
/**
|
|
1488
1520
|
* Clone the client - returns a new instance
|