@sanity/blueprints 0.30.0 → 0.31.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 +90 -0
- package/dist/definers/context.js +110 -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 +102 -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/validation/context.d.ts +19 -0
- package/dist/validation/context.js +136 -0
- package/dist/validation/context.js.map +1 -0
- package/package.json +1 -1
- package/src/definers/context.ts +124 -0
- package/src/definers/functions/durable.ts +5 -9
- package/src/index.ts +3 -0
- package/src/types/context.ts +109 -0
- package/src/types/functions/index.ts +4 -10
- package/src/validation/context.ts +142 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type BlueprintContextKnowledgeBaseConfig, type BlueprintContextKnowledgeBaseResource, type BlueprintContextMcpEndpointConfig, type BlueprintContextMcpEndpointResource } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a Context knowledge base.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The blueprint must be scoped to an organization. A new knowledge base has no sources. Add sources in the Context API
|
|
7
|
+
* or the dashboard.
|
|
8
|
+
*
|
|
9
|
+
* The default deletion policy is `retain`. If the stack is destroyed, the knowledge base is detached and not deleted. If
|
|
10
|
+
* the resource is removed from the blueprint, the deploy fails. To remove the resource, first deploy it with one of these
|
|
11
|
+
* `lifecycle` values:
|
|
12
|
+
* - `{ownershipAction: {type: 'detach'}}` keeps the knowledge base.
|
|
13
|
+
* - `{deletionPolicy: 'allow'}` deletes the knowledge base.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* defineContextKnowledgeBase({
|
|
18
|
+
* name: 'product-docs',
|
|
19
|
+
* title: 'Product docs',
|
|
20
|
+
* description: 'Everything about the product',
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example Detach before removal
|
|
25
|
+
* ```ts
|
|
26
|
+
* defineContextKnowledgeBase({
|
|
27
|
+
* name: 'product-docs',
|
|
28
|
+
* title: 'Product docs',
|
|
29
|
+
* description: 'Everything about the product',
|
|
30
|
+
* lifecycle: {ownershipAction: {type: 'detach'}},
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
* @param parameters The knowledge base configuration
|
|
34
|
+
* @public
|
|
35
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
36
|
+
* @hidden
|
|
37
|
+
* @category Definers
|
|
38
|
+
* @expandType BlueprintContextKnowledgeBaseConfig
|
|
39
|
+
* @returns The knowledge base resource
|
|
40
|
+
*/
|
|
41
|
+
export declare function defineContextKnowledgeBase(parameters: BlueprintContextKnowledgeBaseConfig): BlueprintContextKnowledgeBaseResource;
|
|
42
|
+
/**
|
|
43
|
+
* Defines a Context MCP endpoint that agents connect to.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The blueprint must be scoped to an organization.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* defineContextMcpEndpoint({
|
|
51
|
+
* name: 'support-agent',
|
|
52
|
+
* title: 'Support agent',
|
|
53
|
+
* sources: [{type: 'dataset', id: 'abc123.production'}],
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example Knowledge base and dataset sources
|
|
58
|
+
* ```ts
|
|
59
|
+
* const productDocs = defineContextKnowledgeBase({
|
|
60
|
+
* name: 'product-docs',
|
|
61
|
+
* title: 'Product docs',
|
|
62
|
+
* description: 'Everything about the product',
|
|
63
|
+
* })
|
|
64
|
+
*
|
|
65
|
+
* defineContextMcpEndpoint({
|
|
66
|
+
* name: 'support-agent',
|
|
67
|
+
* title: 'Support agent',
|
|
68
|
+
* sources: [productDocs, {type: 'dataset', id: 'abc123.production'}],
|
|
69
|
+
* instructions: 'Answer questions about the product.',
|
|
70
|
+
* groqFilter: '_type in ["article", "faq"]',
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example Dataset settings
|
|
75
|
+
* ```ts
|
|
76
|
+
* defineContextMcpEndpoint({
|
|
77
|
+
* name: 'editor-agent',
|
|
78
|
+
* title: 'Editor agent',
|
|
79
|
+
* sources: [{type: 'dataset', id: 'abc123.production', workspace: 'marketing', perspective: 'drafts', semanticSearch: false}],
|
|
80
|
+
* })
|
|
81
|
+
* ```
|
|
82
|
+
* @param parameters The MCP endpoint configuration
|
|
83
|
+
* @public
|
|
84
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
85
|
+
* @hidden
|
|
86
|
+
* @category Definers
|
|
87
|
+
* @expandType BlueprintContextMcpEndpointConfig
|
|
88
|
+
* @returns The MCP endpoint resource
|
|
89
|
+
*/
|
|
90
|
+
export declare function defineContextMcpEndpoint(parameters: BlueprintContextMcpEndpointConfig): BlueprintContextMcpEndpointResource;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { validateContextKnowledgeBase, validateContextMcpEndpoint, } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Defines a Context knowledge base.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The blueprint must be scoped to an organization. A new knowledge base has no sources. Add sources in the Context API
|
|
8
|
+
* or the dashboard.
|
|
9
|
+
*
|
|
10
|
+
* The default deletion policy is `retain`. If the stack is destroyed, the knowledge base is detached and not deleted. If
|
|
11
|
+
* the resource is removed from the blueprint, the deploy fails. To remove the resource, first deploy it with one of these
|
|
12
|
+
* `lifecycle` values:
|
|
13
|
+
* - `{ownershipAction: {type: 'detach'}}` keeps the knowledge base.
|
|
14
|
+
* - `{deletionPolicy: 'allow'}` deletes the knowledge base.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* defineContextKnowledgeBase({
|
|
19
|
+
* name: 'product-docs',
|
|
20
|
+
* title: 'Product docs',
|
|
21
|
+
* description: 'Everything about the product',
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Detach before removal
|
|
26
|
+
* ```ts
|
|
27
|
+
* defineContextKnowledgeBase({
|
|
28
|
+
* name: 'product-docs',
|
|
29
|
+
* title: 'Product docs',
|
|
30
|
+
* description: 'Everything about the product',
|
|
31
|
+
* lifecycle: {ownershipAction: {type: 'detach'}},
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
* @param parameters The knowledge base configuration
|
|
35
|
+
* @public
|
|
36
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
37
|
+
* @hidden
|
|
38
|
+
* @category Definers
|
|
39
|
+
* @expandType BlueprintContextKnowledgeBaseConfig
|
|
40
|
+
* @returns The knowledge base resource
|
|
41
|
+
*/
|
|
42
|
+
export function defineContextKnowledgeBase(parameters) {
|
|
43
|
+
const knowledgeBaseResource = {
|
|
44
|
+
...parameters,
|
|
45
|
+
type: 'sanity.context.knowledge-base',
|
|
46
|
+
};
|
|
47
|
+
runValidation(() => validateContextKnowledgeBase(knowledgeBaseResource));
|
|
48
|
+
return knowledgeBaseResource;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Defines a Context MCP endpoint that agents connect to.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* The blueprint must be scoped to an organization.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* defineContextMcpEndpoint({
|
|
59
|
+
* name: 'support-agent',
|
|
60
|
+
* title: 'Support agent',
|
|
61
|
+
* sources: [{type: 'dataset', id: 'abc123.production'}],
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example Knowledge base and dataset sources
|
|
66
|
+
* ```ts
|
|
67
|
+
* const productDocs = defineContextKnowledgeBase({
|
|
68
|
+
* name: 'product-docs',
|
|
69
|
+
* title: 'Product docs',
|
|
70
|
+
* description: 'Everything about the product',
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* defineContextMcpEndpoint({
|
|
74
|
+
* name: 'support-agent',
|
|
75
|
+
* title: 'Support agent',
|
|
76
|
+
* sources: [productDocs, {type: 'dataset', id: 'abc123.production'}],
|
|
77
|
+
* instructions: 'Answer questions about the product.',
|
|
78
|
+
* groqFilter: '_type in ["article", "faq"]',
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example Dataset settings
|
|
83
|
+
* ```ts
|
|
84
|
+
* defineContextMcpEndpoint({
|
|
85
|
+
* name: 'editor-agent',
|
|
86
|
+
* title: 'Editor agent',
|
|
87
|
+
* sources: [{type: 'dataset', id: 'abc123.production', workspace: 'marketing', perspective: 'drafts', semanticSearch: false}],
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
* @param parameters The MCP endpoint configuration
|
|
91
|
+
* @public
|
|
92
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
93
|
+
* @hidden
|
|
94
|
+
* @category Definers
|
|
95
|
+
* @expandType BlueprintContextMcpEndpointConfig
|
|
96
|
+
* @returns The MCP endpoint resource
|
|
97
|
+
*/
|
|
98
|
+
export function defineContextMcpEndpoint(parameters) {
|
|
99
|
+
const mcpEndpointResource = {
|
|
100
|
+
...parameters,
|
|
101
|
+
type: 'sanity.context.mcp',
|
|
102
|
+
// Malformed sources pass through untouched, so validation reports them instead of throwing here.
|
|
103
|
+
sources: Array.isArray(parameters.sources)
|
|
104
|
+
? parameters.sources.map((source) => source?.type === 'sanity.context.knowledge-base' ? { type: 'knowledge-base', id: `$.resources.${source.name}` } : source)
|
|
105
|
+
: parameters.sources,
|
|
106
|
+
};
|
|
107
|
+
runValidation(() => validateContextMcpEndpoint(mcpEndpointResource));
|
|
108
|
+
return mcpEndpointResource;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/definers/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAA+C;IACxF,MAAM,qBAAqB,GAA0C;QACnE,GAAG,UAAU;QACb,IAAI,EAAE,+BAA+B;KACtC,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,4BAA4B,CAAC,qBAAqB,CAAC,CAAC,CAAA;IAExE,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAA6C;IACpF,MAAM,mBAAmB,GAAwC;QAC/D,GAAG,UAAU;QACb,IAAI,EAAE,oBAAoB;QAC1B,iGAAiG;QACjG,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YACxC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAChC,MAAM,EAAE,IAAI,KAAK,+BAA+B,CAAC,CAAC,CAAC,EAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,eAAe,MAAM,CAAC,IAAI,EAAE,EAAC,CAAC,CAAC,CAAC,MAAM,CACvH;YACH,CAAC,CAAC,UAAU,CAAC,OAAO;KACvB,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,CAAC,CAAA;IAEpE,OAAO,mBAAmB,CAAA;AAC5B,CAAC"}
|
|
@@ -8,17 +8,13 @@ import { type BlueprintDurableConfig, type BlueprintDurableFunctionResource } fr
|
|
|
8
8
|
* defineDurableFunction({
|
|
9
9
|
* name: 'daily-cleanup',
|
|
10
10
|
* event: {type: 'document', on: ['create'], filter: "_type == 'post'"},
|
|
11
|
-
* concurrency: 5,
|
|
12
|
-
* debounce: 10,
|
|
13
11
|
* })
|
|
14
12
|
* ```
|
|
15
13
|
*
|
|
16
|
-
*
|
|
17
14
|
* @param functionConfig The configuration for the function
|
|
18
15
|
* @category Definers
|
|
19
|
-
* @
|
|
16
|
+
* @beta Deploying Durable Functions via Blueprints is experimental.
|
|
20
17
|
* @public
|
|
21
|
-
* @hidden
|
|
22
18
|
* @expandType BlueprintDurableConfig
|
|
23
19
|
* @returns The validated durable function resource
|
|
24
20
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { 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';
|
|
@@ -12,29 +11,26 @@ import { defineFunction } from './index.js';
|
|
|
12
11
|
* defineDurableFunction({
|
|
13
12
|
* name: 'daily-cleanup',
|
|
14
13
|
* event: {type: 'document', on: ['create'], filter: "_type == 'post'"},
|
|
15
|
-
* concurrency: 5,
|
|
16
|
-
* debounce: 10,
|
|
17
14
|
* })
|
|
18
15
|
* ```
|
|
19
16
|
*
|
|
20
|
-
*
|
|
21
17
|
* @param functionConfig The configuration for the function
|
|
22
18
|
* @category Definers
|
|
23
|
-
* @
|
|
19
|
+
* @beta Deploying Durable Functions via Blueprints is experimental.
|
|
24
20
|
* @public
|
|
25
|
-
* @hidden
|
|
26
21
|
* @expandType BlueprintDurableConfig
|
|
27
22
|
* @returns The validated durable function resource
|
|
28
23
|
*/
|
|
29
24
|
export function defineDurableFunction(functionConfig) {
|
|
30
|
-
const { name, event,
|
|
25
|
+
const { name, event, src, durableTimeout } = functionConfig;
|
|
31
26
|
const functionResource = {
|
|
32
27
|
...defineFunction({ ...functionConfig, src: src ?? `functions/${name}` }, { skipValidation: true }),
|
|
33
28
|
type: 'sanity.function.durable',
|
|
34
29
|
...(event !== undefined && { event }),
|
|
35
30
|
...(durableTimeout !== undefined && { durableTimeout: parseDuration(durableTimeout, 's') }),
|
|
36
|
-
|
|
37
|
-
...(
|
|
31
|
+
// TODO: eventually support queue fields once backend supports it
|
|
32
|
+
// ...(concurrency !== undefined && {concurrency}),
|
|
33
|
+
// ...(debounce !== undefined && {debounce: createDebounceObject(debounce)}),
|
|
38
34
|
};
|
|
39
35
|
runValidation(() => validateDurableFunction(functionResource));
|
|
40
36
|
return functionResource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable.js","sourceRoot":"","sources":["../../../src/definers/functions/durable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,uBAAuB,EAAC,MAAM,gBAAgB,CAAA;AAC1H,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"durable.js","sourceRoot":"","sources":["../../../src/definers/functions/durable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,uBAAuB,EAAC,MAAM,gBAAgB,CAAA;AAC1H,OAAO,EAAC,aAAa,EAAC,MAAM,+BAA+B,CAAA;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAEzC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CAAC,cAAsC;IAC1E,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAC,GAAG,cAAc,CAAA;IACzD,MAAM,gBAAgB,GAAqC;QACzD,GAAG,cAAc,CAAC,EAAC,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,aAAa,IAAI,EAAE,EAAC,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;QAC/F,IAAI,EAAE,yBAAyB;QAC/B,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAC,KAAK,EAAC,CAAC;QACnC,GAAG,CAAC,cAAc,KAAK,SAAS,IAAI,EAAC,cAAc,EAAE,aAAa,CAAC,cAAc,EAAE,GAAG,CAAC,EAAC,CAAC;QACzF,iEAAiE;QACjE,mDAAmD;QACnD,6EAA6E;KAC9E,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAC9D,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export * from './definers/applications.js';
|
|
10
10
|
export * from './definers/blueprints.js';
|
|
11
|
+
export * from './definers/context.js';
|
|
11
12
|
export * from './definers/cors.js';
|
|
12
13
|
export * from './definers/datasets.js';
|
|
13
14
|
export * from './definers/functions/document.js';
|
|
@@ -37,6 +38,7 @@ export * from './definers/webhooks.js';
|
|
|
37
38
|
*/
|
|
38
39
|
export * from './types/applications.js';
|
|
39
40
|
export * from './types/blueprints.js';
|
|
41
|
+
export * from './types/context.js';
|
|
40
42
|
export * from './types/cors.js';
|
|
41
43
|
export * from './types/datasets.js';
|
|
42
44
|
export * from './types/errors.js';
|
|
@@ -56,6 +58,7 @@ export * from './types/webhooks.js';
|
|
|
56
58
|
*/
|
|
57
59
|
export * from './validation/applications.js';
|
|
58
60
|
export * from './validation/blueprints.js';
|
|
61
|
+
export * from './validation/context.js';
|
|
59
62
|
export * from './validation/cors.js';
|
|
60
63
|
export * from './validation/datasets.js';
|
|
61
64
|
export * from './validation/functions.js';
|
package/dist/index.js
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';
|
|
@@ -39,6 +40,7 @@ export * from './definers/webhooks.js';
|
|
|
39
40
|
*/
|
|
40
41
|
export * from './types/applications.js';
|
|
41
42
|
export * from './types/blueprints.js';
|
|
43
|
+
export * from './types/context.js';
|
|
42
44
|
export * from './types/cors.js';
|
|
43
45
|
export * from './types/datasets.js';
|
|
44
46
|
export * from './types/errors.js';
|
|
@@ -59,6 +61,7 @@ export * from './types/webhooks.js';
|
|
|
59
61
|
*/
|
|
60
62
|
export * from './validation/applications.js';
|
|
61
63
|
export * from './validation/blueprints.js';
|
|
64
|
+
export * from './validation/context.js';
|
|
62
65
|
export * from './validation/cors.js';
|
|
63
66
|
export * from './validation/datasets.js';
|
|
64
67
|
export * from './validation/functions.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD;;;GAGG;AACH;;;GAGG;AACH,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kCAAkC,CAAA;AAChD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uCAAuC,CAAA;AACrD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,mCAAmC,CAAA;AACjD,cAAc,6CAA6C,CAAA;AAC3D,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,CAAA;AACzC,cAAc,qCAAqC,CAAA;AACnD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AAExC,yEAAyE;AACzE;;;GAGG"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { BlueprintResource } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A knowledge base that a Context MCP endpoint serves.
|
|
4
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
5
|
+
* @hidden
|
|
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
|
+
* A Sanity dataset that a Context MCP endpoint serves.
|
|
15
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
16
|
+
* @hidden
|
|
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
|
+
* Content that a Context MCP endpoint serves.
|
|
35
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
36
|
+
* @hidden
|
|
37
|
+
* @category Resource Types
|
|
38
|
+
*/
|
|
39
|
+
export type ContextMcpEndpointSource = ContextKnowledgeBaseSource | ContextDatasetSource;
|
|
40
|
+
/**
|
|
41
|
+
* A Context knowledge base resource.
|
|
42
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
43
|
+
* @hidden
|
|
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
|
+
* Configuration for a Context knowledge base.
|
|
60
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
61
|
+
* @hidden
|
|
62
|
+
* @category Resource Types
|
|
63
|
+
* @interface
|
|
64
|
+
*/
|
|
65
|
+
export type BlueprintContextKnowledgeBaseConfig = Omit<BlueprintContextKnowledgeBaseResource, 'type'>;
|
|
66
|
+
/**
|
|
67
|
+
* A Context MCP endpoint resource.
|
|
68
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
69
|
+
* @hidden
|
|
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
|
+
* Configuration for a Context MCP endpoint.
|
|
91
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
92
|
+
* @hidden
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/types/context.ts"],"names":[],"mappings":""}
|
|
@@ -180,11 +180,10 @@ export interface BlueprintPubSubFunctionResource extends BlueprintBaseFunctionRe
|
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* A durable, step-based function.
|
|
183
|
-
* @
|
|
184
|
-
* @hidden
|
|
183
|
+
* @beta Deploying Durable Functions via Blueprints is experimental.
|
|
185
184
|
* @category Functions Types
|
|
186
185
|
*/
|
|
187
|
-
export interface BlueprintDurableFunctionResource extends BlueprintBaseFunctionResource
|
|
186
|
+
export interface BlueprintDurableFunctionResource extends BlueprintBaseFunctionResource {
|
|
188
187
|
type: 'sanity.function.durable';
|
|
189
188
|
event?: BlueprintFunctionResourceContentLakeEvent;
|
|
190
189
|
/**
|
|
@@ -301,12 +300,11 @@ export type BlueprintPubSubFunctionConfig = Omit<BlueprintPubSubFunctionResource
|
|
|
301
300
|
/**
|
|
302
301
|
* Configuration for defining a durable function.
|
|
303
302
|
* @public
|
|
304
|
-
* @
|
|
305
|
-
* @hidden
|
|
303
|
+
* @beta Deploying Durable Functions via Blueprints is experimental.
|
|
306
304
|
* @category Functions Types
|
|
307
305
|
* @interface
|
|
308
306
|
*/
|
|
309
|
-
export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout'
|
|
307
|
+
export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout'> & {
|
|
310
308
|
/**
|
|
311
309
|
* Path to the function source code
|
|
312
310
|
* @defaultValue `functions/${name}`
|
|
@@ -321,8 +319,4 @@ export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'typ
|
|
|
321
319
|
* @defaultValue 86_400 (24 hours)
|
|
322
320
|
*/
|
|
323
321
|
durableTimeout?: string | number;
|
|
324
|
-
/**
|
|
325
|
-
* Optional debounce configuration, as a duration or a full config
|
|
326
|
-
*/
|
|
327
|
-
debounce?: DebounceInput;
|
|
328
322
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type BlueprintError } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that the given resource is a valid Context knowledge base.
|
|
4
|
+
* @param resource The Context knowledge base resource
|
|
5
|
+
* @alpha
|
|
6
|
+
* @hidden
|
|
7
|
+
* @category Validation
|
|
8
|
+
* @returns A list of validation errors
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateContextKnowledgeBase(resource: unknown): BlueprintError[];
|
|
11
|
+
/**
|
|
12
|
+
* Validates that the given resource is a valid Context MCP endpoint.
|
|
13
|
+
* @param resource The Context MCP endpoint resource
|
|
14
|
+
* @alpha
|
|
15
|
+
* @hidden
|
|
16
|
+
* @category Validation
|
|
17
|
+
* @returns A list of validation errors
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateContextMcpEndpoint(resource: unknown): BlueprintError[];
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
* @alpha
|
|
41
|
+
* @hidden
|
|
42
|
+
* @category Validation
|
|
43
|
+
* @returns A list of validation errors
|
|
44
|
+
*/
|
|
45
|
+
export function validateContextKnowledgeBase(resource) {
|
|
46
|
+
if (!resource)
|
|
47
|
+
return [{ type: 'invalid_value', message: 'Knowledge base config must be provided' }];
|
|
48
|
+
if (typeof resource !== 'object')
|
|
49
|
+
return [{ type: 'invalid_type', message: 'Knowledge base config must be an object' }];
|
|
50
|
+
const errors = validateResource(resource);
|
|
51
|
+
if ('type' in resource && resource.type !== 'sanity.context.knowledge-base') {
|
|
52
|
+
errors.push({ type: 'invalid_value', message: 'Knowledge base type must be `sanity.context.knowledge-base`' });
|
|
53
|
+
}
|
|
54
|
+
errors.push(...validateText(resource, 'title', 'Knowledge base title', { required: true, max: 100 }));
|
|
55
|
+
errors.push(...validateText(resource, 'description', 'Knowledge base description', { required: true, max: 2000 }));
|
|
56
|
+
return errors;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validates that the given resource is a valid Context MCP endpoint.
|
|
60
|
+
* @param resource The Context MCP endpoint resource
|
|
61
|
+
* @alpha
|
|
62
|
+
* @hidden
|
|
63
|
+
* @category Validation
|
|
64
|
+
* @returns A list of validation errors
|
|
65
|
+
*/
|
|
66
|
+
export function validateContextMcpEndpoint(resource) {
|
|
67
|
+
if (!resource)
|
|
68
|
+
return [{ type: 'invalid_value', message: 'MCP endpoint config must be provided' }];
|
|
69
|
+
if (typeof resource !== 'object')
|
|
70
|
+
return [{ type: 'invalid_type', message: 'MCP endpoint config must be an object' }];
|
|
71
|
+
const errors = validateResource(resource);
|
|
72
|
+
if ('type' in resource && resource.type !== 'sanity.context.mcp') {
|
|
73
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint type must be `sanity.context.mcp`' });
|
|
74
|
+
}
|
|
75
|
+
if ('name' in resource && typeof resource.name === 'string') {
|
|
76
|
+
if (resource.name.length > 64 || !MCP_ENDPOINT_NAME_PATTERN.test(resource.name)) {
|
|
77
|
+
errors.push({
|
|
78
|
+
type: 'invalid_format',
|
|
79
|
+
message: 'MCP endpoint name must be lowercase letters, digits and single hyphens, up to 64 characters',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else if (resource.name === 'by-name' || MCP_ENDPOINT_ID_PATTERN.test(resource.name)) {
|
|
83
|
+
errors.push({ type: 'invalid_value', message: `MCP endpoint name "${resource.name}" is reserved` });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
errors.push(...validateText(resource, 'title', 'MCP endpoint title', { required: true, max: 100 }));
|
|
87
|
+
errors.push(...validateText(resource, 'instructions', 'MCP endpoint instructions', { required: false, max: 10_000 }));
|
|
88
|
+
errors.push(...validateText(resource, 'groqFilter', 'MCP endpoint GROQ filter', { required: false, max: 10_000 }));
|
|
89
|
+
if (!('sources' in resource)) {
|
|
90
|
+
errors.push({ type: 'missing_parameter', message: 'MCP endpoint sources are required' });
|
|
91
|
+
return errors;
|
|
92
|
+
}
|
|
93
|
+
if (!Array.isArray(resource.sources) || resource.sources.length === 0) {
|
|
94
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint must have at least one source' });
|
|
95
|
+
return errors;
|
|
96
|
+
}
|
|
97
|
+
if (resource.sources.length > 100) {
|
|
98
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint can have at most 100 sources' });
|
|
99
|
+
}
|
|
100
|
+
let datasets = 0;
|
|
101
|
+
for (const source of resource.sources) {
|
|
102
|
+
if (!source || typeof source !== 'object' || !('type' in source) || !('id' in source)) {
|
|
103
|
+
errors.push({ type: 'invalid_value', message: 'Each MCP endpoint source needs a `type` and an `id`' });
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (typeof source.id !== 'string' || source.id.length === 0) {
|
|
107
|
+
errors.push({ type: 'invalid_type', message: 'MCP endpoint source `id` must be a non-empty string' });
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (source.type === 'dataset') {
|
|
111
|
+
datasets++;
|
|
112
|
+
// The provider checks the format before references resolve, and no resource exposes `<projectId>.<datasetName>`
|
|
113
|
+
if (source.id.startsWith('$.resources.')) {
|
|
114
|
+
errors.push({
|
|
115
|
+
type: 'invalid_value',
|
|
116
|
+
message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>", not a resource reference`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else if (!isReference(source.id) && !DATASET_SOURCE_PATTERN.test(source.id)) {
|
|
120
|
+
errors.push({ type: 'invalid_format', message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>"` });
|
|
121
|
+
}
|
|
122
|
+
errors.push(...validateDatasetSettings(source));
|
|
123
|
+
}
|
|
124
|
+
else if (source.type !== 'knowledge-base') {
|
|
125
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint source `type` must be `knowledge-base` or `dataset`' });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (datasets > 1) {
|
|
129
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint can have at most one dataset source' });
|
|
130
|
+
}
|
|
131
|
+
if (datasets === 0 && 'groqFilter' in resource) {
|
|
132
|
+
errors.push({ type: 'invalid_value', message: 'MCP endpoint GROQ filter requires a dataset source' });
|
|
133
|
+
}
|
|
134
|
+
return errors;
|
|
135
|
+
}
|
|
136
|
+
//# 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,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,GAAG,KAAK,cAAc,EAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/F,CAAC;IACD,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,KAAK,mBAAmB,EAAC,CAAC,CAAA;IACpG,IAAI,KAAK,CAAC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AC/C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,oDAAoD,EAAC,CAAC,CAAA;IACrG,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
45
|
+
* @hidden
|
|
46
|
+
* @category Definers
|
|
47
|
+
* @expandType BlueprintContextKnowledgeBaseConfig
|
|
48
|
+
* @returns The knowledge base resource
|
|
49
|
+
*/
|
|
50
|
+
export function defineContextKnowledgeBase(parameters: BlueprintContextKnowledgeBaseConfig): BlueprintContextKnowledgeBaseResource {
|
|
51
|
+
const knowledgeBaseResource: BlueprintContextKnowledgeBaseResource = {
|
|
52
|
+
...parameters,
|
|
53
|
+
type: 'sanity.context.knowledge-base',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
runValidation(() => validateContextKnowledgeBase(knowledgeBaseResource))
|
|
57
|
+
|
|
58
|
+
return knowledgeBaseResource
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Defines a Context MCP endpoint that agents connect to.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* The blueprint must be scoped to an organization.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* defineContextMcpEndpoint({
|
|
70
|
+
* name: 'support-agent',
|
|
71
|
+
* title: 'Support agent',
|
|
72
|
+
* sources: [{type: 'dataset', id: 'abc123.production'}],
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example Knowledge base and dataset sources
|
|
77
|
+
* ```ts
|
|
78
|
+
* const productDocs = defineContextKnowledgeBase({
|
|
79
|
+
* name: 'product-docs',
|
|
80
|
+
* title: 'Product docs',
|
|
81
|
+
* description: 'Everything about the product',
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* defineContextMcpEndpoint({
|
|
85
|
+
* name: 'support-agent',
|
|
86
|
+
* title: 'Support agent',
|
|
87
|
+
* sources: [productDocs, {type: 'dataset', id: 'abc123.production'}],
|
|
88
|
+
* instructions: 'Answer questions about the product.',
|
|
89
|
+
* groqFilter: '_type in ["article", "faq"]',
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Dataset settings
|
|
94
|
+
* ```ts
|
|
95
|
+
* defineContextMcpEndpoint({
|
|
96
|
+
* name: 'editor-agent',
|
|
97
|
+
* title: 'Editor agent',
|
|
98
|
+
* sources: [{type: 'dataset', id: 'abc123.production', workspace: 'marketing', perspective: 'drafts', semanticSearch: false}],
|
|
99
|
+
* })
|
|
100
|
+
* ```
|
|
101
|
+
* @param parameters The MCP endpoint configuration
|
|
102
|
+
* @public
|
|
103
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
104
|
+
* @hidden
|
|
105
|
+
* @category Definers
|
|
106
|
+
* @expandType BlueprintContextMcpEndpointConfig
|
|
107
|
+
* @returns The MCP endpoint resource
|
|
108
|
+
*/
|
|
109
|
+
export function defineContextMcpEndpoint(parameters: BlueprintContextMcpEndpointConfig): BlueprintContextMcpEndpointResource {
|
|
110
|
+
const mcpEndpointResource: BlueprintContextMcpEndpointResource = {
|
|
111
|
+
...parameters,
|
|
112
|
+
type: 'sanity.context.mcp',
|
|
113
|
+
// Malformed sources pass through untouched, so validation reports them instead of throwing here.
|
|
114
|
+
sources: Array.isArray(parameters.sources)
|
|
115
|
+
? parameters.sources.map((source) =>
|
|
116
|
+
source?.type === 'sanity.context.knowledge-base' ? {type: 'knowledge-base', id: `$.resources.${source.name}`} : source,
|
|
117
|
+
)
|
|
118
|
+
: parameters.sources,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
runValidation(() => validateContextMcpEndpoint(mcpEndpointResource))
|
|
122
|
+
|
|
123
|
+
return mcpEndpointResource
|
|
124
|
+
}
|
|
@@ -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,109 @@
|
|
|
1
|
+
import type {BlueprintResource} from '../index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A knowledge base that a Context MCP endpoint serves.
|
|
5
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
6
|
+
* @hidden
|
|
7
|
+
* @category Resource Types
|
|
8
|
+
*/
|
|
9
|
+
export interface ContextKnowledgeBaseSource {
|
|
10
|
+
type: 'knowledge-base'
|
|
11
|
+
/** A knowledge base in the blueprint as `$.resources.<name>`, or the ID (`kb…`) of a knowledge base. */
|
|
12
|
+
id: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A Sanity dataset that a Context MCP endpoint serves.
|
|
17
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
18
|
+
* @hidden
|
|
19
|
+
* @category Resource Types
|
|
20
|
+
*/
|
|
21
|
+
export interface ContextDatasetSource {
|
|
22
|
+
type: 'dataset'
|
|
23
|
+
/** The dataset as `<projectId>.<datasetName>`, for example `abc123.production`. It can't be a `$.resources.<name>` reference. */
|
|
24
|
+
id: string
|
|
25
|
+
/** The studio workspace whose schema agents use, by name. `null` uses the studio's first workspace. */
|
|
26
|
+
workspace?: string | null
|
|
27
|
+
/** The perspective agents query the dataset with. `null` uses `published`. */
|
|
28
|
+
perspective?: 'published' | 'drafts' | 'raw' | null
|
|
29
|
+
/**
|
|
30
|
+
* Whether agents can use semantic search on the dataset. `false` turns it off. `true` or `null` use it while the
|
|
31
|
+
* dataset has embeddings enabled.
|
|
32
|
+
*/
|
|
33
|
+
semanticSearch?: boolean | null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Content that a Context MCP endpoint serves.
|
|
38
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
39
|
+
* @hidden
|
|
40
|
+
* @category Resource Types
|
|
41
|
+
*/
|
|
42
|
+
export type ContextMcpEndpointSource = ContextKnowledgeBaseSource | ContextDatasetSource
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A Context knowledge base resource.
|
|
46
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
47
|
+
* @hidden
|
|
48
|
+
* @category Resource Types
|
|
49
|
+
*/
|
|
50
|
+
export interface BlueprintContextKnowledgeBaseResource extends BlueprintResource {
|
|
51
|
+
type: 'sanity.context.knowledge-base'
|
|
52
|
+
/**
|
|
53
|
+
* The resource name in the blueprint. The knowledge base has no name, only a `title`. With the default deletion
|
|
54
|
+
* policy (`retain`), a deploy fails if this name changes.
|
|
55
|
+
*/
|
|
56
|
+
name: string
|
|
57
|
+
/** The knowledge base title, up to 100 characters. */
|
|
58
|
+
title: string
|
|
59
|
+
/** What the knowledge base covers, up to 2,000 characters. */
|
|
60
|
+
description: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Configuration for a Context knowledge base.
|
|
65
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
66
|
+
* @hidden
|
|
67
|
+
* @category Resource Types
|
|
68
|
+
* @interface
|
|
69
|
+
*/
|
|
70
|
+
export type BlueprintContextKnowledgeBaseConfig = Omit<BlueprintContextKnowledgeBaseResource, 'type'>
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A Context MCP endpoint resource.
|
|
74
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
75
|
+
* @hidden
|
|
76
|
+
* @category Resource Types
|
|
77
|
+
*/
|
|
78
|
+
export interface BlueprintContextMcpEndpointResource extends BlueprintResource {
|
|
79
|
+
type: 'sanity.context.mcp'
|
|
80
|
+
/**
|
|
81
|
+
* The endpoint name in the URL that agents connect to: lowercase letters, digits and single hyphens, up to 64
|
|
82
|
+
* characters. The names `by-name` and `mcp` followed by 8 letters or digits are reserved. With the default deletion
|
|
83
|
+
* policy (`allow`), a change deletes the endpoint and creates a new endpoint with a new URL.
|
|
84
|
+
*/
|
|
85
|
+
name: string
|
|
86
|
+
/** The endpoint title, up to 100 characters. */
|
|
87
|
+
title: string
|
|
88
|
+
/** What the endpoint serves: any number of knowledge bases and at most one dataset. */
|
|
89
|
+
sources: ContextMcpEndpointSource[]
|
|
90
|
+
/** Instructions for agents that connect to the endpoint, up to 10,000 characters. */
|
|
91
|
+
instructions?: string
|
|
92
|
+
/** A GROQ filter for the documents that the dataset source serves. It requires a dataset source. */
|
|
93
|
+
groqFilter?: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Configuration for a Context MCP endpoint.
|
|
98
|
+
* @alpha Deploying Context via Blueprints is experimental. This feature is not available publicly yet.
|
|
99
|
+
* @hidden
|
|
100
|
+
* @category Resource Types
|
|
101
|
+
* @interface
|
|
102
|
+
*/
|
|
103
|
+
export type BlueprintContextMcpEndpointConfig = Omit<BlueprintContextMcpEndpointResource, 'type' | 'sources'> & {
|
|
104
|
+
/**
|
|
105
|
+
* What the endpoint serves: any number of knowledge bases and at most one dataset. A knowledge base source can also
|
|
106
|
+
* be the resource that {@link defineContextKnowledgeBase} returns.
|
|
107
|
+
*/
|
|
108
|
+
sources: Array<ContextMcpEndpointSource | BlueprintContextKnowledgeBaseResource>
|
|
109
|
+
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {type BlueprintError, validateResource} from '../index.js'
|
|
2
|
+
import {isReference} from '../utils/validation.js'
|
|
3
|
+
|
|
4
|
+
const MCP_ENDPOINT_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
5
|
+
const MCP_ENDPOINT_ID_PATTERN = /^mcp[a-z0-9]{8}$/
|
|
6
|
+
const DATASET_SOURCE_PATTERN = /^[a-z0-9]+\.[a-z0-9][a-z0-9_-]*$/
|
|
7
|
+
const DATASET_PERSPECTIVES: unknown[] = ['published', 'drafts', 'raw']
|
|
8
|
+
|
|
9
|
+
function validateText(resource: object, field: string, label: string, options: {required: boolean; max: number}): BlueprintError[] {
|
|
10
|
+
if (!(field in resource)) {
|
|
11
|
+
return options.required ? [{type: 'missing_parameter', message: `${label} is required`}] : []
|
|
12
|
+
}
|
|
13
|
+
const value: unknown = Reflect.get(resource, field)
|
|
14
|
+
if (typeof value !== 'string') return [{type: 'invalid_type', message: `${label} must be a string`}]
|
|
15
|
+
if (value.length === 0) 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
|
+
|
|
22
|
+
function validateDatasetSettings(source: object): BlueprintError[] {
|
|
23
|
+
const errors: BlueprintError[] = []
|
|
24
|
+
const workspace: unknown = Reflect.get(source, 'workspace')
|
|
25
|
+
const perspective: unknown = Reflect.get(source, 'perspective')
|
|
26
|
+
const semanticSearch: unknown = Reflect.get(source, 'semanticSearch')
|
|
27
|
+
if (workspace != null && (typeof workspace !== 'string' || workspace.length === 0)) {
|
|
28
|
+
errors.push({type: 'invalid_type', message: 'Dataset source `workspace` must be a non-empty string or null'})
|
|
29
|
+
}
|
|
30
|
+
if (perspective != null && !DATASET_PERSPECTIVES.includes(perspective)) {
|
|
31
|
+
errors.push({type: 'invalid_value', message: 'Dataset source `perspective` must be `published`, `drafts`, `raw` or null'})
|
|
32
|
+
}
|
|
33
|
+
if (semanticSearch != null && typeof semanticSearch !== 'boolean') {
|
|
34
|
+
errors.push({type: 'invalid_type', message: 'Dataset source `semanticSearch` must be a boolean or null'})
|
|
35
|
+
}
|
|
36
|
+
return errors
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Validates that the given resource is a valid Context knowledge base.
|
|
41
|
+
* @param resource The Context knowledge base resource
|
|
42
|
+
* @alpha
|
|
43
|
+
* @hidden
|
|
44
|
+
* @category Validation
|
|
45
|
+
* @returns A list of validation errors
|
|
46
|
+
*/
|
|
47
|
+
export function validateContextKnowledgeBase(resource: unknown): BlueprintError[] {
|
|
48
|
+
if (!resource) return [{type: 'invalid_value', message: 'Knowledge base config must be provided'}]
|
|
49
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Knowledge base config must be an object'}]
|
|
50
|
+
|
|
51
|
+
const errors: BlueprintError[] = validateResource(resource)
|
|
52
|
+
|
|
53
|
+
if ('type' in resource && resource.type !== 'sanity.context.knowledge-base') {
|
|
54
|
+
errors.push({type: 'invalid_value', message: 'Knowledge base type must be `sanity.context.knowledge-base`'})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
errors.push(...validateText(resource, 'title', 'Knowledge base title', {required: true, max: 100}))
|
|
58
|
+
errors.push(...validateText(resource, 'description', 'Knowledge base description', {required: true, max: 2000}))
|
|
59
|
+
|
|
60
|
+
return errors
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Validates that the given resource is a valid Context MCP endpoint.
|
|
65
|
+
* @param resource The Context MCP endpoint resource
|
|
66
|
+
* @alpha
|
|
67
|
+
* @hidden
|
|
68
|
+
* @category Validation
|
|
69
|
+
* @returns A list of validation errors
|
|
70
|
+
*/
|
|
71
|
+
export function validateContextMcpEndpoint(resource: unknown): BlueprintError[] {
|
|
72
|
+
if (!resource) return [{type: 'invalid_value', message: 'MCP endpoint config must be provided'}]
|
|
73
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'MCP endpoint config must be an object'}]
|
|
74
|
+
|
|
75
|
+
const errors: BlueprintError[] = validateResource(resource)
|
|
76
|
+
|
|
77
|
+
if ('type' in resource && resource.type !== 'sanity.context.mcp') {
|
|
78
|
+
errors.push({type: 'invalid_value', message: 'MCP endpoint type must be `sanity.context.mcp`'})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if ('name' in resource && typeof resource.name === 'string') {
|
|
82
|
+
if (resource.name.length > 64 || !MCP_ENDPOINT_NAME_PATTERN.test(resource.name)) {
|
|
83
|
+
errors.push({
|
|
84
|
+
type: 'invalid_format',
|
|
85
|
+
message: 'MCP endpoint name must be lowercase letters, digits and single hyphens, up to 64 characters',
|
|
86
|
+
})
|
|
87
|
+
} else if (resource.name === 'by-name' || MCP_ENDPOINT_ID_PATTERN.test(resource.name)) {
|
|
88
|
+
errors.push({type: 'invalid_value', message: `MCP endpoint name "${resource.name}" is reserved`})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
errors.push(...validateText(resource, 'title', 'MCP endpoint title', {required: true, max: 100}))
|
|
93
|
+
errors.push(...validateText(resource, 'instructions', 'MCP endpoint instructions', {required: false, max: 10_000}))
|
|
94
|
+
errors.push(...validateText(resource, 'groqFilter', 'MCP endpoint GROQ filter', {required: false, max: 10_000}))
|
|
95
|
+
|
|
96
|
+
if (!('sources' in resource)) {
|
|
97
|
+
errors.push({type: 'missing_parameter', message: 'MCP endpoint sources are required'})
|
|
98
|
+
return errors
|
|
99
|
+
}
|
|
100
|
+
if (!Array.isArray(resource.sources) || resource.sources.length === 0) {
|
|
101
|
+
errors.push({type: 'invalid_value', message: 'MCP endpoint must have at least one source'})
|
|
102
|
+
return errors
|
|
103
|
+
}
|
|
104
|
+
if (resource.sources.length > 100) {
|
|
105
|
+
errors.push({type: 'invalid_value', message: 'MCP endpoint can have at most 100 sources'})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let datasets = 0
|
|
109
|
+
for (const source of resource.sources) {
|
|
110
|
+
if (!source || typeof source !== 'object' || !('type' in source) || !('id' in source)) {
|
|
111
|
+
errors.push({type: 'invalid_value', message: 'Each MCP endpoint source needs a `type` and an `id`'})
|
|
112
|
+
continue
|
|
113
|
+
}
|
|
114
|
+
if (typeof source.id !== 'string' || source.id.length === 0) {
|
|
115
|
+
errors.push({type: 'invalid_type', message: 'MCP endpoint source `id` must be a non-empty string'})
|
|
116
|
+
continue
|
|
117
|
+
}
|
|
118
|
+
if (source.type === 'dataset') {
|
|
119
|
+
datasets++
|
|
120
|
+
// The provider checks the format before references resolve, and no resource exposes `<projectId>.<datasetName>`
|
|
121
|
+
if (source.id.startsWith('$.resources.')) {
|
|
122
|
+
errors.push({
|
|
123
|
+
type: 'invalid_value',
|
|
124
|
+
message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>", not a resource reference`,
|
|
125
|
+
})
|
|
126
|
+
} else if (!isReference(source.id) && !DATASET_SOURCE_PATTERN.test(source.id)) {
|
|
127
|
+
errors.push({type: 'invalid_format', message: `Dataset source "${source.id}" must be "<projectId>.<datasetName>"`})
|
|
128
|
+
}
|
|
129
|
+
errors.push(...validateDatasetSettings(source))
|
|
130
|
+
} else if (source.type !== 'knowledge-base') {
|
|
131
|
+
errors.push({type: 'invalid_value', message: 'MCP endpoint source `type` must be `knowledge-base` or `dataset`'})
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (datasets > 1) {
|
|
135
|
+
errors.push({type: 'invalid_value', message: 'MCP endpoint can have at most one dataset source'})
|
|
136
|
+
}
|
|
137
|
+
if (datasets === 0 && 'groqFilter' in resource) {
|
|
138
|
+
errors.push({type: 'invalid_value', message: 'MCP endpoint GROQ filter requires a dataset source'})
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return errors
|
|
142
|
+
}
|