@sanity/client 6.28.3-instruct.4 → 6.28.3-instruct.6
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.browser.d.cts +163 -38
- package/dist/index.browser.d.ts +163 -38
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +163 -38
- package/dist/index.d.ts +163 -38
- package/dist/index.js +1 -1
- package/dist/stega.browser.d.cts +163 -38
- package/dist/stega.browser.d.ts +163 -38
- package/dist/stega.d.cts +163 -38
- package/dist/stega.d.ts +163 -38
- package/package.json +1 -1
- package/src/instruct/types.ts +161 -27
package/src/instruct/types.ts
CHANGED
|
@@ -48,6 +48,146 @@ export interface InstructGroqInstructionParam {
|
|
|
48
48
|
params?: Record<string, string>
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export type InstructTypeConfig =
|
|
52
|
+
| {include: string[]; exclude?: never}
|
|
53
|
+
| {exclude: string[]; include?: never}
|
|
54
|
+
|
|
55
|
+
export type InstructPathSegment = string | {_key: string}
|
|
56
|
+
export type InstructPath = InstructPathSegment[]
|
|
57
|
+
export type InstructOperation = 'set' | 'append' | 'mixed'
|
|
58
|
+
|
|
59
|
+
export interface InstructTargetInclude {
|
|
60
|
+
path: InstructPathSegment | InstructPath
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sets the operation for this path, and all its children.
|
|
64
|
+
* This overrides any operation set parents or the root target.
|
|
65
|
+
* @see #InstructTarget.operation
|
|
66
|
+
* @see #include
|
|
67
|
+
*/
|
|
68
|
+
operation?: InstructOperation
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
72
|
+
*
|
|
73
|
+
* When `include` is specified, only segments explicitly listed will be included.
|
|
74
|
+
*
|
|
75
|
+
* Fields or array items not on the include list, are implicitly excluded.
|
|
76
|
+
*/
|
|
77
|
+
include?: (InstructPathSegment | InstructTargetInclude)[]
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
81
|
+
* Fields or array items not on the exclude list, are implicitly included.
|
|
82
|
+
*/
|
|
83
|
+
exclude?: InstructPathSegment[]
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Types can be used to exclude array item types or all fields directly under the target path of a certain type.
|
|
87
|
+
* If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
|
|
88
|
+
*
|
|
89
|
+
* `types.include` and `types.exclude` are mutually exclusive.
|
|
90
|
+
*/
|
|
91
|
+
types?: InstructTypeConfig
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @beta
|
|
96
|
+
*/
|
|
97
|
+
export interface InstructTarget {
|
|
98
|
+
/**
|
|
99
|
+
* Root target path.
|
|
100
|
+
*
|
|
101
|
+
* Use this to have the instruction only affect a part of the document.
|
|
102
|
+
*
|
|
103
|
+
* To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
|
|
104
|
+
* and `types.exclude`.
|
|
105
|
+
*
|
|
106
|
+
* Example:
|
|
107
|
+
*
|
|
108
|
+
* `target: ['body', {_key: 'someKey'}, 'nestedObject']`
|
|
109
|
+
*
|
|
110
|
+
* Here, the instruction will only write to fields under the nestedObject.
|
|
111
|
+
*
|
|
112
|
+
* Default: [] = the document itself
|
|
113
|
+
*
|
|
114
|
+
* @see #InstructPathSegment
|
|
115
|
+
* @see #InstructPath
|
|
116
|
+
* */
|
|
117
|
+
path?: InstructPathSegment | InstructPath
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Sets the default operation for all paths in the target.
|
|
121
|
+
* Instruct runs in `'mixed'` operation mode by default:
|
|
122
|
+
* Changes are set in all non-array fields, and append to all array fields.
|
|
123
|
+
*
|
|
124
|
+
* ### Operation types
|
|
125
|
+
* - `'set'` – an *overwriting* operation, and replaces the full field value.
|
|
126
|
+
* - `'append'`:
|
|
127
|
+
* – array fields: appends new items to the end of the array,
|
|
128
|
+
* - string fields: '<existing content> <new content>'
|
|
129
|
+
* - text fields: '<existing content>\n<new content>'
|
|
130
|
+
* - number fields: existing + new
|
|
131
|
+
* - other field types not mentioned will set instead (dates, url)
|
|
132
|
+
* - `'mixed'` – (default) sets non-array fields, and appends to array fields
|
|
133
|
+
*
|
|
134
|
+
* The default operation can be overridden on a per-path basis using `include`.
|
|
135
|
+
*
|
|
136
|
+
* Nested fields inherit the operation specified by their parent and falls back to the
|
|
137
|
+
* top level target operation if not otherwise specified.
|
|
138
|
+
*
|
|
139
|
+
* Use `include` to change the `operation` of individual fields or items.
|
|
140
|
+
*
|
|
141
|
+
* #### Appending in the middle of arrays
|
|
142
|
+
* `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
|
|
143
|
+
*
|
|
144
|
+
* To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
|
|
145
|
+
* Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
|
|
146
|
+
*
|
|
147
|
+
* @see #InstructTargetInclude.operation
|
|
148
|
+
* @see #include
|
|
149
|
+
* @see #InstructTargetInclude.include
|
|
150
|
+
*/
|
|
151
|
+
operation?: InstructOperation
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* maxPathDepth controls how deep into the schema from the target root the instruction will affect.
|
|
155
|
+
*
|
|
156
|
+
* Depth is based on path segments:
|
|
157
|
+
* - `title` has depth 1
|
|
158
|
+
* - `array[_key="no"].title` has depth 3
|
|
159
|
+
*
|
|
160
|
+
* Be careful not to set this too high in studios with recursive document schemas, as it could have
|
|
161
|
+
* negative impact on performance; both for runtime and quality of responses.
|
|
162
|
+
*
|
|
163
|
+
* Default: 4
|
|
164
|
+
*/
|
|
165
|
+
maxPathDepth?: number
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
169
|
+
*
|
|
170
|
+
* When `include` is specified, only segments explicitly listed will be included.
|
|
171
|
+
*
|
|
172
|
+
* Fields or array items not on the include list, are implicitly excluded.
|
|
173
|
+
*/
|
|
174
|
+
include?: (InstructPathSegment | InstructTargetInclude)[]
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* By default, all children up to `target.maxPathDepth` are included.
|
|
178
|
+
* Fields or array items not on the exclude list, are implicitly included.
|
|
179
|
+
*/
|
|
180
|
+
exclude?: InstructPathSegment[]
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Types can be used to exclude array item types or all fields directly under the target path of a certain type.
|
|
184
|
+
* If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
|
|
185
|
+
*
|
|
186
|
+
* `types.include` and `types.exclude` are mutually exclusive.
|
|
187
|
+
*/
|
|
188
|
+
types?: InstructTypeConfig
|
|
189
|
+
}
|
|
190
|
+
|
|
51
191
|
/** @beta */
|
|
52
192
|
export type InstructInstructionParam =
|
|
53
193
|
| string
|
|
@@ -66,36 +206,19 @@ interface InstructRequestBase {
|
|
|
66
206
|
instruction: string
|
|
67
207
|
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
68
208
|
instructionParams?: InstructInstructionParams
|
|
69
|
-
/**
|
|
70
|
-
* Optional document path output target for the instruction.
|
|
71
|
-
* When provided, the instruction will apply to this path in the document and its children.
|
|
72
|
-
*
|
|
73
|
-
* ## Examples
|
|
74
|
-
* - `path: 'title'` will output to the title field in the document
|
|
75
|
-
* - `path: 'array[_key="xx"]'` will output to the item with `_key: 'xx'` in the array field
|
|
76
|
-
*/
|
|
77
|
-
path?: string
|
|
78
209
|
|
|
79
210
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* The string-paths are relative to the `path` param
|
|
211
|
+
* Target defines which parts of the document will be affected by the instruction.
|
|
212
|
+
* It can be an array, so multiple parts of the document can be separately configured in detail.
|
|
83
213
|
*
|
|
84
|
-
*
|
|
85
|
-
* if an relative-path does not exist or is invalid, it will be silently ignored.
|
|
86
|
-
*
|
|
87
|
-
* @see InstructRequestBase#conditionalPaths
|
|
88
|
-
* @see InstructRequestBase#outputTypes
|
|
89
|
-
*/
|
|
90
|
-
relativeOutputPaths?: {include: string[]} | {exclude: string[]}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Controls which types the instruction is allowed to output to.
|
|
214
|
+
* Omitting target implies that the document itself is the root.
|
|
94
215
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
216
|
+
* Notes:
|
|
217
|
+
* - instruction can only affect fields up to `maxPathDepth`
|
|
218
|
+
* - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
|
|
219
|
+
* It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
|
|
97
220
|
*/
|
|
98
|
-
|
|
221
|
+
target?: InstructTarget | InstructTarget[]
|
|
99
222
|
|
|
100
223
|
/**
|
|
101
224
|
* When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
|
|
@@ -120,8 +243,8 @@ interface InstructRequestBase {
|
|
|
120
243
|
defaultReadOnly?: boolean
|
|
121
244
|
defaultHidden?: boolean
|
|
122
245
|
paths?: {
|
|
123
|
-
/** path here is not a relative path: it must be the full document path, regardless of `path` param
|
|
124
|
-
path:
|
|
246
|
+
/** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
|
|
247
|
+
path: InstructPath
|
|
125
248
|
readOnly: boolean
|
|
126
249
|
hidden: boolean
|
|
127
250
|
}[]
|
|
@@ -155,6 +278,15 @@ interface InstructRequestBase {
|
|
|
155
278
|
*/
|
|
156
279
|
timeZone: string
|
|
157
280
|
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Controls how much variance the instructions will run with.
|
|
284
|
+
*
|
|
285
|
+
* Value must be in the range [0, 1] (inclusive).
|
|
286
|
+
*
|
|
287
|
+
* Default: 0.3
|
|
288
|
+
*/
|
|
289
|
+
temperature?: number
|
|
158
290
|
}
|
|
159
291
|
|
|
160
292
|
interface Sync {
|
|
@@ -199,6 +331,7 @@ interface Async {
|
|
|
199
331
|
*/
|
|
200
332
|
interface ExistingDocumentRequest {
|
|
201
333
|
documentId: string
|
|
334
|
+
createDocument?: never
|
|
202
335
|
}
|
|
203
336
|
|
|
204
337
|
/**
|
|
@@ -211,6 +344,7 @@ interface CreateDocumentRequest<T extends Record<string, Any> = Record<string, A
|
|
|
211
344
|
_id?: string
|
|
212
345
|
_type: string
|
|
213
346
|
} & SanityDocumentStub<T>
|
|
347
|
+
documentId?: never
|
|
214
348
|
}
|
|
215
349
|
|
|
216
350
|
/** @beta */
|