@elementor/editor-variables 3.35.0-470 → 3.35.0-471

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-variables",
3
- "version": "3.35.0-470",
3
+ "version": "3.35.0-471",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,22 +39,22 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "3.35.0-470",
43
- "@elementor/editor-canvas": "3.35.0-470",
44
- "@elementor/editor-controls": "3.35.0-470",
45
- "@elementor/editor-current-user": "3.35.0-470",
46
- "@elementor/editor-editing-panel": "3.35.0-470",
47
- "@elementor/editor-mcp": "3.35.0-470",
48
- "@elementor/editor-panels": "3.35.0-470",
49
- "@elementor/editor-props": "3.35.0-470",
50
- "@elementor/editor-ui": "3.35.0-470",
51
- "@elementor/editor-v1-adapters": "3.35.0-470",
52
- "@elementor/http-client": "3.35.0-470",
42
+ "@elementor/editor": "3.35.0-471",
43
+ "@elementor/editor-canvas": "3.35.0-471",
44
+ "@elementor/editor-controls": "3.35.0-471",
45
+ "@elementor/editor-current-user": "3.35.0-471",
46
+ "@elementor/editor-editing-panel": "3.35.0-471",
47
+ "@elementor/editor-mcp": "3.35.0-471",
48
+ "@elementor/editor-panels": "3.35.0-471",
49
+ "@elementor/editor-props": "3.35.0-471",
50
+ "@elementor/editor-ui": "3.35.0-471",
51
+ "@elementor/editor-v1-adapters": "3.35.0-471",
52
+ "@elementor/http-client": "3.35.0-471",
53
53
  "@elementor/icons": "^1.63.0",
54
- "@elementor/mixpanel": "3.35.0-470",
55
- "@elementor/schema": "3.35.0-470",
54
+ "@elementor/mixpanel": "3.35.0-471",
55
+ "@elementor/schema": "3.35.0-471",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "3.35.0-470",
57
+ "@elementor/utils": "3.35.0-471",
58
58
  "@wordpress/i18n": "^5.13.0"
59
59
  },
60
60
  "peerDependencies": {
package/src/mcp/index.ts CHANGED
@@ -1,11 +1,7 @@
1
- import { initCreateVariableTool } from './create-variable-tool';
2
- import { initDeleteVariableTool } from './delete-variable-tool';
3
- import { initUpdateVariableTool } from './update-variable-tool';
1
+ import { initManageVariableTool } from './manage-variable-tool';
4
2
  import { initVariablesResource } from './variables-resource';
5
3
 
6
4
  export function initMcp() {
7
- initCreateVariableTool();
8
- initUpdateVariableTool();
9
- initDeleteVariableTool();
5
+ initManageVariableTool();
10
6
  initVariablesResource();
11
7
  }
@@ -0,0 +1,85 @@
1
+ import { getMCPByDomain } from '@elementor/editor-mcp';
2
+ import { z } from '@elementor/schema';
3
+
4
+ import { service } from '../service';
5
+ import { GLOBAL_VARIABLES_URI } from './variables-resource';
6
+
7
+ export const initManageVariableTool = () => {
8
+ getMCPByDomain( 'variables' ).addTool( {
9
+ name: 'manage-global-variable',
10
+ schema: {
11
+ action: z.enum( [ 'create', 'update', 'delete' ] ).describe( 'Operation to perform' ),
12
+ id: z
13
+ .string()
14
+ .optional()
15
+ .describe( 'Variable id (required for update/delete). Get from list-global-variables.' ),
16
+ type: z
17
+ .string()
18
+ .optional()
19
+ .describe( 'Variable type: "global-color-variable" or "global-font-variable" (required for create)' ),
20
+ label: z.string().optional().describe( 'Variable label (required for create/update)' ),
21
+ value: z.string().optional().describe( 'Variable value (required for create/update)' ),
22
+ },
23
+ outputSchema: {
24
+ status: z.enum( [ 'ok' ] ).describe( 'Operation status' ),
25
+ message: z.string().optional().describe( 'Error details if status is error' ),
26
+ },
27
+ modelPreferences: {
28
+ intelligencePriority: 0.75,
29
+ speedPriority: 0.75,
30
+ },
31
+ requiredResources: [
32
+ {
33
+ uri: GLOBAL_VARIABLES_URI,
34
+ description: 'Global variables',
35
+ },
36
+ ],
37
+ description: `Manages global variables (create/update/delete). Existing variables available in resources.
38
+ CREATE: requires type, label, value. Ensure label is unique.
39
+ UPDATE: requires id, label, value. When renaming: keep existing value. When updating value: keep exact label.
40
+ DELETE: requires id. DESTRUCTIVE - confirm with user first.
41
+
42
+ # NAMING - IMPORTANT
43
+ the variables names should ALWAYS be lowercased and dashed spaced. example: "Headline Primary" should be "headline-primary"
44
+ `,
45
+ handler: async ( params ) => {
46
+ const operations = getServiceActions( service );
47
+ const op = operations[ params.action ];
48
+ if ( op ) {
49
+ await op( params );
50
+ return {
51
+ status: 'ok',
52
+ };
53
+ }
54
+ throw new Error( `Unknown action ${ params.action }` );
55
+ },
56
+ isDestructive: true, // Because delete is destructive
57
+ } );
58
+ };
59
+
60
+ type Opts< T extends Record< string, string > > = Partial< T > & {
61
+ [ k: string ]: unknown;
62
+ };
63
+
64
+ function getServiceActions( svc: typeof service ) {
65
+ return {
66
+ create( { type, label, value }: Opts< { type: string; label: string; value: string } > ) {
67
+ if ( ! type || ! label || ! value ) {
68
+ throw new Error( 'Create requires type, label, and value' );
69
+ }
70
+ return svc.create( { type, label, value } );
71
+ },
72
+ update( { id, label, value }: Opts< { id: string; label: string; value: string } > ) {
73
+ if ( ! id || ! label || ! value ) {
74
+ throw new Error( 'Update requires id, label, and value' );
75
+ }
76
+ return svc.update( id, { label, value } );
77
+ },
78
+ delete( { id }: Opts< { id: string } > ) {
79
+ if ( ! id ) {
80
+ throw new Error( 'delete requires id' );
81
+ }
82
+ return svc.delete( id );
83
+ },
84
+ };
85
+ }
@@ -6,33 +6,37 @@ import { type TVariable } from '../storage';
6
6
  export const GLOBAL_VARIABLES_URI = 'elementor://global-variables';
7
7
 
8
8
  export const initVariablesResource = () => {
9
- const { mcpServer } = getMCPByDomain( 'canvas' );
9
+ const canvasMcpEntry = getMCPByDomain( 'canvas' );
10
+ const variablesMcpEntry = getMCPByDomain( 'variables' );
10
11
 
11
- mcpServer.resource(
12
- 'global-variables',
13
- GLOBAL_VARIABLES_URI,
14
- {
15
- description:
16
- 'List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)',
17
- },
18
- async () => {
19
- const variables: Record< string, TVariable > = {};
20
- Object.entries( service.variables() ).forEach( ( [ id, variable ] ) => {
21
- if ( ! variable.deleted ) {
22
- variables[ id ] = variable;
23
- }
24
- } );
12
+ [ canvasMcpEntry, variablesMcpEntry ].forEach( ( entry ) => {
13
+ const { mcpServer } = entry;
14
+ mcpServer.resource(
15
+ 'global-variables',
16
+ GLOBAL_VARIABLES_URI,
17
+ {
18
+ description:
19
+ 'List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)',
20
+ },
21
+ async () => {
22
+ const variables: Record< string, TVariable > = {};
23
+ Object.entries( service.variables() ).forEach( ( [ id, variable ] ) => {
24
+ if ( ! variable.deleted ) {
25
+ variables[ id ] = variable;
26
+ }
27
+ } );
25
28
 
26
- return {
27
- contents: [ { uri: GLOBAL_VARIABLES_URI, text: JSON.stringify( variables ) } ],
28
- };
29
- }
30
- );
29
+ return {
30
+ contents: [ { uri: GLOBAL_VARIABLES_URI, text: JSON.stringify( variables ) } ],
31
+ };
32
+ }
33
+ );
31
34
 
32
- window.addEventListener( 'variables:updated', () => {
33
- mcpServer.server.sendResourceUpdated( {
34
- uri: GLOBAL_VARIABLES_URI,
35
- contents: [ { uri: GLOBAL_VARIABLES_URI, text: localStorage[ 'elementor-global-variables' ] } ],
35
+ window.addEventListener( 'variables:updated', () => {
36
+ mcpServer.server.sendResourceUpdated( {
37
+ uri: GLOBAL_VARIABLES_URI,
38
+ contents: [ { uri: GLOBAL_VARIABLES_URI, text: localStorage[ 'elementor-global-variables' ] } ],
39
+ } );
36
40
  } );
37
41
  } );
38
42
  };
@@ -1,25 +1,15 @@
1
1
  import { service } from '../service';
2
2
 
3
+ const defaultResolver = ( key: string ) => ( value: unknown ) => {
4
+ const idOrLabel = String( value );
5
+ return {
6
+ $$type: key,
7
+ value: service.variables()[ idOrLabel ] ? idOrLabel : service.findIdByLabel( idOrLabel ),
8
+ };
9
+ };
10
+
3
11
  export const globalVariablesLLMResolvers = {
4
- 'global-color-variable': ( value: unknown ) => {
5
- const idOrLabel = String( value );
6
- return {
7
- $$type: 'global-color-variable',
8
- value: service.variables()[ idOrLabel ] ? idOrLabel : service.findIdByLabel( idOrLabel ),
9
- };
10
- },
11
- 'global-font-variable': ( value: unknown ) => {
12
- const idOrLabel = String( value );
13
- return {
14
- $$type: 'global-font-variable',
15
- value: service.variables()[ idOrLabel ] ? idOrLabel : service.findIdByLabel( idOrLabel ),
16
- };
17
- },
18
- 'global-size-variable': ( value: unknown ) => {
19
- const idOrLabel = String( value );
20
- return {
21
- $$type: 'global-size-variable',
22
- value: service.variables()[ idOrLabel ] ? idOrLabel : service.findIdByLabel( idOrLabel ),
23
- };
24
- },
12
+ 'global-color-variable': defaultResolver( 'global-color-variable' ),
13
+ 'global-font-variable': defaultResolver( 'global-font-variable' ),
14
+ 'global-size-variable': defaultResolver( 'global-size-variable' ),
25
15
  };
@@ -1,74 +0,0 @@
1
- import { getMCPByDomain } from '@elementor/editor-mcp';
2
- import { z } from '@elementor/schema';
3
-
4
- import { service } from '../service';
5
-
6
- const InputSchema = {
7
- type: z
8
- .string()
9
- .describe( 'The type of the variable. Example values: "global-color-variable" or "global-font-variable".' ),
10
- label: z.string().describe( 'The label of the variable, displayed to the user' ),
11
- value: z.string().describe( 'The value of the variable, should correspond to the type' ),
12
- };
13
-
14
- const OutputSchema = {
15
- status: z.enum( [ 'ok', 'error' ] ).describe( 'The status of the operation' ),
16
- message: z.string().optional().describe( 'Optional message providing additional information about the operation' ),
17
- };
18
-
19
- export const initCreateVariableTool = () => {
20
- getMCPByDomain( 'canvas' ).addTool( {
21
- name: 'create-global-variable',
22
- schema: InputSchema,
23
- outputSchema: OutputSchema,
24
- modelPreferences: {
25
- intelligencePriority: 0.7,
26
- speedPriority: 0.7,
27
- },
28
- description: `Create a new global variable
29
- ## When to use this tool:
30
- - When a user requests to create a new global variable in the Elementor editor.
31
- - When you need to add a new variable to be used in the editor.
32
-
33
- ## Prequisites:
34
- - Ensure you have the most up-to-date list of existing global variables to avoid label duplication. You can use the "list-global-variables" tool to fetch the current variables.
35
- - Make sure when creating a new variable, the label is unique and not already in use.
36
- - If the user does not provide a label, ask them to provide one before proceeding.
37
- - If the user does not provide a type, ask them to provide one before proceeding.
38
- - If the user does not provide a value, ask them to provide one before proceeding.
39
-
40
- ## Required parameters:
41
- - type: The type of the variable. Possible values are 'global-color-variable' or 'global-font-variable'.
42
- - label: The label of the variable, displayed to the user. Must be unique and not already in use.
43
- - value: The value of the variable. For color variables, this should be a valid CSS color (e.g., 'rgb(255,0,0)', '#ff0000', 'red'). For font variables, this should be a valid font family (e.g., 'Arial', 'serif').
44
-
45
- ## Example tool call (JSON format):
46
- \`\`\`json
47
- { "type": "global-color-variable", "label": "My Cool Color", "value": "rgb(1,2,3)" }
48
- \`\`\`
49
-
50
- ## Example tool response (JSON format):
51
- \`\`\`json
52
- { "status": "ok" }
53
- \`\`\`
54
-
55
- ## Example to a failed tool response, which must be displayed to the end user. If the error message is not plain, attempt to find the most useful part of the message and display it.
56
- { "status": "error", "message": "Unsupported type 'global-kuku-variable'" }
57
-
58
- In that case, inform the user the type is unsupported and they should try another type, perhaps consult to online documentation.
59
- `,
60
- handler: async ( params ) => {
61
- const { type, label, value } = params;
62
- try {
63
- await service.create( { type, label, value } );
64
- } catch ( error ) {
65
- const message: string = ( error as Error ).message || 'Unknown server error';
66
- return {
67
- status: 'error',
68
- message: `There was an error creating the variable: ${ message }`,
69
- };
70
- }
71
- return { status: 'ok' };
72
- },
73
- } );
74
- };
@@ -1,54 +0,0 @@
1
- import { getMCPByDomain } from '@elementor/editor-mcp';
2
- import { z } from '@elementor/schema';
3
-
4
- import { service } from '../service';
5
-
6
- export const initDeleteVariableTool = () => {
7
- getMCPByDomain( 'canvas' ).addTool( {
8
- name: 'delete-global-variable',
9
- schema: {
10
- id: z.string().describe( 'The unique identifier of the variable to be deleted.' ),
11
- },
12
- outputSchema: {
13
- status: z.enum( [ 'ok', 'error' ] ).describe( 'The status of the operation' ),
14
- },
15
- modelPreferences: {
16
- intelligencePriority: 0.7,
17
- speedPriority: 0.8,
18
- },
19
- description: `Delete an existing global variable
20
-
21
- ## When to use this tool:
22
- - When a user requests to delete an existing global variable in the Elementor editor.
23
- - When you need to remove a variable that is no longer needed or relevant, with the user's confirmation.
24
-
25
- ## Prerequisites:
26
- - Ensure you have the most up-to-date list of existing global variables. You can use the "list-global-variables" tool to fetch the current variables.
27
- - Reference the variable by the "id" property, given from the "list-global-variables" tool.
28
- - Make sure you have the unique identifier of the variable to be deleted before using this tool.
29
- - Confirm with the user that they want to proceed with the deletion, as this action is irreversible.
30
-
31
- <notice>
32
- A use might reference a variable by it's label, but you must always use the unique identifier (id) to delete it.
33
- If you only have the label, use the "list-global-variables" tool to find the corresponding id.
34
- </notice>
35
-
36
- <important>
37
- This operation is destructive and cannot be undone. Ensure that the user is fully aware of the consequences before proceeding.
38
- When a variable is deleted, all references to it in all pages accross the website will lose their effect.
39
- </important>`,
40
- handler: async ( params ) => {
41
- const { id } = params;
42
- try {
43
- await service.delete( id );
44
- return { status: 'ok' };
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
- } catch ( err: unknown ) {
47
- return {
48
- status: 'error',
49
- };
50
- }
51
- },
52
- isDestrcutive: true,
53
- } );
54
- };
@@ -1,62 +0,0 @@
1
- import { getMCPByDomain } from '@elementor/editor-mcp';
2
- import { z } from '@elementor/schema';
3
-
4
- import { service } from '../service';
5
- import { type TVariable } from '../storage';
6
-
7
- const VariableSchema = {
8
- type: z.string().describe( 'The type of the variable.' ),
9
- label: z.string().describe( 'The label of the variable, displayed to the user' ),
10
- value: z.string().describe( 'The value of the variable.' ),
11
- id: z
12
- .string()
13
- .describe(
14
- 'The unique identifier of the variable. Used for internal reference, not to be exposed to end users'
15
- ),
16
- };
17
- const VariableListSchema = {
18
- variables: z.array( z.object( VariableSchema ) ).describe( 'List of variables' ),
19
- };
20
-
21
- export const initListVariablesTool = () => {
22
- getMCPByDomain( 'canvas' ).addTool( {
23
- name: 'list-global-variables',
24
- description: `List the global variables
25
-
26
- ## When to use this tool:
27
- - When a user requests to see all available global variables in the Elementor editor.
28
- - When you need to be exact on a variable label, to avoid any mistakes.
29
- - When you want to see the most up-to-date list of global variables.
30
- - Before using any other variables related tools that makes changes, such as deletion, creation, or updates. This ensures you have the latest information and there is no naming collision or mismatching.
31
-
32
- ## Example tool response (JSON format):
33
- \`\`\`json
34
- { variables: [
35
- { type: 'global-color-variable', label: 'Cool', value: 'rgb(1,2,3)', id: 'some-unique-id' },
36
- { type: 'global-font-variable', label: 'Headline', value: 'serif', id: 'some-other-unique-id' },
37
- ] }
38
- \`\`\`
39
-
40
- Once you get the response, please display the variables in a user-friendly way, unless explicitly requested otherwise.
41
- Unless explicitly requested otherwise, response in HTML Format, prefer to use tables or unordered lists.
42
-
43
- Note: **The label is most improtant to be seen as-is without any changes.**
44
-
45
- <important>
46
- **Do not omit the label**. This is important for the user to identify the variable.
47
- **Do not change the label**, it must be displayed exactly as it is, in it's original characters as received from this tool.
48
- </important>
49
- `,
50
- outputSchema: VariableListSchema,
51
- modelPreferences: {
52
- intelligencePriority: 0.5,
53
- speedPriority: 0.95,
54
- },
55
- handler: async () => {
56
- const variables = service.variables() as Record< string, TVariable >;
57
- return {
58
- variables: Object.entries( variables ).map( ( [ id, varData ] ) => ( { id, ...varData } ) ),
59
- };
60
- },
61
- } );
62
- };
@@ -1,85 +0,0 @@
1
- import { getMCPByDomain } from '@elementor/editor-mcp';
2
- import { z } from '@elementor/schema';
3
-
4
- import { service } from '../service';
5
-
6
- export const initUpdateVariableTool = () => {
7
- getMCPByDomain( 'canvas' ).addTool( {
8
- schema: {
9
- id: z.string().describe( 'The unique identifier of the variable to be updated or renamed.' ),
10
- label: z
11
- .string()
12
- .describe(
13
- 'The label of the variable to be stored after the change. If the user only wishes to update the value, this must be strictly equal to the current label.'
14
- ),
15
- value: z
16
- .string()
17
- .describe(
18
- "The new value for the variable. For color variables, this should be a valid CSS color (e.g., 'rgb(255,0,0)', '#ff0000', 'red'). For font variables, this should be a valid font family (e.g., 'Arial', 'serif'). If the user wishes to rename only, make sure you provide the existing value."
19
- ),
20
- },
21
- outputSchema: {
22
- status: z.enum( [ 'ok', 'error' ] ).describe( 'The status of the operation' ),
23
- message: z
24
- .string()
25
- .optional()
26
- .describe( 'Optional message providing additional information about the operation' ),
27
- },
28
- name: 'update-global-variable',
29
- modelPreferences: {
30
- intelligencePriority: 0.75,
31
- speedPriority: 0.7,
32
- },
33
- description: `Update an existing global variable
34
-
35
- ## When to use this tool:
36
- - When a user requests to update an existing global variable in the Elementor editor.
37
- - When you need to modify the value of an existing variable.
38
- - When you want to rename an existing variable (change its label).
39
- - When you want to both rename and modify the value of an existing variable.
40
-
41
- ## Prerequisites:
42
- - Ensure you have the most up-to-date list of existing global variables to avoid label duplication. You can use the "list-global-variables" tool to fetch the current variables.
43
- - Make sure when updating a variable, the new label is unique and not already in use by another variable.
44
- - Make sure you understand whether you are updating a value, renaming, or both.
45
- - Reference the variable by the "id" property, given from the "list-global-variables" tool.
46
- - If the user wishes to rename, make sure you have the existing value.
47
- - If the user wishes to update the value, make sure you have to **correct label**.
48
- - You must have the unique identifier, the current label, the current value, and the new value or label or both, before using this tool.
49
-
50
- ## Required parameters:
51
- - id: The unique identifier of the variable to be updated or renamed.
52
- - label: The label of the variable to be stored after the change. If the user only wishes to update the value, this must be strictly equal to the current label.
53
- - value: The new value for the variable. For color variables, this should be a valid CSS color (e.g., 'rgb(255,0,0)', '#ff0000', 'red'). For font variables, this should be a valid font family (e.g., 'Arial', 'serif'). If the user wishes to rename only, make sure you provide the existing value.
54
-
55
- ## Example tool call (JSON format):
56
- \`\`\`json
57
- { "id": "some-unique-id", "label": "Cool", "value": "rgb(0,140,250)" }
58
- \`\`\`
59
-
60
- ## Example responses (JSON format):
61
- Successful update:
62
- \`\`\`json
63
- { "status": "ok" }
64
- \`\`\`
65
-
66
- Failed update, which must be displayed to the end user. If the error message is not plain, attempt to find the most useful part of the message and display it.
67
- \`\`\`json
68
- { "status": "error", "message": "Label 'Cool' is already in use by another variable." }
69
- \`\`\`
70
- `,
71
- handler: async ( params ) => {
72
- const { id, label, value } = params;
73
- try {
74
- await service.update( id, { label, value } );
75
- return { status: 'ok' };
76
- } catch ( error ) {
77
- const message: string = ( error as Error ).message || 'Unknown server error';
78
- return {
79
- status: 'error',
80
- message: `There was an error creating the variable: ${ message }`,
81
- };
82
- }
83
- },
84
- } );
85
- };