@sanity/blueprints 0.31.0 → 0.33.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/README.md +2 -0
- package/dist/definers/agents.d.ts +43 -0
- package/dist/definers/agents.js +55 -0
- package/dist/definers/agents.js.map +1 -0
- package/dist/definers/context.d.ts +2 -4
- package/dist/definers/context.js +2 -4
- package/dist/definers/context.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/types/agents.d.ts +53 -0
- package/dist/types/agents.js +2 -0
- package/dist/types/agents.js.map +1 -0
- package/dist/types/applications.d.ts +5 -0
- package/dist/types/context.d.ts +7 -14
- package/dist/types/studios.d.ts +18 -0
- package/dist/utils/validation.d.ts +12 -0
- package/dist/utils/validation.js +19 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/validation/agents.d.ts +12 -0
- package/dist/validation/agents.js +143 -0
- package/dist/validation/agents.js.map +1 -0
- package/dist/validation/applications.js +11 -0
- package/dist/validation/applications.js.map +1 -1
- package/dist/validation/context.d.ts +0 -4
- package/dist/validation/context.js +0 -4
- package/dist/validation/context.js.map +1 -1
- package/dist/validation/studios.js +70 -1
- package/dist/validation/studios.js.map +1 -1
- package/package.json +1 -1
- package/src/definers/agents.ts +58 -0
- package/src/definers/context.ts +2 -4
- package/src/index.ts +3 -0
- package/src/types/agents.ts +56 -0
- package/src/types/applications.ts +6 -0
- package/src/types/context.ts +7 -14
- package/src/types/studios.ts +20 -0
- package/src/utils/validation.ts +21 -0
- package/src/validation/agents.ts +149 -0
- package/src/validation/applications.ts +10 -0
- package/src/validation/context.ts +0 -4
- package/src/validation/studios.ts +77 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type {BlueprintError} from '../types/errors.js'
|
|
2
|
+
|
|
3
|
+
/** Slug pattern an agent `name` must match. */
|
|
4
|
+
const AGENT_NAME_SLUG = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/
|
|
5
|
+
|
|
6
|
+
/** Maximum length of an agent `name`. */
|
|
7
|
+
const AGENT_NAME_MAX_LENGTH = 63
|
|
8
|
+
|
|
9
|
+
/** Maximum length of an agent `description`. */
|
|
10
|
+
const AGENT_DESCRIPTION_MAX_LENGTH = 255
|
|
11
|
+
|
|
12
|
+
/** Allowlisted deploy regions (cities). */
|
|
13
|
+
const AGENT_REGIONS = [
|
|
14
|
+
'virginia',
|
|
15
|
+
'ohio',
|
|
16
|
+
'california',
|
|
17
|
+
'portland',
|
|
18
|
+
'montreal',
|
|
19
|
+
'calgary',
|
|
20
|
+
'ireland',
|
|
21
|
+
'london',
|
|
22
|
+
'paris',
|
|
23
|
+
'frankfurt',
|
|
24
|
+
'zurich',
|
|
25
|
+
'stockholm',
|
|
26
|
+
'milan',
|
|
27
|
+
'spain',
|
|
28
|
+
] as const
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Validates that the given resource is a valid Agent.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Validates the `name` slug, optional `description`, the `region` allowlist, and the `model` shape; `model.apiKey` is presence-checked only.
|
|
35
|
+
* @param resource The Agent resource
|
|
36
|
+
* @hidden
|
|
37
|
+
* @category Validation
|
|
38
|
+
* @returns A list of validation errors
|
|
39
|
+
*/
|
|
40
|
+
export function validateAgent(resource: unknown): BlueprintError[] {
|
|
41
|
+
if (!resource) return [{type: 'invalid_value', message: 'Agent config must be provided'}]
|
|
42
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Agent config must be an object'}]
|
|
43
|
+
|
|
44
|
+
const errors: BlueprintError[] = []
|
|
45
|
+
|
|
46
|
+
if ('type' in resource && resource.type !== 'sanity.agent') {
|
|
47
|
+
errors.push({type: 'invalid_value', message: 'Agent type must be `sanity.agent`'})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!('name' in resource)) {
|
|
51
|
+
errors.push({type: 'missing_parameter', message: '`name` is required'})
|
|
52
|
+
} else if (typeof resource.name !== 'string') {
|
|
53
|
+
errors.push({type: 'invalid_type', message: '`name` must be a string'})
|
|
54
|
+
} else {
|
|
55
|
+
if (resource.name.length > AGENT_NAME_MAX_LENGTH) {
|
|
56
|
+
errors.push({type: 'invalid_value', message: `\`name\` must be at most ${AGENT_NAME_MAX_LENGTH} characters`})
|
|
57
|
+
}
|
|
58
|
+
if (!AGENT_NAME_SLUG.test(resource.name)) {
|
|
59
|
+
errors.push({type: 'invalid_format', message: '`name` must match the slug pattern `^[a-z0-9]([a-z0-9-]*[a-z0-9])?$`'})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if ('description' in resource && typeof resource.description !== 'undefined') {
|
|
64
|
+
if (typeof resource.description !== 'string') {
|
|
65
|
+
errors.push({type: 'invalid_type', message: '`description` must be a string'})
|
|
66
|
+
} else if (resource.description.length > AGENT_DESCRIPTION_MAX_LENGTH) {
|
|
67
|
+
errors.push({type: 'invalid_value', message: `\`description\` must be at most ${AGENT_DESCRIPTION_MAX_LENGTH} characters`})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!('region' in resource)) {
|
|
72
|
+
errors.push({type: 'missing_parameter', message: '`region` is required'})
|
|
73
|
+
} else if (typeof resource.region !== 'string') {
|
|
74
|
+
errors.push({type: 'invalid_type', message: '`region` must be a string'})
|
|
75
|
+
} else if (!AGENT_REGIONS.includes(resource.region as (typeof AGENT_REGIONS)[number])) {
|
|
76
|
+
errors.push({type: 'invalid_value', message: `\`region\` must be one of ${AGENT_REGIONS.join(', ')}`})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
errors.push(...validateAgentModel(resource))
|
|
80
|
+
|
|
81
|
+
return errors
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Validates the `model` value on an agent resource; `apiKey` is presence-checked only.
|
|
86
|
+
* @param resource The agent resource (already known to be an object)
|
|
87
|
+
* @returns A list of validation errors
|
|
88
|
+
*/
|
|
89
|
+
function validateAgentModel(resource: object): BlueprintError[] {
|
|
90
|
+
if (!('model' in resource) || typeof resource.model === 'undefined' || resource.model === null) {
|
|
91
|
+
return [{type: 'missing_parameter', message: '`model` is required'}]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const {model} = resource
|
|
95
|
+
if (typeof model !== 'object') {
|
|
96
|
+
return [{type: 'invalid_type', message: '`model` must be an object'}]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const errors: BlueprintError[] = []
|
|
100
|
+
|
|
101
|
+
if (!('provider' in model)) {
|
|
102
|
+
errors.push({type: 'missing_parameter', message: '`model.provider` is required'})
|
|
103
|
+
} else if (typeof model.provider !== 'string') {
|
|
104
|
+
errors.push({type: 'invalid_type', message: '`model.provider` must be a string'})
|
|
105
|
+
} else if (model.provider.length === 0) {
|
|
106
|
+
errors.push({type: 'invalid_value', message: '`model.provider` must be a non-empty string'})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!('id' in model)) {
|
|
110
|
+
errors.push({type: 'missing_parameter', message: '`model.id` is required'})
|
|
111
|
+
} else if (typeof model.id !== 'string') {
|
|
112
|
+
errors.push({type: 'invalid_type', message: '`model.id` must be a string'})
|
|
113
|
+
} else if (model.id.length === 0) {
|
|
114
|
+
errors.push({type: 'invalid_value', message: '`model.id` must be a non-empty string'})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if ('baseURL' in model && typeof model.baseURL !== 'undefined') {
|
|
118
|
+
if (typeof model.baseURL !== 'string') {
|
|
119
|
+
errors.push({type: 'invalid_type', message: '`model.baseURL` must be a string'})
|
|
120
|
+
} else if (!isWellFormedUrl(model.baseURL)) {
|
|
121
|
+
errors.push({type: 'invalid_format', message: '`model.baseURL` must be a well-formed URL'})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!('apiKey' in model)) {
|
|
126
|
+
errors.push({type: 'missing_parameter', message: '`model.apiKey` is required'})
|
|
127
|
+
} else if (typeof model.apiKey !== 'string') {
|
|
128
|
+
errors.push({type: 'invalid_type', message: '`model.apiKey` must be a string'})
|
|
129
|
+
} else if (model.apiKey.length === 0) {
|
|
130
|
+
errors.push({type: 'invalid_value', message: 'model.apiKey is empty'})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return errors
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Checks whether a value is a well-formed absolute URL.
|
|
138
|
+
* @param value The value to check
|
|
139
|
+
* @returns `true` if the value parses as a URL
|
|
140
|
+
*/
|
|
141
|
+
function isWellFormedUrl(value: string): boolean {
|
|
142
|
+
try {
|
|
143
|
+
// eslint-disable-next-line no-new
|
|
144
|
+
new URL(value)
|
|
145
|
+
return true
|
|
146
|
+
} catch {
|
|
147
|
+
return false
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -296,6 +296,16 @@ export function validateApplication(resource: unknown): BlueprintError[] {
|
|
|
296
296
|
errors.push({type: 'invalid_value', message: 'visibility must be one of `default`, `unlisted`, or `disabled`'})
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
+
if ('autoUpdates' in resource && typeof resource.autoUpdates !== 'undefined') {
|
|
300
|
+
if (!resource.autoUpdates || typeof resource.autoUpdates !== 'object') {
|
|
301
|
+
errors.push({type: 'invalid_type', message: 'Application autoUpdates must be an object'})
|
|
302
|
+
} else if (!('enabled' in resource.autoUpdates)) {
|
|
303
|
+
errors.push({type: 'missing_parameter', message: 'Application autoUpdates.enabled is required'})
|
|
304
|
+
} else if (typeof resource.autoUpdates.enabled !== 'boolean') {
|
|
305
|
+
errors.push({type: 'invalid_type', message: 'Application autoUpdates.enabled must be a boolean'})
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
299
309
|
if (!('views' in resource) || typeof resource.views === 'undefined') {
|
|
300
310
|
errors.push({type: 'missing_parameter', message: 'Application must declare at least one view'})
|
|
301
311
|
} else if (!Array.isArray(resource.views)) {
|
|
@@ -39,8 +39,6 @@ function validateDatasetSettings(source: object): BlueprintError[] {
|
|
|
39
39
|
/**
|
|
40
40
|
* Validates that the given resource is a valid Context knowledge base.
|
|
41
41
|
* @param resource The Context knowledge base resource
|
|
42
|
-
* @alpha
|
|
43
|
-
* @hidden
|
|
44
42
|
* @category Validation
|
|
45
43
|
* @returns A list of validation errors
|
|
46
44
|
*/
|
|
@@ -63,8 +61,6 @@ export function validateContextKnowledgeBase(resource: unknown): BlueprintError[
|
|
|
63
61
|
/**
|
|
64
62
|
* Validates that the given resource is a valid Context MCP endpoint.
|
|
65
63
|
* @param resource The Context MCP endpoint resource
|
|
66
|
-
* @alpha
|
|
67
|
-
* @hidden
|
|
68
64
|
* @category Validation
|
|
69
65
|
* @returns A list of validation errors
|
|
70
66
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {BlueprintError} from '../types/errors.js'
|
|
2
2
|
import {APPLICATION_VISIBILITIES} from '../types/studios.js'
|
|
3
|
-
import {isReference} from '../utils/validation.js'
|
|
3
|
+
import {isReference, validateStringField} from '../utils/validation.js'
|
|
4
4
|
import {validateResource} from './resources.js'
|
|
5
5
|
|
|
6
6
|
/** hostname validity pattern */
|
|
@@ -105,5 +105,81 @@ export function validateStudio(resource: unknown): BlueprintError[] {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
if ('mfManifest' in resource && typeof resource.mfManifest !== 'undefined') {
|
|
109
|
+
if (!resource.mfManifest || typeof resource.mfManifest !== 'object' || Array.isArray(resource.mfManifest)) {
|
|
110
|
+
errors.push({type: 'invalid_type', message: 'Studio mfManifest must be an object'})
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if ('workspaces' in resource && typeof resource.workspaces !== 'undefined') {
|
|
115
|
+
if (!Array.isArray(resource.workspaces)) {
|
|
116
|
+
errors.push({type: 'invalid_type', message: 'Studio workspaces must be an array'})
|
|
117
|
+
} else {
|
|
118
|
+
resource.workspaces.forEach((workspace, index) => {
|
|
119
|
+
errors.push(...validateStudioWorkspace(workspace, `Studio workspaces[${index}]`))
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if ('schemaInputs' in resource && typeof resource.schemaInputs !== 'undefined') {
|
|
125
|
+
if (!Array.isArray(resource.schemaInputs)) {
|
|
126
|
+
errors.push({type: 'invalid_type', message: 'Studio schemaInputs must be an array'})
|
|
127
|
+
} else {
|
|
128
|
+
resource.schemaInputs.forEach((schemaInput, index) => {
|
|
129
|
+
errors.push(...validateStudioSchemaInput(schemaInput, `Studio schemaInputs[${index}]`))
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return errors
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Validates a single workspace extracted from the studio configuration.
|
|
139
|
+
* @param workspace The workspace to validate
|
|
140
|
+
* @param label The label used as the prefix of error messages
|
|
141
|
+
* @returns A list of validation errors
|
|
142
|
+
*/
|
|
143
|
+
function validateStudioWorkspace(workspace: unknown, label: string): BlueprintError[] {
|
|
144
|
+
if (!workspace) return [{type: 'invalid_value', message: `${label} must be provided`}]
|
|
145
|
+
if (typeof workspace !== 'object' || Array.isArray(workspace)) return [{type: 'invalid_type', message: `${label} must be an object`}]
|
|
146
|
+
|
|
147
|
+
const errors: BlueprintError[] = []
|
|
148
|
+
|
|
149
|
+
for (const field of ['projectId', 'dataset', 'schemaDescriptorId', 'name']) {
|
|
150
|
+
errors.push(...validateStringField(workspace, field, label, {required: true}))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (const field of ['title', 'subtitle', 'basePath', 'icon']) {
|
|
154
|
+
errors.push(...validateStringField(workspace, field, label, {required: false}))
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return errors
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Validates a single schema input extracted from the studio's schema definition.
|
|
162
|
+
* @param schemaInput The schema input to validate
|
|
163
|
+
* @param label The label used as the prefix of error messages
|
|
164
|
+
* @returns A list of validation errors
|
|
165
|
+
*/
|
|
166
|
+
function validateStudioSchemaInput(schemaInput: unknown, label: string): BlueprintError[] {
|
|
167
|
+
if (!schemaInput) return [{type: 'invalid_value', message: `${label} must be provided`}]
|
|
168
|
+
if (typeof schemaInput !== 'object' || Array.isArray(schemaInput)) return [{type: 'invalid_type', message: `${label} must be an object`}]
|
|
169
|
+
|
|
170
|
+
const errors: BlueprintError[] = []
|
|
171
|
+
|
|
172
|
+
for (const field of ['projectId', 'dataset', 'name']) {
|
|
173
|
+
errors.push(...validateStringField(schemaInput, field, label, {required: true}))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
errors.push(...validateStringField(schemaInput, 'title', label, {required: false}))
|
|
177
|
+
|
|
178
|
+
if (!('manifestSchema' in schemaInput) || typeof schemaInput.manifestSchema === 'undefined') {
|
|
179
|
+
errors.push({type: 'missing_parameter', message: `${label}.manifestSchema is required`})
|
|
180
|
+
} else if (!Array.isArray(schemaInput.manifestSchema)) {
|
|
181
|
+
errors.push({type: 'invalid_type', message: `${label}.manifestSchema must be an array`})
|
|
182
|
+
}
|
|
183
|
+
|
|
108
184
|
return errors
|
|
109
185
|
}
|