@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.
- package/dist/index.browser.cjs +2 -44
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +0 -404
- package/dist/index.browser.d.ts +0 -404
- package/dist/index.browser.js +2 -44
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +3 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -393
- package/dist/index.d.ts +0 -393
- package/dist/index.js +3 -45
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +0 -393
- package/dist/stega.browser.d.ts +0 -393
- package/dist/stega.d.cts +0 -393
- package/dist/stega.d.ts +0 -393
- package/package.json +2 -1
- package/src/SanityClient.ts +0 -13
- package/src/types.ts +0 -10
- package/umd/sanityClient.js +2 -44
- package/umd/sanityClient.min.js +2 -2
- package/src/agent/actions/AgentActionsClient.ts +0 -74
- package/src/agent/actions/generate.ts +0 -24
- package/src/agent/actions/types.ts +0 -373
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
//Request shape
|
|
2
|
-
|
|
3
|
-
import type {Any, SanityDocumentStub} from '@sanity/client'
|
|
4
|
-
|
|
5
|
-
/** @beta */
|
|
6
|
-
export interface GenerateConstantInstructionParam {
|
|
7
|
-
type: 'constant'
|
|
8
|
-
value: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* Includes a LLM-friendly version of the field value in the instruction
|
|
14
|
-
* @beta
|
|
15
|
-
* */
|
|
16
|
-
export interface GenerateFieldInstructionParam {
|
|
17
|
-
type: 'field'
|
|
18
|
-
/**
|
|
19
|
-
* Examples: ['title'], ['array', {_key: 'arrayItemKey'}, 'field']
|
|
20
|
-
*/
|
|
21
|
-
path: GeneratePath
|
|
22
|
-
/**
|
|
23
|
-
* If omitted, implicitly uses the documentId of the instruction target
|
|
24
|
-
*/
|
|
25
|
-
documentId?: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* Includes a LLM-friendly version of the document in the instruction
|
|
31
|
-
* @beta
|
|
32
|
-
* */
|
|
33
|
-
export interface GenerateDocumentInstructionParam {
|
|
34
|
-
type: 'document'
|
|
35
|
-
/**
|
|
36
|
-
* If omitted, implicitly uses the documentId of the instruction target
|
|
37
|
-
*/
|
|
38
|
-
documentId?: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Includes a LLM-friendly version of GROQ query result in the instruction
|
|
43
|
-
* @beta
|
|
44
|
-
* */
|
|
45
|
-
export interface GenerateGroqInstructionParam {
|
|
46
|
-
type: 'groq'
|
|
47
|
-
query: string
|
|
48
|
-
params?: Record<string, string>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type GenerateTypeConfig =
|
|
52
|
-
| {include: string[]; exclude?: never}
|
|
53
|
-
| {exclude: string[]; include?: never}
|
|
54
|
-
|
|
55
|
-
export type GeneratePathSegment = string | {_key: string}
|
|
56
|
-
export type GeneratePath = GeneratePathSegment[]
|
|
57
|
-
export type GenerateOperation = 'set' | 'append' | 'mixed'
|
|
58
|
-
|
|
59
|
-
export interface GenerateTargetInclude {
|
|
60
|
-
path: GeneratePathSegment | GeneratePath
|
|
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 #GenerateTarget.operation
|
|
66
|
-
* @see #include
|
|
67
|
-
*/
|
|
68
|
-
operation?: GenerateOperation
|
|
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?: (GeneratePathSegment | GenerateTargetInclude)[]
|
|
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?: GeneratePathSegment[]
|
|
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?: GenerateTypeConfig
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @beta
|
|
96
|
-
*/
|
|
97
|
-
export interface GenerateTarget {
|
|
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
|
-
* `path: ['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 #GeneratePathSegment
|
|
115
|
-
* @see #GeneratePath
|
|
116
|
-
* */
|
|
117
|
-
path?: GeneratePathSegment | GeneratePath
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Sets the default operation for all paths in the target.
|
|
121
|
-
* Generate 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 #GenerateTargetInclude.operation
|
|
148
|
-
* @see #include
|
|
149
|
-
* @see #GenerateTargetInclude.include
|
|
150
|
-
*/
|
|
151
|
-
operation?: GenerateOperation
|
|
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?: (GeneratePathSegment | GenerateTargetInclude)[]
|
|
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?: GeneratePathSegment[]
|
|
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?: GenerateTypeConfig
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** @beta */
|
|
192
|
-
export type GenerateInstructionParam =
|
|
193
|
-
| string
|
|
194
|
-
| GenerateConstantInstructionParam
|
|
195
|
-
| GenerateFieldInstructionParam
|
|
196
|
-
| GenerateDocumentInstructionParam
|
|
197
|
-
| GenerateGroqInstructionParam
|
|
198
|
-
|
|
199
|
-
/** @beta */
|
|
200
|
-
export type GenerateInstructionParams = Record<string, GenerateInstructionParam>
|
|
201
|
-
|
|
202
|
-
interface GenerateRequestBase {
|
|
203
|
-
/** schemaId as reported by sanity deploy / sanity schema store */
|
|
204
|
-
schemaId: string
|
|
205
|
-
/** string template using $variable – more on this below under "Dynamic instruction" */
|
|
206
|
-
instruction: string
|
|
207
|
-
/** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
|
|
208
|
-
instructionParams?: GenerateInstructionParams
|
|
209
|
-
|
|
210
|
-
/**
|
|
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.
|
|
213
|
-
*
|
|
214
|
-
* Omitting target implies that the document itself is the root.
|
|
215
|
-
*
|
|
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)
|
|
220
|
-
*
|
|
221
|
-
* @see GenerateRequestBase#conditionalPaths
|
|
222
|
-
*/
|
|
223
|
-
target?: GenerateTarget | GenerateTarget[]
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
|
|
227
|
-
*
|
|
228
|
-
* By default, Generate will not output to conditional `readOnly` and `hidden` fields,
|
|
229
|
-
* ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
|
|
230
|
-
*
|
|
231
|
-
* `conditionalPaths` param allows setting the default conditional value for
|
|
232
|
-
* `hidden` and `readOnly` to false,
|
|
233
|
-
* or individually set `hidden` and `readOnly` state for individual document paths.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
|
|
237
|
-
* and cannot be changed via conditionalPaths
|
|
238
|
-
*
|
|
239
|
-
* conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
|
|
240
|
-
*
|
|
241
|
-
* Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
|
|
242
|
-
* visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
|
|
243
|
-
*
|
|
244
|
-
* @see GenerateRequestBase#target
|
|
245
|
-
*/
|
|
246
|
-
conditionalPaths?: {
|
|
247
|
-
defaultReadOnly?: boolean
|
|
248
|
-
defaultHidden?: boolean
|
|
249
|
-
paths?: {
|
|
250
|
-
/** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
|
|
251
|
-
path: GeneratePath
|
|
252
|
-
readOnly: boolean
|
|
253
|
-
hidden: boolean
|
|
254
|
-
}[]
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* When localeSettings is provided on the request, instruct can write to date and datetime fields.
|
|
259
|
-
* Otherwise, such fields will be ignored.
|
|
260
|
-
*/
|
|
261
|
-
localeSettings?: {
|
|
262
|
-
/**
|
|
263
|
-
* A valid Unicode BCP 47 locale identifier used to interpret and format
|
|
264
|
-
* natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
|
|
265
|
-
*
|
|
266
|
-
* This affects how phrases like "next Friday" or "in two weeks" are parsed,
|
|
267
|
-
* and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
|
|
268
|
-
*
|
|
269
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
|
|
270
|
-
*/
|
|
271
|
-
locale: string
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* A valid IANA time zone identifier used to resolve relative and absolute
|
|
275
|
-
* date expressions to a specific point in time. Examples include
|
|
276
|
-
* "America/New_York", "Europe/Paris", or "Asia/Tokyo".
|
|
277
|
-
*
|
|
278
|
-
* This ensures phrases like "tomorrow at 9am" are interpreted correctly
|
|
279
|
-
* based on the user's local time.
|
|
280
|
-
*
|
|
281
|
-
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
|
282
|
-
*/
|
|
283
|
-
timeZone: string
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Controls how much variance the instructions will run with.
|
|
288
|
-
*
|
|
289
|
-
* Value must be in the range [0, 1] (inclusive).
|
|
290
|
-
*
|
|
291
|
-
* Default: 0.3
|
|
292
|
-
*/
|
|
293
|
-
temperature?: number
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
interface Sync {
|
|
297
|
-
/**
|
|
298
|
-
* By default, noWrite: false.
|
|
299
|
-
* Write enabled operations will mutate the target document, and emit AI presence in the studio.
|
|
300
|
-
*
|
|
301
|
-
* When noWrite: true, the api will not mutate any documents nor emit presence.
|
|
302
|
-
* Ie, when true, no changes will be made to content-lake
|
|
303
|
-
*
|
|
304
|
-
* noWrite: true is incompatible with async: true,
|
|
305
|
-
* as noWrite implies that you will use the return value of the operation
|
|
306
|
-
*/
|
|
307
|
-
noWrite?: boolean
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
311
|
-
* The instruction operation will carry on in the background.
|
|
312
|
-
*
|
|
313
|
-
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
314
|
-
*
|
|
315
|
-
* async: true is incompatible with noWrite: true, as async: true does not return the resulting document
|
|
316
|
-
*/
|
|
317
|
-
async?: false
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
interface Async {
|
|
321
|
-
/**
|
|
322
|
-
* When async: true, requests responds with status 201 and {_id} as response body as soon as the request is validated.
|
|
323
|
-
* The instruction operation will carry on in the background.
|
|
324
|
-
*
|
|
325
|
-
* When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
|
|
326
|
-
*
|
|
327
|
-
* async: true is incompatible with noWrite, as async: true does not return the resulting document
|
|
328
|
-
*/
|
|
329
|
-
async: true
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Instruction for an existing document.
|
|
334
|
-
* @beta
|
|
335
|
-
*/
|
|
336
|
-
interface ExistingDocumentRequest {
|
|
337
|
-
documentId: string
|
|
338
|
-
createDocument?: never
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Instruction to create a new document
|
|
343
|
-
* @beta
|
|
344
|
-
*/
|
|
345
|
-
interface CreateDocumentRequest<T extends Record<string, Any> = Record<string, Any>> {
|
|
346
|
-
createDocument: {
|
|
347
|
-
/** if no _id is provided, one will be generated. _id is always returned when the requests succeed */
|
|
348
|
-
_id?: string
|
|
349
|
-
_type: string
|
|
350
|
-
} & SanityDocumentStub<T>
|
|
351
|
-
documentId?: never
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/** @beta */
|
|
355
|
-
export type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
356
|
-
| ExistingDocumentRequest
|
|
357
|
-
| CreateDocumentRequest<T>
|
|
358
|
-
) &
|
|
359
|
-
GenerateRequestBase &
|
|
360
|
-
Sync
|
|
361
|
-
|
|
362
|
-
/** @beta */
|
|
363
|
-
export type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
364
|
-
| ExistingDocumentRequest
|
|
365
|
-
| CreateDocumentRequest<T>
|
|
366
|
-
) &
|
|
367
|
-
GenerateRequestBase &
|
|
368
|
-
Async
|
|
369
|
-
|
|
370
|
-
/** @beta */
|
|
371
|
-
export type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> =
|
|
372
|
-
| GenerateSyncInstruction<T>
|
|
373
|
-
| GenerateAsyncInstruction<T>
|