@silexlabs/grapesjs-ai-capabilities 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GrapesJS AI Capabilities
2
2
 
3
- Discovery and metadata layer for GrapesJS commands. Allows plugins to register capabilities that external builders can expose as MCP tools or other AI integrations.
3
+ Discovery and metadata layer for GrapesJS commands. Sits between plugins that **expose** capabilities and builders that **consume** them (MCP servers, AI agents, chat interfaces, etc.).
4
4
 
5
5
  > This code is part of a bigger project: [about Silex v3](https://www.silex.me/)
6
6
 
@@ -17,77 +17,96 @@ The strategy: keep capability descriptions **minimal**. An SLM discovers availab
17
17
 
18
18
  This approach works because SLMs are iterative: they try, fail, read the error, and try again. A 500-token tool description wastes context; a 5-word description plus a clear error on misuse teaches faster.
19
19
 
20
- ## API
20
+ ## Use case 1: Expose capabilities to AI
21
21
 
22
- The plugin keeps an internal registry per editor. All functions take the editor as first argument.
22
+ You're a **plugin author** and want your GrapesJS commands to be discoverable by AI tools.
23
+
24
+ Listen for the `ai-capabilities:ready` event during your plugin init. No import needed — if the ai-capabilities plugin isn't loaded, the event never fires and nothing happens:
23
25
 
24
26
  ```js
25
- import plugin, {
26
- addCapability,
27
- getCapability,
28
- getAllCapabilities,
29
- removeCapability,
30
- hasCapability,
31
- PLUGIN_ID,
32
- } from '@silexlabs/grapesjs-ai-capabilities'
27
+ // In your plugin's init function
28
+ export default (editor, opts) => {
29
+ // ... your plugin setup ...
30
+
31
+ editor.on('ai-capabilities:ready', (addCapability) => {
32
+ addCapability({
33
+ id: 'css-var:set',
34
+ command: 'css-var:set',
35
+ description: 'Set CSS variable',
36
+ inputSchema: {
37
+ type: 'object',
38
+ required: ['name', 'value', 'type'],
39
+ properties: {
40
+ name: { type: 'string' },
41
+ value: { type: 'string' },
42
+ type: { type: 'string', enum: ['color', 'size', 'typo'] },
43
+ },
44
+ },
45
+ tags: ['css'],
46
+ })
47
+ })
48
+ }
33
49
  ```
34
50
 
35
- ### addCapability(editor, def, options?)
51
+ Keep descriptions short. Put the detail in `inputSchema` and in your command's error messages.
52
+
53
+ ## Use case 2: Implement an MCP server (or other AI integration)
54
+
55
+ You're a **builder** and want to expose GrapesJS capabilities as MCP tools, API endpoints, or chat actions.
36
56
 
37
- Register a capability. Returns `{ ok, capability?, error?, warnings? }`.
57
+ Import the query functions to read the registry and map capabilities to your integration:
38
58
 
39
59
  ```js
40
- addCapability(editor, {
41
- id: 'css-var:set',
42
- command: 'css-var:set',
43
- description: 'Set CSS variable',
44
- inputSchema: {
45
- type: 'object',
46
- required: ['name', 'value', 'type'],
47
- properties: {
48
- name: { type: 'string' },
49
- value: { type: 'string' },
50
- type: { type: 'string', enum: ['color', 'size', 'typo'] },
51
- },
52
- },
53
- tags: ['css'],
54
- })
60
+ import { getAllCapabilities } from '@silexlabs/grapesjs-ai-capabilities'
61
+
62
+ // Get all registered capabilities as MCP tool definitions
63
+ const capabilities = getAllCapabilities()
64
+
65
+ for (const cap of capabilities) {
66
+ mcpServer.addTool({
67
+ name: cap.id,
68
+ description: cap.description,
69
+ inputSchema: cap.inputSchema,
70
+ execute: (params) => editor.runCommand(cap.command, params),
71
+ })
72
+ }
55
73
  ```
56
74
 
75
+ Execution always goes through `editor.runCommand()` — this plugin does not implement `run()`.
76
+
77
+ ## API reference
78
+
79
+ The plugin keeps a single global registry. Query functions don't need the editor.
80
+
81
+ ### addCapability(def, options?)
82
+
83
+ Register a capability. Returns the capability object. Throws on validation errors.
84
+
57
85
  Pass `{ replace: true }` as third argument to overwrite an existing capability.
58
86
 
59
- ### getCapability(editor, id)
87
+ ### getCapability(id)
60
88
 
61
- Returns `{ ok, capability? }` or `{ ok: false, error }`.
89
+ Returns the capability object. Throws if not found.
62
90
 
63
- ### getAllCapabilities(editor, filter?)
91
+ ### getAllCapabilities(filter?)
64
92
 
65
- Returns `{ ok, capabilities, count }`. Optional filter: `{ tags: ['css'] }`.
93
+ Returns an array of capabilities. Optional filter: `{ tags: ['css'] }`.
66
94
 
67
- ### removeCapability(editor, id)
95
+ ### removeCapability(id)
68
96
 
69
- Returns `{ ok, removed }`. No-op if missing.
97
+ Returns `true` if removed, `false` if not found.
70
98
 
71
- ### hasCapability(editor, id)
99
+ ### hasCapability(id)
72
100
 
73
101
  Returns `true` or `false`.
74
102
 
75
- ## Usage with other plugins
103
+ ### clearCapabilities()
76
104
 
77
- On `editor.on('load')`, the plugin triggers an `ai-capabilities:ready` event with the `addCapability` function. Other plugins listen for this event to register their capabilities — no imports needed, fully decoupled:
105
+ Clears the registry. Useful for tests.
78
106
 
79
- ```js
80
- // In any plugin's init function
81
- editor.on('ai-capabilities:ready', (addCapability) => {
82
- addCapability(editor, {
83
- id: 'css-var:list',
84
- command: 'css-var:list',
85
- description: 'List CSS variables',
86
- })
87
- })
88
- ```
107
+ ### Event: `ai-capabilities:ready`
89
108
 
90
- If `grapesjs-ai-capabilities` is not loaded, the event never fires and nothing happens.
109
+ Fired on `editor.on('load')`. The callback receives the `addCapability` function.
91
110
 
92
111
  ## Install
93
112
 
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- /*! @silexlabs/grapesjs-ai-capabilities - 0.0.2 */
2
- !function(t,e){'object'==typeof exports&&'object'==typeof module?module.exports=e():'function'==typeof define&&define.amd?define([],e):'object'==typeof exports?exports["@silexlabs/grapesjs-ai-capabilities"]=e():t["@silexlabs/grapesjs-ai-capabilities"]=e()}(Object('undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:this),()=>(()=>{"use strict";var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(t,'__esModule',{value:!0})}},e={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t){var e=function(t,e){if("object"!=r(t)||!t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var n=o.call(t,e||"default");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==r(e)?e:e+""}function n(t,e,r){return(e=o(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,o)}return r}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach(function(e){n(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}t.r(e),t.d(e,{EVENT_READY:()=>f,PLUGIN_ID:()=>c,addCapability:()=>d,default:()=>b,getAllCapabilities:()=>y,getCapability:()=>m,hasCapability:()=>h,removeCapability:()=>g});const c='grapesjs-ai-capabilities',u=new WeakMap,s=['title','tags','version'];function p(t,e){try{const r=u.get(t);return r?e(r):{ok:!1,error:'Plugin not initialized on this editor'}}catch(t){return{ok:!1,error:t.message}}}function l(t){if(null===t||'object'!=typeof t)return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}const f='ai-capabilities:ready',b=t=>{u.set(t,new Map),t.on('load',()=>{t.trigger(f,d)})};function d(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return p(t,o=>{if(!e||'string'!=typeof e.id||!e.id)return{ok:!1,error:'id is required and must be a non-empty string'};if('string'!=typeof e.command||!e.command)return{ok:!1,error:'command is required and must be a non-empty string'};const n=e.description||e.prompt;if('string'!=typeof n||!n)return{ok:!1,error:'description (or prompt) is required and must be a non-empty string'};if(o.has(e.id)&&!r.replace)return{ok:!1,error:"Capability \"".concat(e.id,"\" already exists")};if(void 0!==e.tags&&!Array.isArray(e.tags))return{ok:!1,error:'tags must be an array'};if(void 0!==e.inputSchema&&!l(e.inputSchema))return{ok:!1,error:'inputSchema must be an object'};if(void 0!==e.outputSchema&&!l(e.outputSchema))return{ok:!1,error:'outputSchema must be an object'};const i=[];t.Commands.has(e.command)||(i.push("Command \"".concat(e.command,"\" not found. It may be registered later.")),console.warn("[".concat(c,"] ").concat(i[0])));const u={id:e.id,command:e.command,description:n,inputSchema:e.inputSchema||{},outputSchema:e.outputSchema||{}};for(const t of s)void 0!==e[t]&&(u[t]=e[t]);o.set(e.id,u);const p={ok:!0,capability:a({},u)};return i.length&&(p.warnings=i),p})}function m(t,e){return p(t,t=>{const r=t.get(e);return r?{ok:!0,capability:a({},r)}:{ok:!1,error:"Capability \"".concat(e,"\" not found")}})}function y(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return p(t,t=>{let r=Array.from(t.values());e.tags&&Array.isArray(e.tags)&&e.tags.length&&(r=r.filter(t=>t.tags&&e.tags.some(e=>t.tags.includes(e))));const o=r.map(t=>a({},t));return{ok:!0,capabilities:o,count:o.length}})}function g(t,e){return p(t,t=>({ok:!0,removed:t.delete(e)}))}function h(t,e){try{const r=u.get(t);return!!r&&r.has(e)}catch(t){return!1}}return e})());
1
+ /*! @silexlabs/grapesjs-ai-capabilities - 0.0.3 */
2
+ !function(t,e){'object'==typeof exports&&'object'==typeof module?module.exports=e():'function'==typeof define&&define.amd?define([],e):'object'==typeof exports?exports["@silexlabs/grapesjs-ai-capabilities"]=e():t["@silexlabs/grapesjs-ai-capabilities"]=e()}(Object('undefined'!=typeof globalThis?globalThis:'undefined'!=typeof window?window:this),()=>(()=>{"use strict";var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(t,'__esModule',{value:!0})}},e={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t){var e=function(t,e){if("object"!=r(t)||!t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var n=o.call(t,e||"default");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==r(e)?e:e+""}function n(t,e,r){return(e=o(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,o)}return r}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach(function(e){n(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}t.r(e),t.d(e,{EVENT_READY:()=>l,PLUGIN_ID:()=>c,addCapability:()=>b,clearCapabilities:()=>h,default:()=>f,getAllCapabilities:()=>d,getCapability:()=>y,hasCapability:()=>g,removeCapability:()=>m});const c='grapesjs-ai-capabilities',u=new Map,s=['title','tags','version'];function p(t){if(null===t||'object'!=typeof t)return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}const l='ai-capabilities:ready',f=t=>{t.on('load',()=>{t.trigger(l,b)})};function b(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!t||'string'!=typeof t.id||!t.id)throw new Error('id is required and must be a non-empty string');if('string'!=typeof t.command||!t.command)throw new Error('command is required and must be a non-empty string');const r=t.description||t.prompt;if('string'!=typeof r||!r)throw new Error('description (or prompt) is required and must be a non-empty string');if(u.has(t.id)&&!e.replace)throw new Error("Capability \"".concat(t.id,"\" already exists"));if(void 0!==t.tags&&!Array.isArray(t.tags))throw new Error('tags must be an array');if(void 0!==t.inputSchema&&!p(t.inputSchema))throw new Error('inputSchema must be an object');if(void 0!==t.outputSchema&&!p(t.outputSchema))throw new Error('outputSchema must be an object');const o={id:t.id,command:t.command,description:r,inputSchema:t.inputSchema||{},outputSchema:t.outputSchema||{}};for(const e of s)void 0!==t[e]&&(o[e]=t[e]);return u.set(t.id,o),a({},o)}function y(t){const e=u.get(t);if(!e)throw new Error("Capability \"".concat(t,"\" not found"));return a({},e)}function d(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=Array.from(u.values());return t.tags&&Array.isArray(t.tags)&&t.tags.length&&(e=e.filter(e=>e.tags&&t.tags.some(t=>e.tags.includes(t)))),e.map(t=>a({},t))}function m(t){return u.delete(t)}function g(t){return u.has(t)}function h(){u.clear()}return e})());
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAQ,uCAAyCD,IAEjDD,EAAK,uCAAyCC,GAC/C,CATD,CASGK,OAA6B,oBAAfC,WAA6BA,WAAgC,oBAAXC,OAAyBA,OAASC,MAAQ,I,mBCR7G,IAAIC,EAAsB,CCA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AAOjB,KAAKT,SACzD2B,EAAeA,EAAaD,OAAOI,GAC/BA,EAAErB,MAAQiB,EAAOjB,KAAKsB,KAAKnE,GAAKkE,EAAErB,KAAKuB,SAASpE,MAGxD,MAAMqE,EAASN,EAAaO,IAAIJ,GAACR,EAAA,GAAUQ,IAC3C,MAAO,CAAE/C,IAAI,EAAM4C,aAAcM,EAAQE,MAAOF,EAAOjC,SAE/D,CAEO,SAASoC,EAAiBxD,EAAQsB,GACrC,OAAOvB,EAAaC,EAASE,IAElB,CAAEC,IAAI,EAAMsD,QADHvD,EAASwD,OAAOpC,KAGxC,CAEO,SAASqC,EAAc3D,EAAQsB,GAClC,IACI,MAAMpB,EAAWN,EAAWzB,IAAI6B,GAChC,QAAOE,GAAWA,EAASwB,IAAIJ,EACnC,CAAE,MAAOsC,GACL,OAAO,CACX,CACJ,C","sources":["webpack://@silexlabs/grapesjs-ai-capabilities/webpack/universalModuleDefinition","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/bootstrap","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/runtime/define property getters","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/runtime/hasOwnProperty shorthand","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/runtime/make namespace object","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/typeof.js","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/toPropertyKey.js","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/toPrimitive.js","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@silexlabs/grapesjs-ai-capabilities/./src/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@silexlabs/grapesjs-ai-capabilities\"] = factory();\n\telse\n\t\troot[\"@silexlabs/grapesjs-ai-capabilities\"] = factory();\n})(Object(typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this)), () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, _typeof(o);\n}\nexport { _typeof as default };","import _typeof from \"./typeof.js\";\nimport toPrimitive from \"./toPrimitive.js\";\nfunction toPropertyKey(t) {\n var i = toPrimitive(t, \"string\");\n return \"symbol\" == _typeof(i) ? i : i + \"\";\n}\nexport { toPropertyKey as default };","import _typeof from \"./typeof.js\";\nfunction toPrimitive(t, r) {\n if (\"object\" != _typeof(t) || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != _typeof(i)) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n}\nexport { toPrimitive as default };","import toPropertyKey from \"./toPropertyKey.js\";\nfunction _defineProperty(e, r, t) {\n return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {\n value: t,\n enumerable: !0,\n configurable: !0,\n writable: !0\n }) : e[r] = t, e;\n}\nexport { _defineProperty as default };","export const PLUGIN_ID = 'grapesjs-ai-capabilities'\n\nconst registries = new WeakMap()\nconst OPTIONAL_FIELDS = ['title', 'tags', 'version']\n\nfunction withRegistry(editor, fn) {\n try {\n const registry = registries.get(editor)\n if (!registry) {\n return { ok: false, error: 'Plugin not initialized on this editor' }\n }\n return fn(registry)\n } catch (err) {\n return { ok: false, error: err.message }\n }\n}\n\nfunction isPlainObject(v) {\n if (v === null || typeof v !== 'object') return false\n const proto = Object.getPrototypeOf(v)\n return proto === Object.prototype || proto === null\n}\n\nexport const EVENT_READY = 'ai-capabilities:ready'\n\nexport default (editor) => {\n registries.set(editor, new Map())\n editor.on('load', () => {\n editor.trigger(EVENT_READY, addCapability)\n })\n}\n\nexport function addCapability(editor, def, options = {}) {\n return withRegistry(editor, (registry) => {\n if (!def || typeof def.id !== 'string' || !def.id) {\n return { ok: false, error: 'id is required and must be a non-empty string' }\n }\n if (typeof def.command !== 'string' || !def.command) {\n return { ok: false, error: 'command is required and must be a non-empty string' }\n }\n const description = def.description || def.prompt\n if (typeof description !== 'string' || !description) {\n return { ok: false, error: 'description (or prompt) is required and must be a non-empty string' }\n }\n if (registry.has(def.id) && !options.replace) {\n return { ok: false, error: `Capability \"${def.id}\" already exists` }\n }\n if (def.tags !== undefined && !Array.isArray(def.tags)) {\n return { ok: false, error: 'tags must be an array' }\n }\n if (def.inputSchema !== undefined && !isPlainObject(def.inputSchema)) {\n return { ok: false, error: 'inputSchema must be an object' }\n }\n if (def.outputSchema !== undefined && !isPlainObject(def.outputSchema)) {\n return { ok: false, error: 'outputSchema must be an object' }\n }\n const warnings = []\n if (!editor.Commands.has(def.command)) {\n warnings.push(`Command \"${def.command}\" not found. It may be registered later.`)\n console.warn(`[${PLUGIN_ID}] ${warnings[0]}`)\n }\n const capability = {\n id: def.id,\n command: def.command,\n description,\n inputSchema: def.inputSchema || {},\n outputSchema: def.outputSchema || {},\n }\n for (const field of OPTIONAL_FIELDS) {\n if (def[field] !== undefined) capability[field] = def[field]\n }\n registry.set(def.id, capability)\n const result = { ok: true, capability: { ...capability } }\n if (warnings.length) result.warnings = warnings\n return result\n })\n}\n\nexport function getCapability(editor, id) {\n return withRegistry(editor, (registry) => {\n const cap = registry.get(id)\n if (!cap) {\n return { ok: false, error: `Capability \"${id}\" not found` }\n }\n return { ok: true, capability: { ...cap } }\n })\n}\n\nexport function getAllCapabilities(editor, filter = {}) {\n return withRegistry(editor, (registry) => {\n let capabilities = Array.from(registry.values())\n if (filter.tags && Array.isArray(filter.tags) && filter.tags.length) {\n capabilities = capabilities.filter(c =>\n c.tags && filter.tags.some(t => c.tags.includes(t))\n )\n }\n const copies = capabilities.map(c => ({ ...c }))\n return { ok: true, capabilities: copies, count: copies.length }\n })\n}\n\nexport function removeCapability(editor, id) {\n return withRegistry(editor, (registry) => {\n const removed = registry.delete(id)\n return { ok: true, removed }\n })\n}\n\nexport function hasCapability(editor, id) {\n try {\n const registry = registries.get(editor)\n return registry ? registry.has(id) : false\n } catch (_) {\n return false\n }\n}\n"],"names":["root","factory","exports","module","define","amd","Object","globalThis","window","this","__webpack_require__","definition","key","o","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","_typeof","iterator","constructor","toPropertyKey","t","i","r","e","toPrimitive","TypeError","String","Number","_defineProperty","configurable","writable","PLUGIN_ID","registries","WeakMap","OPTIONAL_FIELDS","withRegistry","editor","fn","registry","ok","error","err","message","isPlainObject","v","proto","getPrototypeOf","EVENT_READY","set","Map","on","trigger","addCapability","def","options","arguments","length","undefined","id","command","description","prompt","has","replace","concat","tags","Array","isArray","inputSchema","outputSchema","warnings","Commands","push","console","warn","capability","field","result","_objectSpread","getCapability","cap","getAllCapabilities","filter","capabilities","from","values","c","some","includes","copies","map","count","removeCapability","removed","delete","hasCapability","_"],"sourceRoot":""}
1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AAwBF,IAApBJ,EAAIgB,cAA8BzB,EAAcS,EAAIgB,aACpD,MAAM,IAAIV,MAAM,iCAEpB,QAAyBF,IAArBJ,EAAIiB,eAA+B1B,EAAcS,EAAIiB,cACrD,MAAM,IAAIX,MAAM,kCAGpB,MAAMY,EAAa,CACfb,GAAIL,EAAIK,GACRE,QAASP,EAAIO,QACbC,cACAQ,YAAahB,EAAIgB,aAAe,CAAC,EACjCC,aAAcjB,EAAIiB,cAAgB,CAAC,GAEvC,IAAK,MAAME,KAAS7B,OACGc,IAAfJ,EAAImB,KAAsBD,EAAWC,GAASnB,EAAImB,IAG1D,OADA/B,EAASgC,IAAIpB,EAAIK,GAAIa,GACrBG,EAAA,GAAYH,EAChB,CAEO,SAASI,EAAcjB,GAC1B,MAAMkB,EAAMnC,EAASzB,IAAI0C,GACzB,IAAKkB,EACD,MAAM,IAAIjB,MAAM,gBAADM,OAAgBP,EAAE,iBAErC,OAAAgB,EAAA,GAAYE,EAChB,CAEO,SAASC,IAAgC,IAAbC,EAAMvB,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAC,EACrCwB,EAAeZ,MAAMa,KAAKvC,EAASwC,UAMvC,OALIH,EAAOZ,MAAQC,MAAMC,QAAQU,EAAOZ,OAASY,EAAOZ,KAAKV,SACzDuB,EAAeA,EAAaD,OAAOI,GAC/BA,EAAEhB,MAAQY,EAAOZ,KAAKiB,KAAKtD,GAAKqD,EAAEhB,KAAKkB,SAASvD,MAGjDkD,EAAaM,IAAIH,GAACR,EAAA,GAAUQ,GACvC,CAEO,SAASI,EAAiB5B,GAC7B,OAAOjB,EAAS8C,OAAO7B,EAC3B,CAEO,SAAS8B,EAAc9B,GAC1B,OAAOjB,EAASsB,IAAIL,EACxB,CAEO,SAAS+B,IACZhD,EAASiD,OACb,C","sources":["webpack://@silexlabs/grapesjs-ai-capabilities/webpack/universalModuleDefinition","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/bootstrap","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/runtime/define property getters","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/runtime/hasOwnProperty shorthand","webpack://@silexlabs/grapesjs-ai-capabilities/webpack/runtime/make namespace object","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/typeof.js","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/toPropertyKey.js","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/toPrimitive.js","webpack://@silexlabs/grapesjs-ai-capabilities/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@silexlabs/grapesjs-ai-capabilities/./src/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@silexlabs/grapesjs-ai-capabilities\"] = factory();\n\telse\n\t\troot[\"@silexlabs/grapesjs-ai-capabilities\"] = factory();\n})(Object(typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this)), () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, _typeof(o);\n}\nexport { _typeof as default };","import _typeof from \"./typeof.js\";\nimport toPrimitive from \"./toPrimitive.js\";\nfunction toPropertyKey(t) {\n var i = toPrimitive(t, \"string\");\n return \"symbol\" == _typeof(i) ? i : i + \"\";\n}\nexport { toPropertyKey as default };","import _typeof from \"./typeof.js\";\nfunction toPrimitive(t, r) {\n if (\"object\" != _typeof(t) || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != _typeof(i)) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n}\nexport { toPrimitive as default };","import toPropertyKey from \"./toPropertyKey.js\";\nfunction _defineProperty(e, r, t) {\n return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {\n value: t,\n enumerable: !0,\n configurable: !0,\n writable: !0\n }) : e[r] = t, e;\n}\nexport { _defineProperty as default };","export const PLUGIN_ID = 'grapesjs-ai-capabilities'\n\nconst registry = new Map()\nconst OPTIONAL_FIELDS = ['title', 'tags', 'version']\n\nfunction isPlainObject(v) {\n if (v === null || typeof v !== 'object') return false\n const proto = Object.getPrototypeOf(v)\n return proto === Object.prototype || proto === null\n}\n\nexport const EVENT_READY = 'ai-capabilities:ready'\n\nexport default (editor) => {\n editor.on('load', () => {\n editor.trigger(EVENT_READY, addCapability)\n })\n}\n\nexport function addCapability(def, options = {}) {\n if (!def || typeof def.id !== 'string' || !def.id) {\n throw new Error('id is required and must be a non-empty string')\n }\n if (typeof def.command !== 'string' || !def.command) {\n throw new Error('command is required and must be a non-empty string')\n }\n const description = def.description || def.prompt\n if (typeof description !== 'string' || !description) {\n throw new Error('description (or prompt) is required and must be a non-empty string')\n }\n if (registry.has(def.id) && !options.replace) {\n throw new Error(`Capability \"${def.id}\" already exists`)\n }\n if (def.tags !== undefined && !Array.isArray(def.tags)) {\n throw new Error('tags must be an array')\n }\n if (def.inputSchema !== undefined && !isPlainObject(def.inputSchema)) {\n throw new Error('inputSchema must be an object')\n }\n if (def.outputSchema !== undefined && !isPlainObject(def.outputSchema)) {\n throw new Error('outputSchema must be an object')\n }\n\n const capability = {\n id: def.id,\n command: def.command,\n description,\n inputSchema: def.inputSchema || {},\n outputSchema: def.outputSchema || {},\n }\n for (const field of OPTIONAL_FIELDS) {\n if (def[field] !== undefined) capability[field] = def[field]\n }\n registry.set(def.id, capability)\n return { ...capability }\n}\n\nexport function getCapability(id) {\n const cap = registry.get(id)\n if (!cap) {\n throw new Error(`Capability \"${id}\" not found`)\n }\n return { ...cap }\n}\n\nexport function getAllCapabilities(filter = {}) {\n let capabilities = Array.from(registry.values())\n if (filter.tags && Array.isArray(filter.tags) && filter.tags.length) {\n capabilities = capabilities.filter(c =>\n c.tags && filter.tags.some(t => c.tags.includes(t))\n )\n }\n return capabilities.map(c => ({ ...c }))\n}\n\nexport function removeCapability(id) {\n return registry.delete(id)\n}\n\nexport function hasCapability(id) {\n return registry.has(id)\n}\n\nexport function clearCapabilities() {\n registry.clear()\n}\n"],"names":["root","factory","exports","module","define","amd","Object","globalThis","window","this","__webpack_require__","definition","key","o","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","_typeof","iterator","constructor","toPropertyKey","t","i","r","e","toPrimitive","TypeError","String","Number","_defineProperty","configurable","writable","PLUGIN_ID","registry","Map","OPTIONAL_FIELDS","isPlainObject","v","proto","getPrototypeOf","EVENT_READY","editor","on","trigger","addCapability","def","options","arguments","length","undefined","id","Error","command","description","prompt","has","replace","concat","tags","Array","isArray","inputSchema","outputSchema","capability","field","set","_objectSpread","getCapability","cap","getAllCapabilities","filter","capabilities","from","values","c","some","includes","map","removeCapability","delete","hasCapability","clearCapabilities","clear"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silexlabs/grapesjs-ai-capabilities",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Discovery and metadata layer for GrapesJS commands, enabling MCP tool exposure and external integrations",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.js CHANGED
@@ -1,20 +1,8 @@
1
1
  export const PLUGIN_ID = 'grapesjs-ai-capabilities'
2
2
 
3
- const registries = new WeakMap()
3
+ const registry = new Map()
4
4
  const OPTIONAL_FIELDS = ['title', 'tags', 'version']
5
5
 
6
- function withRegistry(editor, fn) {
7
- try {
8
- const registry = registries.get(editor)
9
- if (!registry) {
10
- return { ok: false, error: 'Plugin not initialized on this editor' }
11
- }
12
- return fn(registry)
13
- } catch (err) {
14
- return { ok: false, error: err.message }
15
- }
16
- }
17
-
18
6
  function isPlainObject(v) {
19
7
  if (v === null || typeof v !== 'object') return false
20
8
  const proto = Object.getPrototypeOf(v)
@@ -24,93 +12,75 @@ function isPlainObject(v) {
24
12
  export const EVENT_READY = 'ai-capabilities:ready'
25
13
 
26
14
  export default (editor) => {
27
- registries.set(editor, new Map())
28
15
  editor.on('load', () => {
29
16
  editor.trigger(EVENT_READY, addCapability)
30
17
  })
31
18
  }
32
19
 
33
- export function addCapability(editor, def, options = {}) {
34
- return withRegistry(editor, (registry) => {
35
- if (!def || typeof def.id !== 'string' || !def.id) {
36
- return { ok: false, error: 'id is required and must be a non-empty string' }
37
- }
38
- if (typeof def.command !== 'string' || !def.command) {
39
- return { ok: false, error: 'command is required and must be a non-empty string' }
40
- }
41
- const description = def.description || def.prompt
42
- if (typeof description !== 'string' || !description) {
43
- return { ok: false, error: 'description (or prompt) is required and must be a non-empty string' }
44
- }
45
- if (registry.has(def.id) && !options.replace) {
46
- return { ok: false, error: `Capability "${def.id}" already exists` }
47
- }
48
- if (def.tags !== undefined && !Array.isArray(def.tags)) {
49
- return { ok: false, error: 'tags must be an array' }
50
- }
51
- if (def.inputSchema !== undefined && !isPlainObject(def.inputSchema)) {
52
- return { ok: false, error: 'inputSchema must be an object' }
53
- }
54
- if (def.outputSchema !== undefined && !isPlainObject(def.outputSchema)) {
55
- return { ok: false, error: 'outputSchema must be an object' }
56
- }
57
- const warnings = []
58
- if (!editor.Commands.has(def.command)) {
59
- warnings.push(`Command "${def.command}" not found. It may be registered later.`)
60
- console.warn(`[${PLUGIN_ID}] ${warnings[0]}`)
61
- }
62
- const capability = {
63
- id: def.id,
64
- command: def.command,
65
- description,
66
- inputSchema: def.inputSchema || {},
67
- outputSchema: def.outputSchema || {},
68
- }
69
- for (const field of OPTIONAL_FIELDS) {
70
- if (def[field] !== undefined) capability[field] = def[field]
71
- }
72
- registry.set(def.id, capability)
73
- const result = { ok: true, capability: { ...capability } }
74
- if (warnings.length) result.warnings = warnings
75
- return result
76
- })
20
+ export function addCapability(def, options = {}) {
21
+ if (!def || typeof def.id !== 'string' || !def.id) {
22
+ throw new Error('id is required and must be a non-empty string')
23
+ }
24
+ if (typeof def.command !== 'string' || !def.command) {
25
+ throw new Error('command is required and must be a non-empty string')
26
+ }
27
+ const description = def.description || def.prompt
28
+ if (typeof description !== 'string' || !description) {
29
+ throw new Error('description (or prompt) is required and must be a non-empty string')
30
+ }
31
+ if (registry.has(def.id) && !options.replace) {
32
+ throw new Error(`Capability "${def.id}" already exists`)
33
+ }
34
+ if (def.tags !== undefined && !Array.isArray(def.tags)) {
35
+ throw new Error('tags must be an array')
36
+ }
37
+ if (def.inputSchema !== undefined && !isPlainObject(def.inputSchema)) {
38
+ throw new Error('inputSchema must be an object')
39
+ }
40
+ if (def.outputSchema !== undefined && !isPlainObject(def.outputSchema)) {
41
+ throw new Error('outputSchema must be an object')
42
+ }
43
+
44
+ const capability = {
45
+ id: def.id,
46
+ command: def.command,
47
+ description,
48
+ inputSchema: def.inputSchema || {},
49
+ outputSchema: def.outputSchema || {},
50
+ }
51
+ for (const field of OPTIONAL_FIELDS) {
52
+ if (def[field] !== undefined) capability[field] = def[field]
53
+ }
54
+ registry.set(def.id, capability)
55
+ return { ...capability }
77
56
  }
78
57
 
79
- export function getCapability(editor, id) {
80
- return withRegistry(editor, (registry) => {
81
- const cap = registry.get(id)
82
- if (!cap) {
83
- return { ok: false, error: `Capability "${id}" not found` }
84
- }
85
- return { ok: true, capability: { ...cap } }
86
- })
58
+ export function getCapability(id) {
59
+ const cap = registry.get(id)
60
+ if (!cap) {
61
+ throw new Error(`Capability "${id}" not found`)
62
+ }
63
+ return { ...cap }
87
64
  }
88
65
 
89
- export function getAllCapabilities(editor, filter = {}) {
90
- return withRegistry(editor, (registry) => {
91
- let capabilities = Array.from(registry.values())
92
- if (filter.tags && Array.isArray(filter.tags) && filter.tags.length) {
93
- capabilities = capabilities.filter(c =>
94
- c.tags && filter.tags.some(t => c.tags.includes(t))
95
- )
96
- }
97
- const copies = capabilities.map(c => ({ ...c }))
98
- return { ok: true, capabilities: copies, count: copies.length }
99
- })
66
+ export function getAllCapabilities(filter = {}) {
67
+ let capabilities = Array.from(registry.values())
68
+ if (filter.tags && Array.isArray(filter.tags) && filter.tags.length) {
69
+ capabilities = capabilities.filter(c =>
70
+ c.tags && filter.tags.some(t => c.tags.includes(t))
71
+ )
72
+ }
73
+ return capabilities.map(c => ({ ...c }))
100
74
  }
101
75
 
102
- export function removeCapability(editor, id) {
103
- return withRegistry(editor, (registry) => {
104
- const removed = registry.delete(id)
105
- return { ok: true, removed }
106
- })
76
+ export function removeCapability(id) {
77
+ return registry.delete(id)
107
78
  }
108
79
 
109
- export function hasCapability(editor, id) {
110
- try {
111
- const registry = registries.get(editor)
112
- return registry ? registry.has(id) : false
113
- } catch (_) {
114
- return false
115
- }
80
+ export function hasCapability(id) {
81
+ return registry.has(id)
82
+ }
83
+
84
+ export function clearCapabilities() {
85
+ registry.clear()
116
86
  }