@silexlabs/grapesjs-ai-capabilities 0.0.1 → 0.0.2
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 +10 -10
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +5 -0
package/README.md
CHANGED
|
@@ -74,21 +74,21 @@ Returns `true` or `false`.
|
|
|
74
74
|
|
|
75
75
|
## Usage with other plugins
|
|
76
76
|
|
|
77
|
-
|
|
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:
|
|
78
78
|
|
|
79
79
|
```js
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
})
|
|
88
|
-
}
|
|
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
|
+
})
|
|
89
87
|
})
|
|
90
88
|
```
|
|
91
89
|
|
|
90
|
+
If `grapesjs-ai-capabilities` is not loaded, the event never fires and nothing happens.
|
|
91
|
+
|
|
92
92
|
## Install
|
|
93
93
|
|
|
94
94
|
```
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! @silexlabs/grapesjs-ai-capabilities - 0.
|
|
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,{PLUGIN_ID:()=>c,addCapability:()=>
|
|
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=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B,OAAKsB,EAGE,CAAEtC,IAAI,EAAMiC,WAAUG,EAAA,GAAOE,IAFzB,CAAEtC,IAAI,EAAOC,MAAO,gBAAFqB,OAAiBN,EAAE,kBAIxD,CAEO,SAASuB,EAAmB1C,GAAqB,IAAb2C,EAAM3B,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAC,EACjD,OAAOjB,EAAaC,EAASE,IACzB,IAAI0C,EAAejB,MAAMkB,KAAK3C,EAAS4C,UACnCH,EAAOjB,MAAQC,MAAMC,QAAQe,EAAOjB,OAASiB,EAAOjB,KAAKT,SACzD2B,EAAeA,EAAaD,OAAOI,GAC/BA,EAAErB,MAAQiB,EAAOjB,KAAKsB,KAAKhE,GAAK+D,EAAErB,KAAKuB,SAASjE,MAGxD,MAAMkE,EAASN,EAAaO,IAAIJ,GAACR,EAAA,GAAUQ,IAC3C,MAAO,CAAE5C,IAAI,EAAMyC,aAAcM,EAAQE,MAAOF,EAAOjC,SAE/D,CAEO,SAASoC,EAAiBrD,EAAQmB,GACrC,OAAOpB,EAAaC,EAASE,IAElB,CAAEC,IAAI,EAAMmD,QADHpD,EAASqD,OAAOpC,KAGxC,CAEO,SAASqC,EAAcxD,EAAQmB,GAClC,IACI,MAAMjB,EAAWN,EAAWzB,IAAI6B,GAChC,QAAOE,GAAWA,EAASqB,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 default (editor) => {\n registries.set(editor, new Map())\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","set","Map","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
|
+
{"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,CCA1BA,EAAwB,CAACR,EAASS,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAEX,EAASU,IAC5EN,OAAOQ,eAAeZ,EAASU,EAAK,CAAEG,YAAY,EAAMC,IAAKL,EAAWC,MCJ3EF,EAAwB,CAACO,EAAKC,IAAUZ,OAAOa,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFR,EAAyBR,IACH,oBAAXoB,QAA0BA,OAAOC,aAC1CjB,OAAOQ,eAAeZ,EAASoB,OAAOC,YAAa,CAAEC,MAAO,WAE7DlB,OAAOQ,eAAeZ,EAAS,aAAc,CAAEsB,OAAO,M,KCLvD,SAASC,EAAQZ,GAGf,OAAOY,EAAU,mBAAqBH,QAAU,iBAAmBA,OAAOI,SAAW,SAAUb,GAC7F,cAAcA,CAChB,EAAI,SAAUA,GACZ,OAAOA,GAAK,mBAAqBS,QAAUT,EAAEc,cAAgBL,QAAUT,IAAMS,OAAOH,UAAY,gBAAkBN,CACpH,EAAG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K,EAAIK,GAAIiB,GACrB,MAAME,EAAS,CAAEtC,IAAI,EAAMoC,WAAUG,EAAA,GAAOH,IAE5C,OADIL,EAASd,SAAQqB,EAAOP,SAAWA,GAChCO,GAEf,CAEO,SAASE,EAAc3C,EAAQsB,GAClC,OAAOvB,EAAaC,EAASE,IACzB,MAAM0C,EAAM1C,EAAS/B,IAAImD,GACzB,OAAKsB,EAGE,CAAEzC,IAAI,EAAMoC,WAAUG,EAAA,GAAOE,IAFzB,CAAEzC,IAAI,EAAOC,MAAO,gBAAFwB,OAAiBN,EAAE,kBAIxD,CAEO,SAASuB,EAAmB7C,GAAqB,IAAb8C,EAAM3B,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAC,EACjD,OAAOpB,EAAaC,EAASE,IACzB,IAAI6C,EAAejB,MAAMkB,KAAK9C,EAAS+C,UACnCH,EAAOjB,MAAQC,MAAMC,QAAQe,EAAOjB,OAASiB,EAAOjB,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":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silexlabs/grapesjs-ai-capabilities",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
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
|
@@ -21,8 +21,13 @@ function isPlainObject(v) {
|
|
|
21
21
|
return proto === Object.prototype || proto === null
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export const EVENT_READY = 'ai-capabilities:ready'
|
|
25
|
+
|
|
24
26
|
export default (editor) => {
|
|
25
27
|
registries.set(editor, new Map())
|
|
28
|
+
editor.on('load', () => {
|
|
29
|
+
editor.trigger(EVENT_READY, addCapability)
|
|
30
|
+
})
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export function addCapability(editor, def, options = {}) {
|