@sanity/blueprints 0.30.0 → 0.32.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/definers/context.d.ts +88 -0
- package/dist/definers/context.js +108 -0
- package/dist/definers/context.js.map +1 -0
- package/dist/definers/functions/durable.d.ts +1 -5
- package/dist/definers/functions/durable.js +5 -9
- package/dist/definers/functions/durable.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/context.d.ts +95 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/functions/index.d.ts +4 -10
- 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/context.d.ts +15 -0
- package/dist/validation/context.js +132 -0
- package/dist/validation/context.js.map +1 -0
- package/dist/validation/studios.js +70 -1
- package/dist/validation/studios.js.map +1 -1
- package/package.json +1 -1
- package/src/definers/context.ts +122 -0
- package/src/definers/functions/durable.ts +5 -9
- package/src/index.ts +3 -0
- package/src/types/context.ts +102 -0
- package/src/types/functions/index.ts +4 -10
- package/src/types/studios.ts +20 -0
- package/src/utils/validation.ts +21 -0
- package/src/validation/context.ts +138 -0
- package/src/validation/studios.ts +77 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { validateResource } from '../index.js';
|
|
2
|
+
import { isReference } from '../utils/validation.js';
|
|
3
|
+
const MCP_ENDPOINT_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4
|
+
const MCP_ENDPOINT_ID_PATTERN = /^mcp[a-z0-9]{8}$/;
|
|
5
|
+
const DATASET_SOURCE_PATTERN = /^[a-z0-9]+\.[a-z0-9][a-z0-9_-]*$/;
|
|
6
|
+
const DATASET_PERSPECTIVES = ['published', 'drafts', 'raw'];
|
|
7
|
+
function validateText(resource, field, label, options) {
|
|
8
|
+
if (!(field in resource)) {
|
|
9
|
+
return options.required ? [{ type: 'missing_parameter', message: `${label} is required` }] : [];
|
|
10
|
+
}
|
|
11
|
+
const value = Reflect.get(resource, field);
|
|
12
|
+
if (typeof value !== 'string')
|
|
13
|
+
return [{ type: 'invalid_type', message: `${label} must be a string` }];
|
|
14
|
+
if (value.length === 0)
|
|
15
|
+
return [{ type: 'invalid_value', message: `${label} must not be empty` }];
|
|
16
|
+
if (value.length > options.max) {
|
|
17
|
+
return [{ type: 'invalid_value', message: `${label} must be ${options.max} characters or less` }];
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
function validateDatasetSettings(source) {
|
|
22
|
+
const errors = [];
|
|
23
|
+
const workspace = Reflect.get(source, 'workspace');
|
|
24
|
+
const perspective = Reflect.get(source, 'perspective');
|
|
25
|
+
const semanticSearch = Reflect.get(source, 'semanticSearch');
|
|
26
|
+
if (workspace != null && (typeof workspace !== 'string' || workspace.length === 0)) {
|
|
27
|
+
errors.push({ type: 'invalid_type', message: 'Dataset source `workspace` must be a non-empty string or null' });
|
|
28
|
+
}
|
|
29
|
+
if (perspective != null && !DATASET_PERSPECTIVES.includes(perspective)) {
|
|
30
|
+
errors.push({ type: 'invalid_value', message: 'Dataset source `perspective` must be `published`, `drafts`, `raw` or null' });
|
|
31
|
+
}
|
|
32
|
+
if (semanticSearch != null && typeof semanticSearch !== 'boolean') {
|
|
33
|
+
errors.push({ type: 'invalid_type', message: 'Dataset source `semanticSearch` must be a boolean or null' });
|
|
34
|
+
}
|
|
35
|
+
return errors;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validates that the given resource is a valid Context knowledge base.
|
|
39
|
+
* @param resource The Context knowledge base resource
|
|
40
|
+
* @category Validation
|
|
41
|
+
* @returns A list of validation errors
|
|
42
|
+
*/
|
|
43
|
+
export function validateContextKnowledgeBase(resource) {
|
|
44
|
+
if (!resource)
|
|
45
|
+
return [{ type: 'invalid_value', message: 'Knowledge base config must be provided' }];
|
|
46
|
+
if (typeof resource !== 'object')
|
|
47
|
+
return [{ type: 'invalid_type', message: 'Knowledge base config must be an object' }];
|
|
48
|
+
const errors = validateResource(resource);
|
|
49
|
+
if ('type' in resource && resource.type !== 'sanity.context.knowledge-base') {
|
|
50
|
+
errors.push({ type: 'invalid_value', message: 'Knowledge base type must be `sanity.context.knowledge-base`' });
|
|
51
|
+
}
|
|
52
|
+
errors.push(...validateText(resource, 'title', 'Knowledge base title', { required: true, max: 100 }));
|
|
53
|
+
errors.push(...validateText(resource, 'description', 'Knowledge base description', { required: true, max: 2000 }));
|
|
54
|
+
return errors;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validates that the given resource is a valid Context MCP endpoint.
|
|
58
|
+
* @param resource The Context MCP endpoint resource
|
|
59
|
+
* @category Validation
|
|
60
|
+
* @returns A list of validation errors
|
|
61
|
+
*/
|
|
62
|
+
export function validateContextMcpEndpoint(resource) {
|
|
63
|
+
if (!resource)
|
|
64
|
+
return [{ type: 'invalid_value', message: 'MCP endpoint config must be provided' }];
|
|
65
|
+
if (typeof resource !== 'object')
|
|
66
|
+
return [{ type: 'invalid_type', message: 'MCP endpoint config must be an object' }];
|
|
67
|
+
const errors = validateResource(resource);
|
|
68
|
+
if ('type' in resource && resource.type !== 'sanity.context.mcp') {
|
|
69
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint type must be `sanity.context.mcp`' });
|
|
70
|
+
}
|
|
71
|
+
if ('name' in resource && typeof resource.name === 'string') {
|
|
72
|
+
if (resource.name.length > 64 || !MCP_ENDPOINT_NAME_PATTERN.test(resource.name)) {
|
|
73
|
+
errors.push({
|
|
74
|
+
type: 'invalid_format',
|
|
75
|
+
message: 'MCP endpoint name must be lowercase letters, digits and single hyphens, up to 64 characters',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else if (resource.name === 'by-name' || MCP_ENDPOINT_ID_PATTERN.test(resource.name)) {
|
|
79
|
+
errors.push({ type: 'invalid_value', message: `MCP endpoint name "${resource.name}" is reserved` });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
errors.push(...validateText(resource, 'title', 'MCP endpoint title', { required: true, max: 100 }));
|
|
83
|
+
errors.push(...validateText(resource, 'instructions', 'MCP endpoint instructions', { required: false, max: 10_000 }));
|
|
84
|
+
errors.push(...validateText(resource, 'groqFilter', 'MCP endpoint GROQ filter', { required: false, max: 10_000 }));
|
|
85
|
+
if (!('sources' in resource)) {
|
|
86
|
+
errors.push({ type: 'missing_parameter', message: 'MCP endpoint sources are required' });
|
|
87
|
+
return errors;
|
|
88
|
+
}
|
|
89
|
+
if (!Array.isArray(resource.sources) || resource.sources.length === 0) {
|
|
90
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint must have at least one source' });
|
|
91
|
+
return errors;
|
|
92
|
+
}
|
|
93
|
+
if (resource.sources.length > 100) {
|
|
94
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint can have at most 100 sources' });
|
|
95
|
+
}
|
|
96
|
+
let datasets = 0;
|
|
97
|
+
for (const source of resource.sources) {
|
|
98
|
+
if (!source || typeof source !== 'object' || !('type' in source) || !('id' in source)) {
|
|
99
|
+
errors.push({ type: 'invalid_value', message: 'Each MCP endpoint source needs a `type` and an `id`' });
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (typeof source.id !== 'string' || source.id.length === 0) {
|
|
103
|
+
errors.push({ type: 'invalid_type', message: 'MCP endpoint source `id` must be a non-empty string' });
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (source.type === 'dataset') {
|
|
107
|
+
datasets++;
|
|
108
|
+
// The provider checks the format before references resolve, and no resource exposes `<projectId>.<datasetName>`
|
|
109
|
+
if (source.id.startsWith('$.resources.')) {
|
|
110
|
+
errors.push({
|
|
111
|
+
type: 'invalid_value',
|
|
112
|
+
message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>", not a resource reference`,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
else if (!isReference(source.id) && !DATASET_SOURCE_PATTERN.test(source.id)) {
|
|
116
|
+
errors.push({ type: 'invalid_format', message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>"` });
|
|
117
|
+
}
|
|
118
|
+
errors.push(...validateDatasetSettings(source));
|
|
119
|
+
}
|
|
120
|
+
else if (source.type !== 'knowledge-base') {
|
|
121
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint source `type` must be `knowledge-base` or `dataset`' });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (datasets > 1) {
|
|
125
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint can have at most one dataset source' });
|
|
126
|
+
}
|
|
127
|
+
if (datasets === 0 && 'groqFilter' in resource) {
|
|
128
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint GROQ filter requires a dataset source' });
|
|
129
|
+
}
|
|
130
|
+
return errors;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/validation/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,gBAAgB,EAAC,MAAM,aAAa,CAAA;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAA;AAElD,MAAM,yBAAyB,GAAG,4BAA4B,CAAA;AAC9D,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AAClD,MAAM,sBAAsB,GAAG,kCAAkC,CAAA;AACjE,MAAM,oBAAoB,GAAc,CAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AAEtE,SAAS,YAAY,CAAC,QAAgB,EAAE,KAAa,EAAE,KAAa,EAAE,OAAyC;IAC7G,IAAI,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,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CAAC;YAC5C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kEAAkE,EAAC,CAAC,CAAA;QACnH,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kDAAkD,EAAC,CAAC,CAAA;IACnG,CAAC;IACD,IAAI,QAAQ,KAAK,CAAC,IAAI,YAAY,IAAI,QAAQ,EAAE,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,oDAAoD,EAAC,CAAC,CAAA;IACrG,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APPLICATION_VISIBILITIES } from '../types/studios.js';
|
|
2
|
-
import { isReference } from '../utils/validation.js';
|
|
2
|
+
import { isReference, validateStringField } from '../utils/validation.js';
|
|
3
3
|
import { validateResource } from './resources.js';
|
|
4
4
|
/** hostname validity pattern */
|
|
5
5
|
const STUDIO_SLUG_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
@@ -94,6 +94,75 @@ export function validateStudio(resource) {
|
|
|
94
94
|
errors.push({ type: 'invalid_type', message: 'Studio sourceMap must be a boolean' });
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
if ('mfManifest' in resource && typeof resource.mfManifest !== 'undefined') {
|
|
98
|
+
if (!resource.mfManifest || typeof resource.mfManifest !== 'object' || Array.isArray(resource.mfManifest)) {
|
|
99
|
+
errors.push({ type: 'invalid_type', message: 'Studio mfManifest must be an object' });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if ('workspaces' in resource && typeof resource.workspaces !== 'undefined') {
|
|
103
|
+
if (!Array.isArray(resource.workspaces)) {
|
|
104
|
+
errors.push({ type: 'invalid_type', message: 'Studio workspaces must be an array' });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resource.workspaces.forEach((workspace, index) => {
|
|
108
|
+
errors.push(...validateStudioWorkspace(workspace, `Studio workspaces[${index}]`));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if ('schemaInputs' in resource && typeof resource.schemaInputs !== 'undefined') {
|
|
113
|
+
if (!Array.isArray(resource.schemaInputs)) {
|
|
114
|
+
errors.push({ type: 'invalid_type', message: 'Studio schemaInputs must be an array' });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
resource.schemaInputs.forEach((schemaInput, index) => {
|
|
118
|
+
errors.push(...validateStudioSchemaInput(schemaInput, `Studio schemaInputs[${index}]`));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return errors;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validates a single workspace extracted from the studio configuration.
|
|
126
|
+
* @param workspace The workspace to validate
|
|
127
|
+
* @param label The label used as the prefix of error messages
|
|
128
|
+
* @returns A list of validation errors
|
|
129
|
+
*/
|
|
130
|
+
function validateStudioWorkspace(workspace, label) {
|
|
131
|
+
if (!workspace)
|
|
132
|
+
return [{ type: 'invalid_value', message: `${label} must be provided` }];
|
|
133
|
+
if (typeof workspace !== 'object' || Array.isArray(workspace))
|
|
134
|
+
return [{ type: 'invalid_type', message: `${label} must be an object` }];
|
|
135
|
+
const errors = [];
|
|
136
|
+
for (const field of ['projectId', 'dataset', 'schemaDescriptorId', 'name']) {
|
|
137
|
+
errors.push(...validateStringField(workspace, field, label, { required: true }));
|
|
138
|
+
}
|
|
139
|
+
for (const field of ['title', 'subtitle', 'basePath', 'icon']) {
|
|
140
|
+
errors.push(...validateStringField(workspace, field, label, { required: false }));
|
|
141
|
+
}
|
|
142
|
+
return errors;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Validates a single schema input extracted from the studio's schema definition.
|
|
146
|
+
* @param schemaInput The schema input to validate
|
|
147
|
+
* @param label The label used as the prefix of error messages
|
|
148
|
+
* @returns A list of validation errors
|
|
149
|
+
*/
|
|
150
|
+
function validateStudioSchemaInput(schemaInput, label) {
|
|
151
|
+
if (!schemaInput)
|
|
152
|
+
return [{ type: 'invalid_value', message: `${label} must be provided` }];
|
|
153
|
+
if (typeof schemaInput !== 'object' || Array.isArray(schemaInput))
|
|
154
|
+
return [{ type: 'invalid_type', message: `${label} must be an object` }];
|
|
155
|
+
const errors = [];
|
|
156
|
+
for (const field of ['projectId', 'dataset', 'name']) {
|
|
157
|
+
errors.push(...validateStringField(schemaInput, field, label, { required: true }));
|
|
158
|
+
}
|
|
159
|
+
errors.push(...validateStringField(schemaInput, 'title', label, { required: false }));
|
|
160
|
+
if (!('manifestSchema' in schemaInput) || typeof schemaInput.manifestSchema === 'undefined') {
|
|
161
|
+
errors.push({ type: 'missing_parameter', message: `${label}.manifestSchema is required` });
|
|
162
|
+
}
|
|
163
|
+
else if (!Array.isArray(schemaInput.manifestSchema)) {
|
|
164
|
+
errors.push({ type: 'invalid_type', message: `${label}.manifestSchema must be an array` });
|
|
165
|
+
}
|
|
97
166
|
return errors;
|
|
98
167
|
}
|
|
99
168
|
//# sourceMappingURL=studios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studios.js","sourceRoot":"","sources":["../../src/validation/studios.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,wBAAwB,EAAC,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"studios.js","sourceRoot":"","sources":["../../src/validation/studios.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,wBAAwB,EAAC,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,wBAAwB,CAAA;AACvE,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,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AAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,KAAK,oBAAoB,EAAC,CAAC,CAAA;IAEzI,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,KAAK,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC,CAAA;IAClF,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC,CAAC,CAAA;IAEnF,IAAI,CAAC,CAAC,gBAAgB,IAAI,WAAW,CAAC,IAAI,OAAO,WAAW,CAAC,cAAc,KAAK,WAAW,EAAE,CAAC;QAC5F,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,GAAG,KAAK,6BAA6B,EAAC,CAAC,CAAA;IAC1F,CAAC;SAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,KAAK,kCAAkC,EAAC,CAAC,CAAA;IAC1F,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BlueprintContextKnowledgeBaseConfig,
|
|
3
|
+
type BlueprintContextKnowledgeBaseResource,
|
|
4
|
+
type BlueprintContextMcpEndpointConfig,
|
|
5
|
+
type BlueprintContextMcpEndpointResource,
|
|
6
|
+
validateContextKnowledgeBase,
|
|
7
|
+
validateContextMcpEndpoint,
|
|
8
|
+
} from '../index.js'
|
|
9
|
+
import {runValidation} from '../utils/validation.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Defines a Context knowledge base.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* The blueprint must be scoped to an organization. A new knowledge base has no sources. Add sources in the Context API
|
|
16
|
+
* or the dashboard.
|
|
17
|
+
*
|
|
18
|
+
* The default deletion policy is `retain`. If the stack is destroyed, the knowledge base is detached and not deleted. If
|
|
19
|
+
* the resource is removed from the blueprint, the deploy fails. To remove the resource, first deploy it with one of these
|
|
20
|
+
* `lifecycle` values:
|
|
21
|
+
* - `{ownershipAction: {type: 'detach'}}` keeps the knowledge base.
|
|
22
|
+
* - `{deletionPolicy: 'allow'}` deletes the knowledge base.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* defineContextKnowledgeBase({
|
|
27
|
+
* name: 'product-docs',
|
|
28
|
+
* title: 'Product docs',
|
|
29
|
+
* description: 'Everything about the product',
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Detach before removal
|
|
34
|
+
* ```ts
|
|
35
|
+
* defineContextKnowledgeBase({
|
|
36
|
+
* name: 'product-docs',
|
|
37
|
+
* title: 'Product docs',
|
|
38
|
+
* description: 'Everything about the product',
|
|
39
|
+
* lifecycle: {ownershipAction: {type: 'detach'}},
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
* @param parameters The knowledge base configuration
|
|
43
|
+
* @public
|
|
44
|
+
* @beta Deploying Context via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
45
|
+
* @category Definers
|
|
46
|
+
* @expandType BlueprintContextKnowledgeBaseConfig
|
|
47
|
+
* @returns The knowledge base resource
|
|
48
|
+
*/
|
|
49
|
+
export function defineContextKnowledgeBase(parameters: BlueprintContextKnowledgeBaseConfig): BlueprintContextKnowledgeBaseResource {
|
|
50
|
+
const knowledgeBaseResource: BlueprintContextKnowledgeBaseResource = {
|
|
51
|
+
...parameters,
|
|
52
|
+
type: 'sanity.context.knowledge-base',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
runValidation(() => validateContextKnowledgeBase(knowledgeBaseResource))
|
|
56
|
+
|
|
57
|
+
return knowledgeBaseResource
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Defines a Context MCP endpoint that agents connect to.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* The blueprint must be scoped to an organization.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* defineContextMcpEndpoint({
|
|
69
|
+
* name: 'support-agent',
|
|
70
|
+
* title: 'Support agent',
|
|
71
|
+
* sources: [{type: 'dataset', id: 'abc123.production'}],
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Knowledge base and dataset sources
|
|
76
|
+
* ```ts
|
|
77
|
+
* const productDocs = defineContextKnowledgeBase({
|
|
78
|
+
* name: 'product-docs',
|
|
79
|
+
* title: 'Product docs',
|
|
80
|
+
* description: 'Everything about the product',
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* defineContextMcpEndpoint({
|
|
84
|
+
* name: 'support-agent',
|
|
85
|
+
* title: 'Support agent',
|
|
86
|
+
* sources: [productDocs, {type: 'dataset', id: 'abc123.production'}],
|
|
87
|
+
* instructions: 'Answer questions about the product.',
|
|
88
|
+
* groqFilter: '_type in ["article", "faq"]',
|
|
89
|
+
* })
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example Dataset settings
|
|
93
|
+
* ```ts
|
|
94
|
+
* defineContextMcpEndpoint({
|
|
95
|
+
* name: 'editor-agent',
|
|
96
|
+
* title: 'Editor agent',
|
|
97
|
+
* sources: [{type: 'dataset', id: 'abc123.production', workspace: 'marketing', perspective: 'drafts', semanticSearch: false}],
|
|
98
|
+
* })
|
|
99
|
+
* ```
|
|
100
|
+
* @param parameters The MCP endpoint configuration
|
|
101
|
+
* @public
|
|
102
|
+
* @beta Deploying Context via Blueprints is experimental. This feature is stabilizing but may still be subject to breaking changes.
|
|
103
|
+
* @category Definers
|
|
104
|
+
* @expandType BlueprintContextMcpEndpointConfig
|
|
105
|
+
* @returns The MCP endpoint resource
|
|
106
|
+
*/
|
|
107
|
+
export function defineContextMcpEndpoint(parameters: BlueprintContextMcpEndpointConfig): BlueprintContextMcpEndpointResource {
|
|
108
|
+
const mcpEndpointResource: BlueprintContextMcpEndpointResource = {
|
|
109
|
+
...parameters,
|
|
110
|
+
type: 'sanity.context.mcp',
|
|
111
|
+
// Malformed sources pass through untouched, so validation reports them instead of throwing here.
|
|
112
|
+
sources: Array.isArray(parameters.sources)
|
|
113
|
+
? parameters.sources.map((source) =>
|
|
114
|
+
source?.type === 'sanity.context.knowledge-base' ? {type: 'knowledge-base', id: `$.resources.${source.name}`} : source,
|
|
115
|
+
)
|
|
116
|
+
: parameters.sources,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
runValidation(() => validateContextMcpEndpoint(mcpEndpointResource))
|
|
120
|
+
|
|
121
|
+
return mcpEndpointResource
|
|
122
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {type BlueprintDurableConfig, type BlueprintDurableFunctionResource, validateDurableFunction} from '../../index.js'
|
|
2
|
-
import {createDebounceObject} from '../../utils/debounce.js'
|
|
3
2
|
import {parseDuration} from '../../utils/parse-duration.js'
|
|
4
3
|
import {runValidation} from '../../utils/validation.js'
|
|
5
4
|
import {defineFunction} from './index.js'
|
|
@@ -13,29 +12,26 @@ import {defineFunction} from './index.js'
|
|
|
13
12
|
* defineDurableFunction({
|
|
14
13
|
* name: 'daily-cleanup',
|
|
15
14
|
* event: {type: 'document', on: ['create'], filter: "_type == 'post'"},
|
|
16
|
-
* concurrency: 5,
|
|
17
|
-
* debounce: 10,
|
|
18
15
|
* })
|
|
19
16
|
* ```
|
|
20
17
|
*
|
|
21
|
-
*
|
|
22
18
|
* @param functionConfig The configuration for the function
|
|
23
19
|
* @category Definers
|
|
24
|
-
* @
|
|
20
|
+
* @beta Deploying Durable Functions via Blueprints is experimental.
|
|
25
21
|
* @public
|
|
26
|
-
* @hidden
|
|
27
22
|
* @expandType BlueprintDurableConfig
|
|
28
23
|
* @returns The validated durable function resource
|
|
29
24
|
*/
|
|
30
25
|
export function defineDurableFunction(functionConfig: BlueprintDurableConfig): BlueprintDurableFunctionResource {
|
|
31
|
-
const {name, event,
|
|
26
|
+
const {name, event, src, durableTimeout} = functionConfig
|
|
32
27
|
const functionResource: BlueprintDurableFunctionResource = {
|
|
33
28
|
...defineFunction({...functionConfig, src: src ?? `functions/${name}`}, {skipValidation: true}),
|
|
34
29
|
type: 'sanity.function.durable',
|
|
35
30
|
...(event !== undefined && {event}),
|
|
36
31
|
...(durableTimeout !== undefined && {durableTimeout: parseDuration(durableTimeout, 's')}),
|
|
37
|
-
|
|
38
|
-
...(
|
|
32
|
+
// TODO: eventually support queue fields once backend supports it
|
|
33
|
+
// ...(concurrency !== undefined && {concurrency}),
|
|
34
|
+
// ...(debounce !== undefined && {debounce: createDebounceObject(debounce)}),
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
runValidation(() => validateDurableFunction(functionResource))
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export * from './definers/applications.js'
|
|
11
11
|
export * from './definers/blueprints.js'
|
|
12
|
+
export * from './definers/context.js'
|
|
12
13
|
export * from './definers/cors.js'
|
|
13
14
|
export * from './definers/datasets.js'
|
|
14
15
|
export * from './definers/functions/document.js'
|
|
@@ -40,6 +41,7 @@ export * from './definers/webhooks.js'
|
|
|
40
41
|
*/
|
|
41
42
|
export * from './types/applications.js'
|
|
42
43
|
export * from './types/blueprints.js'
|
|
44
|
+
export * from './types/context.js'
|
|
43
45
|
export * from './types/cors.js'
|
|
44
46
|
export * from './types/datasets.js'
|
|
45
47
|
export * from './types/errors.js'
|
|
@@ -61,6 +63,7 @@ export * from './types/webhooks.js'
|
|
|
61
63
|
*/
|
|
62
64
|
export * from './validation/applications.js'
|
|
63
65
|
export * from './validation/blueprints.js'
|
|
66
|
+
export * from './validation/context.js'
|
|
64
67
|
export * from './validation/cors.js'
|
|
65
68
|
export * from './validation/datasets.js'
|
|
66
69
|
export * from './validation/functions.js'
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type {BlueprintResource} from '../index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A knowledge base that a Context MCP endpoint serves.
|
|
5
|
+
* @beta This feature is subject to breaking changes.
|
|
6
|
+
* @category Resource Types
|
|
7
|
+
*/
|
|
8
|
+
export interface ContextKnowledgeBaseSource {
|
|
9
|
+
type: 'knowledge-base'
|
|
10
|
+
/** A knowledge base in the blueprint as `$.resources.<name>`, or the ID (`kb…`) of a knowledge base. */
|
|
11
|
+
id: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A Sanity dataset that a Context MCP endpoint serves.
|
|
16
|
+
* @beta This feature is subject to breaking changes.
|
|
17
|
+
* @category Resource Types
|
|
18
|
+
*/
|
|
19
|
+
export interface ContextDatasetSource {
|
|
20
|
+
type: 'dataset'
|
|
21
|
+
/** The dataset as `<projectId>.<datasetName>`, for example `abc123.production`. It can't be a `$.resources.<name>` reference. */
|
|
22
|
+
id: string
|
|
23
|
+
/** The studio workspace whose schema agents use, by name. `null` uses the studio's first workspace. */
|
|
24
|
+
workspace?: string | null
|
|
25
|
+
/** The perspective agents query the dataset with. `null` uses `published`. */
|
|
26
|
+
perspective?: 'published' | 'drafts' | 'raw' | null
|
|
27
|
+
/**
|
|
28
|
+
* Whether agents can use semantic search on the dataset. `false` turns it off. `true` or `null` use it while the
|
|
29
|
+
* dataset has embeddings enabled.
|
|
30
|
+
*/
|
|
31
|
+
semanticSearch?: boolean | null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Content that a Context MCP endpoint serves.
|
|
36
|
+
* @beta This feature is subject to breaking changes.
|
|
37
|
+
* @category Resource Types
|
|
38
|
+
*/
|
|
39
|
+
export type ContextMcpEndpointSource = ContextKnowledgeBaseSource | ContextDatasetSource
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A Context knowledge base resource.
|
|
43
|
+
* @beta This feature is subject to breaking changes.
|
|
44
|
+
* @category Resource Types
|
|
45
|
+
*/
|
|
46
|
+
export interface BlueprintContextKnowledgeBaseResource extends BlueprintResource {
|
|
47
|
+
type: 'sanity.context.knowledge-base'
|
|
48
|
+
/**
|
|
49
|
+
* The resource name in the blueprint. The knowledge base has no name, only a `title`. With the default deletion
|
|
50
|
+
* policy (`retain`), a deploy fails if this name changes.
|
|
51
|
+
*/
|
|
52
|
+
name: string
|
|
53
|
+
/** The knowledge base title, up to 100 characters. */
|
|
54
|
+
title: string
|
|
55
|
+
/** What the knowledge base covers, up to 2,000 characters. */
|
|
56
|
+
description: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Configuration for a Context knowledge base.
|
|
61
|
+
* @beta This feature is subject to breaking changes.
|
|
62
|
+
* @category Resource Types
|
|
63
|
+
* @interface
|
|
64
|
+
*/
|
|
65
|
+
export type BlueprintContextKnowledgeBaseConfig = Omit<BlueprintContextKnowledgeBaseResource, 'type'>
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A Context MCP endpoint resource.
|
|
69
|
+
* @beta This feature is subject to breaking changes.
|
|
70
|
+
* @category Resource Types
|
|
71
|
+
*/
|
|
72
|
+
export interface BlueprintContextMcpEndpointResource extends BlueprintResource {
|
|
73
|
+
type: 'sanity.context.mcp'
|
|
74
|
+
/**
|
|
75
|
+
* The endpoint name in the URL that agents connect to: lowercase letters, digits and single hyphens, up to 64
|
|
76
|
+
* characters. The names `by-name` and `mcp` followed by 8 letters or digits are reserved. With the default deletion
|
|
77
|
+
* policy (`allow`), a change deletes the endpoint and creates a new endpoint with a new URL.
|
|
78
|
+
*/
|
|
79
|
+
name: string
|
|
80
|
+
/** The endpoint title, up to 100 characters. */
|
|
81
|
+
title: string
|
|
82
|
+
/** What the endpoint serves: any number of knowledge bases and at most one dataset. */
|
|
83
|
+
sources: ContextMcpEndpointSource[]
|
|
84
|
+
/** Instructions for agents that connect to the endpoint, up to 10,000 characters. */
|
|
85
|
+
instructions?: string
|
|
86
|
+
/** A GROQ filter for the documents that the dataset source serves. It requires a dataset source. */
|
|
87
|
+
groqFilter?: string
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Configuration for a Context MCP endpoint.
|
|
92
|
+
* @beta This feature is subject to breaking changes.
|
|
93
|
+
* @category Resource Types
|
|
94
|
+
* @interface
|
|
95
|
+
*/
|
|
96
|
+
export type BlueprintContextMcpEndpointConfig = Omit<BlueprintContextMcpEndpointResource, 'type' | 'sources'> & {
|
|
97
|
+
/**
|
|
98
|
+
* What the endpoint serves: any number of knowledge bases and at most one dataset. A knowledge base source can also
|
|
99
|
+
* be the resource that {@link defineContextKnowledgeBase} returns.
|
|
100
|
+
*/
|
|
101
|
+
sources: Array<ContextMcpEndpointSource | BlueprintContextKnowledgeBaseResource>
|
|
102
|
+
}
|
|
@@ -205,11 +205,10 @@ export interface BlueprintPubSubFunctionResource extends BlueprintBaseFunctionRe
|
|
|
205
205
|
|
|
206
206
|
/**
|
|
207
207
|
* A durable, step-based function.
|
|
208
|
-
* @
|
|
209
|
-
* @hidden
|
|
208
|
+
* @beta Deploying Durable Functions via Blueprints is experimental.
|
|
210
209
|
* @category Functions Types
|
|
211
210
|
*/
|
|
212
|
-
export interface BlueprintDurableFunctionResource extends BlueprintBaseFunctionResource
|
|
211
|
+
export interface BlueprintDurableFunctionResource extends BlueprintBaseFunctionResource {
|
|
213
212
|
type: 'sanity.function.durable'
|
|
214
213
|
event?: BlueprintFunctionResourceContentLakeEvent
|
|
215
214
|
/**
|
|
@@ -338,12 +337,11 @@ export type BlueprintPubSubFunctionConfig = Omit<BlueprintPubSubFunctionResource
|
|
|
338
337
|
/**
|
|
339
338
|
* Configuration for defining a durable function.
|
|
340
339
|
* @public
|
|
341
|
-
* @
|
|
342
|
-
* @hidden
|
|
340
|
+
* @beta Deploying Durable Functions via Blueprints is experimental.
|
|
343
341
|
* @category Functions Types
|
|
344
342
|
* @interface
|
|
345
343
|
*/
|
|
346
|
-
export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout'
|
|
344
|
+
export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout'> & {
|
|
347
345
|
/**
|
|
348
346
|
* Path to the function source code
|
|
349
347
|
* @defaultValue `functions/${name}`
|
|
@@ -358,8 +356,4 @@ export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'typ
|
|
|
358
356
|
* @defaultValue 86_400 (24 hours)
|
|
359
357
|
*/
|
|
360
358
|
durableTimeout?: string | number
|
|
361
|
-
/**
|
|
362
|
-
* Optional debounce configuration, as a duration or a full config
|
|
363
|
-
*/
|
|
364
|
-
debounce?: DebounceInput
|
|
365
359
|
}
|
package/src/types/studios.ts
CHANGED
|
@@ -27,6 +27,23 @@ export const APPLICATION_VISIBILITIES = ['default', 'unlisted', 'disabled'] as c
|
|
|
27
27
|
*/
|
|
28
28
|
export type ApplicationVisibility = (typeof APPLICATION_VISIBILITIES)[number]
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* A workspace definition extracted from a studio's configuration during the build.
|
|
32
|
+
* @beta This feature is subject to breaking changes.
|
|
33
|
+
* @category Resource Types
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
export type StudioWorkspace = {
|
|
37
|
+
projectId: string
|
|
38
|
+
dataset: string
|
|
39
|
+
schemaDescriptorId: string
|
|
40
|
+
name: string
|
|
41
|
+
title: string | undefined
|
|
42
|
+
subtitle: string | undefined
|
|
43
|
+
basePath: string | undefined
|
|
44
|
+
icon: string | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
/**
|
|
31
48
|
* Represents a Studio resource.
|
|
32
49
|
* @see https://www.sanity.io/docs/studio
|
|
@@ -91,6 +108,9 @@ export interface BlueprintStudioResource extends BlueprintResource<BlueprintProj
|
|
|
91
108
|
/** Schema inputs extracted from the studio's schema definition. */
|
|
92
109
|
schemaInputs?: WorkspaceSchemaInput[]
|
|
93
110
|
|
|
111
|
+
/** Workspaces extracted from the studio's configuration. */
|
|
112
|
+
workspaces?: StudioWorkspace[]
|
|
113
|
+
|
|
94
114
|
/** Module federation manifest */
|
|
95
115
|
mfManifest?: Record<string, unknown>
|
|
96
116
|
}
|
package/src/utils/validation.ts
CHANGED
|
@@ -47,3 +47,24 @@ const REFERENCE_PREFIXES = ['$.resources.', '$.values.', '$.parameters.', '$.par
|
|
|
47
47
|
export function isReference(value: unknown): boolean {
|
|
48
48
|
return typeof value === 'string' && REFERENCE_PREFIXES.some((prefix) => value.startsWith(prefix))
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Validates a string field on an object, optionally requiring it to be present and non-empty.
|
|
53
|
+
* @param obj The object containing the field
|
|
54
|
+
* @param field The field name
|
|
55
|
+
* @param label The label used as the prefix of error messages
|
|
56
|
+
* @param options Whether the field is required
|
|
57
|
+
* @returns A list of validation errors
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export function validateStringField(obj: object, field: string, label: string, options: {required: boolean}): BlueprintError[] {
|
|
61
|
+
const value: unknown = Reflect.get(obj, field)
|
|
62
|
+
|
|
63
|
+
if (typeof value === 'undefined' || (options.required && !value)) {
|
|
64
|
+
return options.required ? [{type: 'missing_parameter', message: `${label}.${field} is required`}] : []
|
|
65
|
+
}
|
|
66
|
+
if (typeof value !== 'string') {
|
|
67
|
+
return [{type: 'invalid_type', message: `${label}.${field} must be a string`}]
|
|
68
|
+
}
|
|
69
|
+
return []
|
|
70
|
+
}
|