@payloadcms/plugin-mcp 4.0.0-internal.40de3ec → 4.0.0-internal.4804abd
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/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/endpoint/access.d.ts +17 -5
- package/dist/endpoint/access.d.ts.map +1 -1
- package/dist/endpoint/access.js +82 -88
- package/dist/endpoint/access.js.map +1 -1
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +11 -0
- package/dist/endpoint/index.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -18
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +102 -71
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +44 -6
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +69 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +65 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +38 -42
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +14 -20
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +97 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +93 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +49 -43
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +84 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +99 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +47 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +82 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +87 -86
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +71 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +65 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +18 -21
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +80 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +95 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +47 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +78 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +31 -40
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
- package/dist/mcp/builtin/validateEntityData.js +82 -0
- package/dist/mcp/builtin/validateEntityData.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +144 -19
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +119 -20
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +120 -58
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts +3 -2
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +27 -8
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +62 -108
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/getPluginConfig.d.ts +1 -1
- package/dist/utils/getPluginConfig.js +1 -1
- package/dist/utils/getPluginConfig.js.map +1 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +11 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +32 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
- package/dist/utils/whereSchema.d.ts +9 -0
- package/dist/utils/whereSchema.d.ts.map +1 -0
- package/dist/utils/whereSchema.js +13 -0
- package/dist/utils/whereSchema.js.map +1 -0
- package/package.json +8 -11
- package/src/defaultAccess.ts +3 -0
- package/src/endpoint/access.ts +88 -101
- package/src/endpoint/index.ts +14 -1
- package/src/exports/client.ts +2 -1
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +8 -16
- package/src/mcp/buildMcpServer.ts +131 -96
- package/src/mcp/builtin/collections/authTools.ts +45 -9
- package/src/mcp/builtin/collections/countTool.ts +74 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +70 -0
- package/src/mcp/builtin/collections/createTool.ts +55 -59
- package/src/mcp/builtin/collections/deleteTool.ts +19 -16
- package/src/mcp/builtin/collections/duplicateTool.ts +135 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +120 -0
- package/src/mcp/builtin/collections/findTool.ts +63 -33
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +110 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +155 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +46 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
- package/src/mcp/builtin/collections/updateTool.ts +111 -110
- package/src/mcp/builtin/getConfigInfoTool.ts +69 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/findTool.ts +26 -17
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +104 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +148 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +41 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +100 -0
- package/src/mcp/builtin/globals/updateTool.ts +50 -55
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +111 -41
- package/src/mcp/sanitizeMCPConfig.ts +116 -78
- package/src/stdio.ts +23 -8
- package/src/types.ts +77 -112
- package/src/utils/getPluginConfig.ts +1 -1
- package/src/utils/schemaConversion/getEntityInputSchema.ts +62 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
- package/src/utils/whereSchema.ts +24 -0
- package/dist/collection/getAccessField.d.ts +0 -12
- package/dist/collection/getAccessField.d.ts.map +0 -1
- package/dist/collection/getAccessField.js +0 -57
- package/dist/collection/getAccessField.js.map +0 -1
- package/dist/collection/index.d.ts +0 -6
- package/dist/collection/index.d.ts.map +0 -1
- package/dist/collection/index.js +0 -60
- package/dist/collection/index.js.map +0 -1
- package/dist/components/AccessField/index.client.d.ts +0 -10
- package/dist/components/AccessField/index.client.d.ts.map +0 -1
- package/dist/components/AccessField/index.client.js +0 -305
- package/dist/components/AccessField/index.client.js.map +0 -1
- package/dist/components/AccessField/index.css +0 -93
- package/dist/utils/schemaConversion/buildToolInput.d.ts +0 -29
- package/dist/utils/schemaConversion/buildToolInput.d.ts.map +0 -1
- package/dist/utils/schemaConversion/buildToolInput.js +0 -51
- package/dist/utils/schemaConversion/buildToolInput.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/src/collection/getAccessField.ts +0 -64
- package/src/collection/index.ts +0 -64
- package/src/components/AccessField/index.client.tsx +0 -344
- package/src/components/AccessField/index.css +0 -93
- package/src/utils/schemaConversion/buildToolInput.ts +0 -68
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaWithJSON } from '@modelcontextprotocol/server';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
4
|
-
/**
|
|
5
|
-
* Builds a create/update tool's `input`: a `data` field (the document's fields) plus controls like
|
|
6
|
-
* `depth` and `draft`. Using just `z.fromJSONSchema(ourJSONSchema)` has a few problems which are mitigated
|
|
7
|
-
* in this function. z.fromJSONSchema is both bigger and lossier (≈40% larger on the lexical schema).
|
|
8
|
-
* Each example below is `what we publish` => `what a plain zod round-trip would publish instead`.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* Bigger - zod inlines shared defs instead of keeping our `$ref`s (and adds junk integer bounds), so a
|
|
12
|
-
* reused def is duplicated at every use:
|
|
13
|
-
* `{ $ref: '#/$defs/author' }` => `{ type: 'object', properties: { id, name }, additionalProperties: false }`
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* Lossier - zod drops the `description` on `enum`/`const` fields:
|
|
17
|
-
* `{ enum: ['draft', 'published'], description: 'Publish state' }` → `{ enum: ['draft', 'published'] }`
|
|
18
|
-
*/
|
|
19
|
-
export declare const buildToolInput: <TControls extends z.ZodRawShape>({ controls, dataDescription, dataSchema, }: {
|
|
20
|
-
/** Tool options alongside `data` (depth, draft, where, …) as plain zod - inferred into `input`. */
|
|
21
|
-
controls: TControls;
|
|
22
|
-
dataDescription: string;
|
|
23
|
-
dataSchema: JsonSchemaType;
|
|
24
|
-
}) => StandardSchemaWithJSON<{
|
|
25
|
-
data: Record<string, unknown>;
|
|
26
|
-
} & Omit<z.output<z.ZodObject<{
|
|
27
|
-
data: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
28
|
-
} & TControls extends infer T ? { -readonly [P in keyof T]: T[P]; } : never, z.core.$strip>>, "data">>;
|
|
29
|
-
//# sourceMappingURL=buildToolInput.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildToolInput.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/buildToolInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAE1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,CAAC,CAAC,WAAW,EAAE,4CAI7D;IACD,mGAAmG;IACnG,QAAQ,EAAE,SAAS,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,cAAc,CAAA;CAC3B,KAkCM,sBAAsB,CACzB;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM;;4FAAe,EAAE,MAAM,CAAC,CAE5E,CAAA"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* Builds a create/update tool's `input`: a `data` field (the document's fields) plus controls like
|
|
4
|
-
* `depth` and `draft`. Using just `z.fromJSONSchema(ourJSONSchema)` has a few problems which are mitigated
|
|
5
|
-
* in this function. z.fromJSONSchema is both bigger and lossier (≈40% larger on the lexical schema).
|
|
6
|
-
* Each example below is `what we publish` => `what a plain zod round-trip would publish instead`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* Bigger - zod inlines shared defs instead of keeping our `$ref`s (and adds junk integer bounds), so a
|
|
10
|
-
* reused def is duplicated at every use:
|
|
11
|
-
* `{ $ref: '#/$defs/author' }` => `{ type: 'object', properties: { id, name }, additionalProperties: false }`
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* Lossier - zod drops the `description` on `enum`/`const` fields:
|
|
15
|
-
* `{ enum: ['draft', 'published'], description: 'Publish state' }` → `{ enum: ['draft', 'published'] }`
|
|
16
|
-
*/ export const buildToolInput = ({ controls, dataDescription, dataSchema })=>{
|
|
17
|
-
// `sanitizeEntitySchema` already emits draft 2020-12 with `$defs`, which is what zod's `fromJSONSchema`
|
|
18
|
-
// and MCP clients both expect. Drop only the root `$schema` keyword, redundant once it's a sub-schema.
|
|
19
|
-
const { $schema: _schema, ...entitySchema } = dataSchema;
|
|
20
|
-
const schema = z.object({
|
|
21
|
-
data: z.fromJSONSchema(entitySchema),
|
|
22
|
-
...controls
|
|
23
|
-
});
|
|
24
|
-
const standard = schema['~standard'];
|
|
25
|
-
return {
|
|
26
|
-
'~standard': {
|
|
27
|
-
...standard,
|
|
28
|
-
jsonSchema: {
|
|
29
|
-
...standard.jsonSchema,
|
|
30
|
-
input: (options)=>{
|
|
31
|
-
// Start from zod's JSON Schema for the whole input, then replace its lossy `data` schema with
|
|
32
|
-
// the sanitized entity schema. The entity's `$defs` move to the root so the `$ref`s resolve.
|
|
33
|
-
const generated = standard.jsonSchema.input(options);
|
|
34
|
-
const { $defs, ...entityBody } = entitySchema;
|
|
35
|
-
generated.properties.data = {
|
|
36
|
-
...entityBody,
|
|
37
|
-
description: dataDescription
|
|
38
|
-
};
|
|
39
|
-
if ($defs) {
|
|
40
|
-
generated.$defs = $defs;
|
|
41
|
-
} else {
|
|
42
|
-
delete generated.$defs;
|
|
43
|
-
}
|
|
44
|
-
return generated;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=buildToolInput.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/buildToolInput.ts"],"sourcesContent":["import type { StandardSchemaWithJSON } from '@modelcontextprotocol/server'\n\nimport { z } from 'zod'\n\nimport type { JsonSchemaType } from '../../types.js'\n\n/**\n * Builds a create/update tool's `input`: a `data` field (the document's fields) plus controls like\n * `depth` and `draft`. Using just `z.fromJSONSchema(ourJSONSchema)` has a few problems which are mitigated\n * in this function. z.fromJSONSchema is both bigger and lossier (≈40% larger on the lexical schema).\n * Each example below is `what we publish` => `what a plain zod round-trip would publish instead`.\n *\n * @example\n * Bigger - zod inlines shared defs instead of keeping our `$ref`s (and adds junk integer bounds), so a\n * reused def is duplicated at every use:\n * `{ $ref: '#/$defs/author' }` => `{ type: 'object', properties: { id, name }, additionalProperties: false }`\n *\n * @example\n * Lossier - zod drops the `description` on `enum`/`const` fields:\n * `{ enum: ['draft', 'published'], description: 'Publish state' }` → `{ enum: ['draft', 'published'] }`\n */\nexport const buildToolInput = <TControls extends z.ZodRawShape>({\n controls,\n dataDescription,\n dataSchema,\n}: {\n /** Tool options alongside `data` (depth, draft, where, …) as plain zod - inferred into `input`. */\n controls: TControls\n dataDescription: string\n dataSchema: JsonSchemaType\n}) => {\n // `sanitizeEntitySchema` already emits draft 2020-12 with `$defs`, which is what zod's `fromJSONSchema`\n // and MCP clients both expect. Drop only the root `$schema` keyword, redundant once it's a sub-schema.\n const { $schema: _schema, ...entitySchema } = dataSchema as Record<string, unknown>\n\n const schema = z.object({\n data: z.fromJSONSchema(entitySchema as unknown as z.core.JSONSchema.JSONSchema),\n ...controls,\n })\n const standard = (schema as unknown as StandardSchemaWithJSON)['~standard']\n\n return {\n '~standard': {\n ...standard,\n jsonSchema: {\n ...standard.jsonSchema,\n input: (options) => {\n // Start from zod's JSON Schema for the whole input, then replace its lossy `data` schema with\n // the sanitized entity schema. The entity's `$defs` move to the root so the `$ref`s resolve.\n const generated = standard.jsonSchema.input(options)\n const { $defs, ...entityBody } = entitySchema\n ;(generated.properties as Record<string, unknown>).data = {\n ...entityBody,\n description: dataDescription,\n }\n if ($defs) {\n generated.$defs = $defs as object\n } else {\n delete generated.$defs\n }\n return generated\n },\n },\n },\n } as StandardSchemaWithJSON<\n { data: Record<string, unknown> } & Omit<z.output<typeof schema>, 'data'>\n >\n}\n"],"names":["z","buildToolInput","controls","dataDescription","dataSchema","$schema","_schema","entitySchema","schema","object","data","fromJSONSchema","standard","jsonSchema","input","options","generated","$defs","entityBody","properties","description"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAIvB;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,iBAAiB,CAAkC,EAC9DC,QAAQ,EACRC,eAAe,EACfC,UAAU,EAMX;IACC,wGAAwG;IACxG,uGAAuG;IACvG,MAAM,EAAEC,SAASC,OAAO,EAAE,GAAGC,cAAc,GAAGH;IAE9C,MAAMI,SAASR,EAAES,MAAM,CAAC;QACtBC,MAAMV,EAAEW,cAAc,CAACJ;QACvB,GAAGL,QAAQ;IACb;IACA,MAAMU,WAAW,AAACJ,MAA4C,CAAC,YAAY;IAE3E,OAAO;QACL,aAAa;YACX,GAAGI,QAAQ;YACXC,YAAY;gBACV,GAAGD,SAASC,UAAU;gBACtBC,OAAO,CAACC;oBACN,8FAA8F;oBAC9F,6FAA6F;oBAC7F,MAAMC,YAAYJ,SAASC,UAAU,CAACC,KAAK,CAACC;oBAC5C,MAAM,EAAEE,KAAK,EAAE,GAAGC,YAAY,GAAGX;oBAC/BS,UAAUG,UAAU,CAA6BT,IAAI,GAAG;wBACxD,GAAGQ,UAAU;wBACbE,aAAajB;oBACf;oBACA,IAAIc,OAAO;wBACTD,UAAUC,KAAK,GAAGA;oBACpB,OAAO;wBACL,OAAOD,UAAUC,KAAK;oBACxB;oBACA,OAAOD;gBACT;YACF;QACF;IACF;AAGF,EAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Removes virtual fields from a JSON Schema by name so they don't appear
|
|
4
|
-
* in the generated MCP tool input schema.
|
|
5
|
-
*/
|
|
6
|
-
export declare function removeVirtualFieldsFromSchema(schema: JsonSchemaType, virtualFieldNames: string[]): JsonSchemaType;
|
|
7
|
-
//# sourceMappingURL=removeVirtualFieldsFromSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"removeVirtualFieldsFromSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,cAAc,EACtB,iBAAiB,EAAE,MAAM,EAAE,GAC1B,cAAc,CAiBhB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes virtual fields from a JSON Schema by name so they don't appear
|
|
3
|
-
* in the generated MCP tool input schema.
|
|
4
|
-
*/ export function removeVirtualFieldsFromSchema(schema, virtualFieldNames) {
|
|
5
|
-
if (virtualFieldNames.length === 0) {
|
|
6
|
-
return schema;
|
|
7
|
-
}
|
|
8
|
-
for (const name of virtualFieldNames){
|
|
9
|
-
delete schema?.properties?.[name];
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(schema.required)) {
|
|
12
|
-
schema.required = schema.required.filter((field)=>!virtualFieldNames.includes(field));
|
|
13
|
-
if (schema.required.length === 0) {
|
|
14
|
-
delete schema.required;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return schema;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=removeVirtualFieldsFromSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts"],"sourcesContent":["import type { JsonSchemaType } from '../../types.js'\n\n/**\n * Removes virtual fields from a JSON Schema by name so they don't appear\n * in the generated MCP tool input schema.\n */\nexport function removeVirtualFieldsFromSchema(\n schema: JsonSchemaType,\n virtualFieldNames: string[],\n): JsonSchemaType {\n if (virtualFieldNames.length === 0) {\n return schema\n }\n\n for (const name of virtualFieldNames) {\n delete schema?.properties?.[name]\n }\n\n if (Array.isArray(schema.required)) {\n schema.required = schema.required.filter((field) => !virtualFieldNames.includes(field))\n if (schema.required.length === 0) {\n delete schema.required\n }\n }\n\n return schema\n}\n"],"names":["removeVirtualFieldsFromSchema","schema","virtualFieldNames","length","name","properties","Array","isArray","required","filter","field","includes"],"mappings":"AAEA;;;CAGC,GACD,OAAO,SAASA,8BACdC,MAAsB,EACtBC,iBAA2B;IAE3B,IAAIA,kBAAkBC,MAAM,KAAK,GAAG;QAClC,OAAOF;IACT;IAEA,KAAK,MAAMG,QAAQF,kBAAmB;QACpC,OAAOD,QAAQI,YAAY,CAACD,KAAK;IACnC;IAEA,IAAIE,MAAMC,OAAO,CAACN,OAAOO,QAAQ,GAAG;QAClCP,OAAOO,QAAQ,GAAGP,OAAOO,QAAQ,CAACC,MAAM,CAAC,CAACC,QAAU,CAACR,kBAAkBS,QAAQ,CAACD;QAChF,IAAIT,OAAOO,QAAQ,CAACL,MAAM,KAAK,GAAG;YAChC,OAAOF,OAAOO,QAAQ;QACxB;IACF;IAEA,OAAOP;AACT"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { JSONField } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { ClientMCPPluginConfig, MCPItem, SanitizedMCPPluginConfig } from '../types.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the API key collection's `access` field — a JSON field whose value
|
|
7
|
-
* is the `MCPAPIKeysDocAccessTree` the endpoint consults. The actual UI is
|
|
8
|
-
* a custom client component (`AccessField`) which renders a permissions
|
|
9
|
-
* matrix; the field's stored shape is just the runtime access tree.
|
|
10
|
-
*/
|
|
11
|
-
export const getAccessField = ({
|
|
12
|
-
pluginConfig,
|
|
13
|
-
}: {
|
|
14
|
-
pluginConfig: SanitizedMCPPluginConfig
|
|
15
|
-
}): JSONField => {
|
|
16
|
-
const clientPluginConfig = sanitizeClientPluginConfig(pluginConfig)
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
name: 'access',
|
|
20
|
-
type: 'json',
|
|
21
|
-
admin: {
|
|
22
|
-
components: {
|
|
23
|
-
Field: {
|
|
24
|
-
clientProps: { pluginConfig: clientPluginConfig },
|
|
25
|
-
path: '@payloadcms/plugin-mcp/client#AccessField',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
// TODO: needs i18n once design is finalized
|
|
29
|
-
description: 'Access for this API key — uncheck to revoke individual tools.',
|
|
30
|
-
position: 'sidebar',
|
|
31
|
-
},
|
|
32
|
-
defaultValue: {},
|
|
33
|
-
// TODO: needs i18n once design is finalized
|
|
34
|
-
label: 'Access',
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Strips the non-serializable parts of `SanitizedMCPPluginConfig` (handlers,
|
|
40
|
-
* input/argsSchema functions, etc.) so the result is safe to thread to a
|
|
41
|
-
* client component via `clientProps`.
|
|
42
|
-
*/
|
|
43
|
-
const sanitizeClientPluginConfig = (
|
|
44
|
-
pluginConfig: SanitizedMCPPluginConfig,
|
|
45
|
-
): ClientMCPPluginConfig => ({
|
|
46
|
-
items: pluginConfig.items.map((item) => ({
|
|
47
|
-
...(item.type === 'collectionTool' ? { collectionSlug: item.collectionSlug } : {}),
|
|
48
|
-
...(item.type === 'globalTool' ? { globalSlug: item.globalSlug } : {}),
|
|
49
|
-
type: item.type,
|
|
50
|
-
description: itemDescription(item),
|
|
51
|
-
key: item.key,
|
|
52
|
-
label: item.label,
|
|
53
|
-
})),
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const itemDescription = (item: MCPItem): string => {
|
|
57
|
-
if (item.type === 'prompt') {
|
|
58
|
-
return item.prompt.description
|
|
59
|
-
}
|
|
60
|
-
if (item.type === 'resource') {
|
|
61
|
-
return item.resource.description
|
|
62
|
-
}
|
|
63
|
-
return item.tool.description
|
|
64
|
-
}
|
package/src/collection/index.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { SanitizedMCPPluginConfig } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { getAccessField } from './getAccessField.js'
|
|
6
|
-
|
|
7
|
-
export const getAPIKeysCollection = ({
|
|
8
|
-
pluginConfig,
|
|
9
|
-
}: {
|
|
10
|
-
pluginConfig: SanitizedMCPPluginConfig
|
|
11
|
-
}): CollectionConfig => {
|
|
12
|
-
const collection: CollectionConfig = {
|
|
13
|
-
slug: 'payload-mcp-api-keys',
|
|
14
|
-
admin: {
|
|
15
|
-
description:
|
|
16
|
-
'API keys control which collections, resources, tools, and prompts MCP clients can access',
|
|
17
|
-
group: 'MCP',
|
|
18
|
-
useAsTitle: 'label',
|
|
19
|
-
},
|
|
20
|
-
auth: {
|
|
21
|
-
disableLocalStrategy: true,
|
|
22
|
-
useAPIKey: true,
|
|
23
|
-
},
|
|
24
|
-
fields: [
|
|
25
|
-
{
|
|
26
|
-
name: 'user',
|
|
27
|
-
type: 'relationship',
|
|
28
|
-
admin: { description: 'The user that the API key is associated with.' },
|
|
29
|
-
relationTo: pluginConfig.userCollection,
|
|
30
|
-
required: true,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: 'label',
|
|
34
|
-
type: 'text',
|
|
35
|
-
admin: { description: 'A useful label for the API key.' },
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'description',
|
|
39
|
-
type: 'text',
|
|
40
|
-
admin: { description: 'The purpose of the API key.' },
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'overrideAccess',
|
|
44
|
-
type: 'checkbox',
|
|
45
|
-
admin: {
|
|
46
|
-
description:
|
|
47
|
-
'When checked, this key bypasses Payload access control on every operation it performs. Leave unchecked unless you have a specific reason.',
|
|
48
|
-
},
|
|
49
|
-
defaultValue: false,
|
|
50
|
-
label: 'Override access control',
|
|
51
|
-
},
|
|
52
|
-
getAccessField({ pluginConfig }),
|
|
53
|
-
],
|
|
54
|
-
labels: {
|
|
55
|
-
plural: 'API Keys',
|
|
56
|
-
singular: 'API Key',
|
|
57
|
-
},
|
|
58
|
-
versions: false,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return pluginConfig.overrideApiKeyCollection
|
|
62
|
-
? pluginConfig.overrideApiKeyCollection(collection)
|
|
63
|
-
: collection
|
|
64
|
-
}
|
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import type { JSONFieldClientProps } from 'payload'
|
|
4
|
-
|
|
5
|
-
import { CheckboxInput, Collapsible, useField } from '@payloadcms/ui'
|
|
6
|
-
import React from 'react'
|
|
7
|
-
|
|
8
|
-
import type { ClientMCPPluginConfig, MCPAPIKeysDocAccessTree } from '../../types.js'
|
|
9
|
-
|
|
10
|
-
import './index.css'
|
|
11
|
-
|
|
12
|
-
const baseClass = 'mcp-access-field'
|
|
13
|
-
|
|
14
|
-
type ClientItem = ClientMCPPluginConfig['items'][number]
|
|
15
|
-
type ScopeKey = 'collections' | 'globals'
|
|
16
|
-
type FlatKey = 'prompts' | 'resources' | 'tools'
|
|
17
|
-
|
|
18
|
-
type Props = {
|
|
19
|
-
pluginConfig: ClientMCPPluginConfig
|
|
20
|
-
} & JSONFieldClientProps
|
|
21
|
-
|
|
22
|
-
/** Drop a key from an object and return a new object — or `undefined` if it'd be empty. */
|
|
23
|
-
const without = <T extends Record<string, unknown>>(
|
|
24
|
-
obj: T | undefined,
|
|
25
|
-
key: string,
|
|
26
|
-
): T | undefined => {
|
|
27
|
-
if (!obj || !(key in obj)) {
|
|
28
|
-
return obj
|
|
29
|
-
}
|
|
30
|
-
const { [key]: _omitted, ...rest } = obj
|
|
31
|
-
return Object.keys(rest).length === 0 ? undefined : (rest as T)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const setKey = <T extends Record<string, unknown>>(
|
|
35
|
-
obj: T | undefined,
|
|
36
|
-
key: string,
|
|
37
|
-
value: unknown,
|
|
38
|
-
): T => ({ ...(obj ?? {}), [key]: value }) as T
|
|
39
|
-
|
|
40
|
-
export const AccessField: React.FC<Props> = ({ path, pluginConfig }) => {
|
|
41
|
-
const { setValue, value } = useField<MCPAPIKeysDocAccessTree>({ path })
|
|
42
|
-
const access = value ?? {}
|
|
43
|
-
|
|
44
|
-
// Bucket items for rendering. (Bucketing is cheap and runs once per render;
|
|
45
|
-
// memoizing would mean managing inputs/refs for marginal benefit.)
|
|
46
|
-
const collectionsBySlug: Record<string, ClientItem[]> = {}
|
|
47
|
-
const globalsBySlug: Record<string, ClientItem[]> = {}
|
|
48
|
-
const tools: ClientItem[] = []
|
|
49
|
-
const prompts: ClientItem[] = []
|
|
50
|
-
const resources: ClientItem[] = []
|
|
51
|
-
for (const item of pluginConfig.items) {
|
|
52
|
-
switch (item.type) {
|
|
53
|
-
case 'collectionTool':
|
|
54
|
-
;(collectionsBySlug[item.collectionSlug!] ??= []).push(item)
|
|
55
|
-
break
|
|
56
|
-
case 'globalTool':
|
|
57
|
-
;(globalsBySlug[item.globalSlug!] ??= []).push(item)
|
|
58
|
-
break
|
|
59
|
-
case 'prompt':
|
|
60
|
-
prompts.push(item)
|
|
61
|
-
break
|
|
62
|
-
case 'resource':
|
|
63
|
-
resources.push(item)
|
|
64
|
-
break
|
|
65
|
-
case 'tool':
|
|
66
|
-
tools.push(item)
|
|
67
|
-
break
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const isScopedAllowed = (scope: ScopeKey, slug: string, key: string): boolean =>
|
|
72
|
-
access[scope]?.[slug]?.[key] !== false
|
|
73
|
-
|
|
74
|
-
const isFlatAllowed = (scope: FlatKey, key: string): boolean => access[scope]?.[key] !== false
|
|
75
|
-
|
|
76
|
-
const toggleScoped = (scope: ScopeKey, slug: string, key: string, allow: boolean) => {
|
|
77
|
-
if (allow) {
|
|
78
|
-
const slugBucket = without(access[scope]?.[slug], key)
|
|
79
|
-
const scopeBucket = slugBucket
|
|
80
|
-
? setKey(access[scope], slug, slugBucket)
|
|
81
|
-
: without(access[scope], slug)
|
|
82
|
-
setValue(scopeBucket ? setKey(access, scope, scopeBucket) : (without(access, scope) ?? {}))
|
|
83
|
-
} else {
|
|
84
|
-
setValue(
|
|
85
|
-
setKey(
|
|
86
|
-
access,
|
|
87
|
-
scope,
|
|
88
|
-
setKey(access[scope], slug, setKey(access[scope]?.[slug], key, false)),
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const toggleFlat = (scope: FlatKey, key: string, allow: boolean) => {
|
|
95
|
-
if (allow) {
|
|
96
|
-
const bucket = without(access[scope], key)
|
|
97
|
-
setValue(bucket ? setKey(access, scope, bucket) : (without(access, scope) ?? {}))
|
|
98
|
-
} else {
|
|
99
|
-
setValue(setKey(access, scope, setKey(access[scope], key, false)))
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const setAllScoped = (scope: ScopeKey, slug: string, leaves: ClientItem[], allow: boolean) => {
|
|
104
|
-
if (allow) {
|
|
105
|
-
const scopeBucket = without(access[scope], slug)
|
|
106
|
-
setValue(scopeBucket ? setKey(access, scope, scopeBucket) : (without(access, scope) ?? {}))
|
|
107
|
-
} else {
|
|
108
|
-
const slugBucket = leaves.reduce<Record<string, boolean>>(
|
|
109
|
-
(acc, leaf) => ({ ...acc, [leaf.key]: false }),
|
|
110
|
-
{},
|
|
111
|
-
)
|
|
112
|
-
setValue(setKey(access, scope, setKey(access[scope], slug, slugBucket)))
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const setAllFlat = (scope: FlatKey, leaves: ClientItem[], allow: boolean) => {
|
|
117
|
-
if (allow) {
|
|
118
|
-
setValue(without(access, scope) ?? {})
|
|
119
|
-
} else {
|
|
120
|
-
const bucket = leaves.reduce<Record<string, boolean>>(
|
|
121
|
-
(acc, leaf) => ({ ...acc, [leaf.key]: false }),
|
|
122
|
-
{},
|
|
123
|
-
)
|
|
124
|
-
setValue(setKey(access, scope, bucket))
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const collectionSlugs = Object.keys(collectionsBySlug)
|
|
129
|
-
const globalSlugs = Object.keys(globalsBySlug)
|
|
130
|
-
|
|
131
|
-
return (
|
|
132
|
-
<div className={baseClass}>
|
|
133
|
-
{collectionSlugs.length > 0 && (
|
|
134
|
-
<section className={`${baseClass}__section`}>
|
|
135
|
-
<header className={`${baseClass}__section-header`}>
|
|
136
|
-
{/* TODO: needs i18n once design is finalized */}
|
|
137
|
-
<h4>Collection-level permissions</h4>
|
|
138
|
-
{/* TODO: needs i18n once design is finalized */}
|
|
139
|
-
<p>Allow MCP clients to perform the following actions within these collections:</p>
|
|
140
|
-
</header>
|
|
141
|
-
{collectionSlugs.map((slug) => {
|
|
142
|
-
const leaves = collectionsBySlug[slug]!
|
|
143
|
-
return (
|
|
144
|
-
<Collapsible
|
|
145
|
-
actions={
|
|
146
|
-
<GroupActions
|
|
147
|
-
onSetAll={(allow) => setAllScoped('collections', slug, leaves, allow)}
|
|
148
|
-
/>
|
|
149
|
-
}
|
|
150
|
-
className={`${baseClass}__group`}
|
|
151
|
-
header={<span className={`${baseClass}__group-label`}>{titleCase(slug)}</span>}
|
|
152
|
-
initCollapsed
|
|
153
|
-
key={`collection-${slug}`}
|
|
154
|
-
>
|
|
155
|
-
<ul className={`${baseClass}__list`}>
|
|
156
|
-
{leaves.map((leaf) => (
|
|
157
|
-
<li key={leaf.key}>
|
|
158
|
-
<CheckboxInput
|
|
159
|
-
checked={isScopedAllowed('collections', slug, leaf.key)}
|
|
160
|
-
id={`${path}.collections.${slug}.${leaf.key}`}
|
|
161
|
-
label={leaf.label}
|
|
162
|
-
onToggle={(e) =>
|
|
163
|
-
toggleScoped('collections', slug, leaf.key, e.target.checked)
|
|
164
|
-
}
|
|
165
|
-
tooltip={leaf.description}
|
|
166
|
-
/>
|
|
167
|
-
</li>
|
|
168
|
-
))}
|
|
169
|
-
</ul>
|
|
170
|
-
</Collapsible>
|
|
171
|
-
)
|
|
172
|
-
})}
|
|
173
|
-
</section>
|
|
174
|
-
)}
|
|
175
|
-
|
|
176
|
-
{globalSlugs.length > 0 && (
|
|
177
|
-
<section className={`${baseClass}__section`}>
|
|
178
|
-
<header className={`${baseClass}__section-header`}>
|
|
179
|
-
{/* TODO: needs i18n once design is finalized */}
|
|
180
|
-
<h4>Global-level permissions</h4>
|
|
181
|
-
{/* TODO: needs i18n once design is finalized */}
|
|
182
|
-
<p>Allow MCP clients to perform the following actions on these globals:</p>
|
|
183
|
-
</header>
|
|
184
|
-
{globalSlugs.map((slug) => {
|
|
185
|
-
const leaves = globalsBySlug[slug]!
|
|
186
|
-
return (
|
|
187
|
-
<Collapsible
|
|
188
|
-
actions={
|
|
189
|
-
<GroupActions
|
|
190
|
-
onSetAll={(allow) => setAllScoped('globals', slug, leaves, allow)}
|
|
191
|
-
/>
|
|
192
|
-
}
|
|
193
|
-
className={`${baseClass}__group`}
|
|
194
|
-
header={<span className={`${baseClass}__group-label`}>{titleCase(slug)}</span>}
|
|
195
|
-
initCollapsed
|
|
196
|
-
key={`global-${slug}`}
|
|
197
|
-
>
|
|
198
|
-
<ul className={`${baseClass}__list`}>
|
|
199
|
-
{leaves.map((leaf) => (
|
|
200
|
-
<li key={leaf.key}>
|
|
201
|
-
<CheckboxInput
|
|
202
|
-
checked={isScopedAllowed('globals', slug, leaf.key)}
|
|
203
|
-
id={`${path}.globals.${slug}.${leaf.key}`}
|
|
204
|
-
label={leaf.label}
|
|
205
|
-
onToggle={(e) => toggleScoped('globals', slug, leaf.key, e.target.checked)}
|
|
206
|
-
tooltip={leaf.description}
|
|
207
|
-
/>
|
|
208
|
-
</li>
|
|
209
|
-
))}
|
|
210
|
-
</ul>
|
|
211
|
-
</Collapsible>
|
|
212
|
-
)
|
|
213
|
-
})}
|
|
214
|
-
</section>
|
|
215
|
-
)}
|
|
216
|
-
|
|
217
|
-
{(tools.length > 0 || prompts.length > 0 || resources.length > 0) && (
|
|
218
|
-
<section className={`${baseClass}__section`}>
|
|
219
|
-
<header className={`${baseClass}__section-header`}>
|
|
220
|
-
{/* TODO: needs i18n once design is finalized */}
|
|
221
|
-
<h4>Project-level permissions</h4>
|
|
222
|
-
{/* TODO: needs i18n once design is finalized */}
|
|
223
|
-
<p>Cross-cutting tools, prompts, and resources not scoped to a single collection.</p>
|
|
224
|
-
</header>
|
|
225
|
-
{tools.length > 0 && (
|
|
226
|
-
<Collapsible
|
|
227
|
-
actions={<GroupActions onSetAll={(allow) => setAllFlat('tools', tools, allow)} />}
|
|
228
|
-
className={`${baseClass}__group`}
|
|
229
|
-
header={
|
|
230
|
-
/* TODO: needs i18n once design is finalized */
|
|
231
|
-
<span className={`${baseClass}__group-label`}>Tools</span>
|
|
232
|
-
}
|
|
233
|
-
initCollapsed
|
|
234
|
-
>
|
|
235
|
-
<ul className={`${baseClass}__list`}>
|
|
236
|
-
{tools.map((leaf) => (
|
|
237
|
-
<li key={leaf.key}>
|
|
238
|
-
<CheckboxInput
|
|
239
|
-
checked={isFlatAllowed('tools', leaf.key)}
|
|
240
|
-
id={`${path}.tools.${leaf.key}`}
|
|
241
|
-
label={leaf.label}
|
|
242
|
-
onToggle={(e) => toggleFlat('tools', leaf.key, e.target.checked)}
|
|
243
|
-
tooltip={leaf.description}
|
|
244
|
-
/>
|
|
245
|
-
</li>
|
|
246
|
-
))}
|
|
247
|
-
</ul>
|
|
248
|
-
</Collapsible>
|
|
249
|
-
)}
|
|
250
|
-
{prompts.length > 0 && (
|
|
251
|
-
<Collapsible
|
|
252
|
-
actions={<GroupActions onSetAll={(allow) => setAllFlat('prompts', prompts, allow)} />}
|
|
253
|
-
className={`${baseClass}__group`}
|
|
254
|
-
header={
|
|
255
|
-
/* TODO: needs i18n once design is finalized */
|
|
256
|
-
<span className={`${baseClass}__group-label`}>Prompts</span>
|
|
257
|
-
}
|
|
258
|
-
initCollapsed
|
|
259
|
-
>
|
|
260
|
-
<ul className={`${baseClass}__list`}>
|
|
261
|
-
{prompts.map((leaf) => (
|
|
262
|
-
<li key={leaf.key}>
|
|
263
|
-
<CheckboxInput
|
|
264
|
-
checked={isFlatAllowed('prompts', leaf.key)}
|
|
265
|
-
id={`${path}.prompts.${leaf.key}`}
|
|
266
|
-
label={leaf.label}
|
|
267
|
-
onToggle={(e) => toggleFlat('prompts', leaf.key, e.target.checked)}
|
|
268
|
-
tooltip={leaf.description}
|
|
269
|
-
/>
|
|
270
|
-
</li>
|
|
271
|
-
))}
|
|
272
|
-
</ul>
|
|
273
|
-
</Collapsible>
|
|
274
|
-
)}
|
|
275
|
-
{resources.length > 0 && (
|
|
276
|
-
<Collapsible
|
|
277
|
-
actions={
|
|
278
|
-
<GroupActions onSetAll={(allow) => setAllFlat('resources', resources, allow)} />
|
|
279
|
-
}
|
|
280
|
-
className={`${baseClass}__group`}
|
|
281
|
-
header={
|
|
282
|
-
/* TODO: needs i18n once design is finalized */
|
|
283
|
-
<span className={`${baseClass}__group-label`}>Resources</span>
|
|
284
|
-
}
|
|
285
|
-
initCollapsed
|
|
286
|
-
>
|
|
287
|
-
<ul className={`${baseClass}__list`}>
|
|
288
|
-
{resources.map((leaf) => (
|
|
289
|
-
<li key={leaf.key}>
|
|
290
|
-
<CheckboxInput
|
|
291
|
-
checked={isFlatAllowed('resources', leaf.key)}
|
|
292
|
-
id={`${path}.resources.${leaf.key}`}
|
|
293
|
-
label={leaf.label}
|
|
294
|
-
onToggle={(e) => toggleFlat('resources', leaf.key, e.target.checked)}
|
|
295
|
-
tooltip={leaf.description}
|
|
296
|
-
/>
|
|
297
|
-
</li>
|
|
298
|
-
))}
|
|
299
|
-
</ul>
|
|
300
|
-
</Collapsible>
|
|
301
|
-
)}
|
|
302
|
-
</section>
|
|
303
|
-
)}
|
|
304
|
-
</div>
|
|
305
|
-
)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const GroupActions: React.FC<{ onSetAll: (allow: boolean) => void }> = ({ onSetAll }) => (
|
|
309
|
-
// TODO: button labels + aria-labels need i18n once design is finalized
|
|
310
|
-
<div className={`${baseClass}__group-actions`}>
|
|
311
|
-
<button
|
|
312
|
-
aria-label="Select all"
|
|
313
|
-
className={`${baseClass}__action`}
|
|
314
|
-
onClick={(e) => {
|
|
315
|
-
e.stopPropagation()
|
|
316
|
-
onSetAll(true)
|
|
317
|
-
}}
|
|
318
|
-
title="Select all"
|
|
319
|
-
type="button"
|
|
320
|
-
>
|
|
321
|
-
all
|
|
322
|
-
</button>
|
|
323
|
-
<span aria-hidden className={`${baseClass}__action-sep`}>
|
|
324
|
-
/
|
|
325
|
-
</span>
|
|
326
|
-
<button
|
|
327
|
-
aria-label="Clear all"
|
|
328
|
-
className={`${baseClass}__action`}
|
|
329
|
-
onClick={(e) => {
|
|
330
|
-
e.stopPropagation()
|
|
331
|
-
onSetAll(false)
|
|
332
|
-
}}
|
|
333
|
-
title="Clear all"
|
|
334
|
-
type="button"
|
|
335
|
-
>
|
|
336
|
-
none
|
|
337
|
-
</button>
|
|
338
|
-
</div>
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
const titleCase = (slug: string): string =>
|
|
342
|
-
slug.replace(/(^|[-_])(.)/g, (_, sep: string, ch: string) =>
|
|
343
|
-
sep ? ` ${ch.toUpperCase()}` : ch.toUpperCase(),
|
|
344
|
-
)
|