@moises.ai/extension 1.0.1 → 1.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 CHANGED
@@ -1 +1,19 @@
1
- # Moises Extensions SDK
1
+ # Moises AI | Extensions SDK
2
+
3
+ Create powerful extensions for the Moises AI Studio.
4
+
5
+ ## Documentation
6
+
7
+ 📖 **[Full Documentation](https://extensions.moises.ai/)** - Complete API reference, guides, and examples
8
+
9
+ ## Quick Start
10
+
11
+ The best way to get started is to bootstrap a new extension project:
12
+
13
+ ```bash
14
+ npm create @moises.ai/extension <my-extension>
15
+ ```
16
+
17
+ This will create a new extension project with all the necessary files and dependencies to begin development.
18
+
19
+ For detailed setup instructions and API reference, visit our [documentation](https://extensions.moises.ai/).
@@ -12,29 +12,29 @@ class h {
12
12
  this.connected = !1;
13
13
  }
14
14
  handleMessage(e) {
15
- const { data: s, source: t, origin: n } = e;
16
- if (t === this.target) {
15
+ const { data: s, source: n, origin: t } = e;
16
+ if (n === this.target) {
17
17
  if (s.type === "response") {
18
- const { requestId: r, result: d, error: o } = s, c = this.pendingRequests.get(r);
19
- c && (o ? c.reject(new Error(o)) : c.resolve(d), this.pendingRequests.delete(r));
18
+ const { requestId: r, result: c, error: o } = s, d = this.pendingRequests.get(r);
19
+ d && (o ? d.reject(new Error(o)) : d.resolve(c), this.pendingRequests.delete(r));
20
20
  return;
21
21
  }
22
22
  if (s.type === "request") {
23
- const { method: r, params: d, requestId: o } = s, c = this.handlers.get(r);
24
- if (!c) {
25
- this.sendResponse(t, o, null, `No handler for method: ${r}`);
23
+ const { method: r, params: c, requestId: o } = s, d = this.handlers.get(r);
24
+ if (!d) {
25
+ this.sendResponse(n, o, null, `No handler for method: ${r}`);
26
26
  return;
27
27
  }
28
- Promise.resolve().then(() => c(d)).then((a) => this.sendResponse(t, o, a)).catch((a) => this.sendResponse(t, o, null, a.message));
28
+ Promise.resolve().then(() => d(c)).then((a) => this.sendResponse(n, o, a)).catch((a) => this.sendResponse(n, o, null, a.message));
29
29
  }
30
30
  }
31
31
  }
32
- sendResponse(e, s, t, n = null) {
32
+ sendResponse(e, s, n, t = null) {
33
33
  e.postMessage({
34
34
  type: "response",
35
35
  requestId: s,
36
- result: t,
37
- error: n
36
+ result: n,
37
+ error: t
38
38
  }, "*");
39
39
  }
40
40
  on(e, s) {
@@ -44,17 +44,17 @@ class h {
44
44
  this.handlers.delete(e);
45
45
  }
46
46
  once(e, s) {
47
- const t = async (n) => (this.off(e), s(n));
48
- this.on(e, t);
47
+ const n = async (t) => (this.off(e), s(t));
48
+ this.on(e, n);
49
49
  }
50
50
  async call(e, s) {
51
- const t = this.requestId++;
52
- return new Promise((n, r) => {
53
- this.pendingRequests.set(t, { resolve: n, reject: r }), this.target.postMessage({
51
+ const n = this.requestId++;
52
+ return new Promise((t, r) => {
53
+ this.pendingRequests.set(n, { resolve: t, reject: r }), this.target.postMessage({
54
54
  type: "request",
55
55
  method: e,
56
56
  params: s,
57
- requestId: t
57
+ requestId: n
58
58
  }, "*");
59
59
  });
60
60
  }
@@ -66,9 +66,12 @@ class u {
66
66
  createProxy() {
67
67
  return new Proxy(this.rpc, {
68
68
  get: (e, s) => s in e ? e[s] : new Proxy({}, {
69
- get: (t, n) => async (r) => {
70
- const d = `${s}.${n}`;
71
- return e.call(d, r);
69
+ get: (n, t) => s === "link" ? async (r, c) => {
70
+ const o = await e.call("register.link", { category: t, options: r });
71
+ this.rpc.on(`${o.id}`, c);
72
+ } : async (r) => {
73
+ const c = `${s}.${t}`;
74
+ return e.call(c, r);
72
75
  }
73
76
  })
74
77
  });
@@ -88,19 +91,13 @@ function l(i) {
88
91
  version: i.version,
89
92
  isLoaded: !1,
90
93
  events: {}
91
- }, { proxy: s, rpc: t } = new u({
94
+ }, { proxy: s, rpc: n } = new u({
92
95
  target: window.parent
93
- }), n = (
94
- /** @type {any} */
95
- s
96
- );
97
- return n.link = async (r, d, o) => {
98
- const c = await n.register.link({ category: r, options: d });
99
- t.on(`${c.id}`, o);
100
- }, n.connect = async function() {
101
- const r = n.register.extension(e);
102
- return e.isLoaded = !0, r;
103
- }, n.plugin = e, n;
96
+ });
97
+ return s.connect = async function() {
98
+ const t = s.register.extension(e);
99
+ return e.isLoaded = !0, t;
100
+ }, s.plugin = e, s;
104
101
  }
105
102
  export {
106
103
  l as M,
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import { M as e } from "./client-Bt6Snfq-.js";
1
+ import { M as e } from "./client-BuA0RRm3.js";
2
2
  export {
3
3
  e as MoisesExtension
4
4
  };
package/dist/index.js CHANGED
@@ -1,45 +1,47 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import { useState as x, useEffect as g } from "react";
3
- import { M as y, R as M } from "./client-Bt6Snfq-.js";
4
- function $(i) {
1
+ import { jsx as l, jsxs as b } from "react/jsx-runtime";
2
+ import { useState as C, useEffect as g } from "react";
3
+ import { M as k, R as M } from "./client-BuA0RRm3.js";
4
+ import { Box as m, HeaderPanel as h } from "@moises.ai/design-system";
5
+ import { Cross1Icon as S } from "@moises.ai/design-system/icons";
6
+ function P(i) {
5
7
  i.id;
6
- let t = null, o = !1;
8
+ let t = null, s = !1;
7
9
  function r() {
8
- const [c, u] = x({
10
+ const [c, o] = C({
9
11
  plugin: null,
10
- isConnected: o,
12
+ isConnected: s,
11
13
  moises: null
12
14
  });
13
15
  g(() => {
14
- t || (t = y(i), u((n) => ({
16
+ t || (t = k(i), o((n) => ({
15
17
  ...n,
16
18
  plugin: t.plugin,
17
19
  moises: t
18
20
  // The entire pluginInstance IS the moises API
19
21
  })));
20
22
  }, [i]), g(() => {
21
- t && !o && t.connect().then(() => {
22
- o = !0, u((n) => ({
23
+ t && !s && t.connect().then(() => {
24
+ s = !0, o((n) => ({
23
25
  ...n,
24
26
  isConnected: !0
25
27
  }));
26
28
  });
27
29
  }, []);
28
- function d({ children: n, width: l, height: a }) {
30
+ function p({ children: n, width: a, height: d }) {
29
31
  const { moises: e } = c;
30
32
  return g(() => {
31
- e && e.ui.setPluginSize({ width: l, height: a });
32
- }, [l, a, e]), /* @__PURE__ */ m("div", { height: "100vh", style: { height: "100vh", backgroundColor: "var(--gray-1)" }, children: /* @__PURE__ */ m("div", { p: "4", children: n }) });
33
+ e && e.ui.setPluginSize({ width: a, height: d });
34
+ }, [a, d, e]), /* @__PURE__ */ l("div", { height: "100vh", style: { height: "100vh", backgroundColor: "var(--gray-1)" }, children: /* @__PURE__ */ l("div", { p: "4", children: n }) });
33
35
  }
34
36
  return {
35
37
  ...c,
36
- ModalLayout: d
38
+ ModalLayout: p
37
39
  };
38
40
  }
39
41
  return r;
40
42
  }
41
- function j({ id: i, url: t, exposedAPI: o, iframeRef: r, onRegisterMetadata: c, onRegisterLink: u }) {
42
- const d = {
43
+ function I({ id: i, url: t, exposedAPI: s, iframeRef: r, onRegisterMetadata: c, onRegisterLink: o }) {
44
+ const p = {
43
45
  id: i,
44
46
  url: t
45
47
  };
@@ -49,24 +51,84 @@ function j({ id: i, url: t, exposedAPI: o, iframeRef: r, onRegisterMetadata: c,
49
51
  });
50
52
  n.on("register.extension", async (e) => {
51
53
  c(e);
52
- }), n.on("register.link", async ({ category: e, options: s }) => {
53
- const f = `link:${e}:${s.label}`;
54
- return u({ id: f, category: e, options: s }), { id: f };
54
+ }), n.on("register.link", async ({ category: e, options: u }) => {
55
+ const f = `link:${e}:${u.label}`;
56
+ return o({ id: f, category: e, options: u }), { id: f };
55
57
  });
56
- for (const [e, s] of Object.entries(o))
57
- for (const [f, p] of Object.entries(s)) {
58
- const h = `${e}.${f}`;
59
- n.on(h, async (v) => await p(v));
58
+ for (const [e, u] of Object.entries(s))
59
+ for (const [f, x] of Object.entries(u)) {
60
+ const v = `${e}.${f}`;
61
+ n.on(v, async (y) => await x(y));
60
62
  }
61
- function l(e, s) {
62
- return n.call(e, s);
63
+ function a(e, u) {
64
+ return n.call(e, u);
63
65
  }
64
- function a() {
66
+ function d() {
65
67
  n.disconnect();
66
68
  }
67
- return { plugin: d, rpc: n, call: l, disconnect: a };
69
+ return { plugin: p, rpc: n, call: a, disconnect: d };
70
+ }
71
+ function B({
72
+ children: i,
73
+ init: t = {},
74
+ title: s = "Sidebar Menu",
75
+ width: r = "300px",
76
+ height: c = "600px"
77
+ }) {
78
+ const { moises: o } = P(t);
79
+ return g(() => {
80
+ o && o.ui.setPluginSize({ width: r, height: c });
81
+ }, [r, c, o]), /* @__PURE__ */ b(
82
+ m,
83
+ {
84
+ height: "100vh",
85
+ style: {
86
+ height: "100vh",
87
+ backgroundColor: "var(--gray-1)",
88
+ display: "flex",
89
+ flexDirection: "column",
90
+ overflow: "hidden"
91
+ },
92
+ children: [
93
+ /* @__PURE__ */ l(
94
+ m,
95
+ {
96
+ p: "4",
97
+ style: {
98
+ position: "sticky",
99
+ top: 0,
100
+ zIndex: 10,
101
+ backgroundColor: "var(--neutral-2)"
102
+ },
103
+ children: /* @__PURE__ */ l(h, { title: s, children: /* @__PURE__ */ l(
104
+ h.Button,
105
+ {
106
+ onClick: () => {
107
+ o.ui.close();
108
+ },
109
+ children: /* @__PURE__ */ l(S, {})
110
+ }
111
+ ) })
112
+ }
113
+ ),
114
+ /* @__PURE__ */ l(
115
+ m,
116
+ {
117
+ px: "4",
118
+ style: {
119
+ flex: 1,
120
+ overflowY: "auto",
121
+ backgroundColor: "var(--neutral-2)"
122
+ },
123
+ children: i
124
+ }
125
+ )
126
+ ]
127
+ }
128
+ );
68
129
  }
69
130
  export {
70
- j as MoisesExtensionHost,
71
- $ as initMoisesExtension
131
+ I as MoisesExtensionHost,
132
+ B as SidebarMenu,
133
+ P as initMoisesExtension
72
134
  };
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@moises.ai/extension",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "SDK for Moises AI extensions",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.js",
9
- "bin": {
10
- "moises-extension": "./scripts/init-boilerplate.js"
11
- },
12
9
  "exports": {
13
10
  ".": {
14
11
  "import": "./dist/index.js",
@@ -26,8 +23,7 @@
26
23
  "dist",
27
24
  "styles.css",
28
25
  "src/client.d.ts",
29
- "src/index.d.ts",
30
- "scripts/init-boilerplate.js"
26
+ "src/index.d.ts"
31
27
  ],
32
28
  "scripts": {
33
29
  "build": "vite build",
@@ -51,7 +47,8 @@
51
47
  "@vitejs/plugin-react": "^4.2.1",
52
48
  "react": "^19.0.0",
53
49
  "react-dom": "^19.0.0",
54
- "vite": "^5.1.0"
50
+ "vite": "^5.1.0",
51
+ "@moises.ai/design-system": "^2.0.33"
55
52
  },
56
53
  "publishConfig": {
57
54
  "access": "public"
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env node
2
- import { promisify } from "util";
3
- import cp from "child_process";
4
- import path from "path";
5
- import fs from "fs";
6
-
7
- // convert libs to promises
8
- const exec = promisify(cp.exec);
9
- const rm = promisify(fs.rm);
10
-
11
- // Simple custom spinner implementation
12
- class Spinner {
13
- constructor(message) {
14
- this.message = message;
15
- this.frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
16
- this.currentFrame = 0;
17
- this.isSpinning = false;
18
- this.interval = null;
19
- }
20
-
21
- start() {
22
- this.isSpinning = true;
23
- process.stdout.write('\x1B[?25l'); // Hide cursor
24
- this.interval = setInterval(() => {
25
- process.stdout.write('\r' + this.frames[this.currentFrame] + ' ' + this.message);
26
- this.currentFrame = (this.currentFrame + 1) % this.frames.length;
27
- }, 100);
28
- return this;
29
- }
30
-
31
- succeed(successMessage) {
32
- this.stop();
33
- process.stdout.write('\r✅ ' + (successMessage || this.message) + '\n');
34
- }
35
-
36
- fail(errorMessage) {
37
- this.stop();
38
- process.stdout.write('\r❌ ' + (errorMessage || this.message) + '\n');
39
- }
40
-
41
- stop() {
42
- if (this.interval) {
43
- clearInterval(this.interval);
44
- this.interval = null;
45
- }
46
- this.isSpinning = false;
47
- process.stdout.write('\x1B[?25h'); // Show cursor
48
- process.stdout.write('\r' + ' '.repeat(this.message.length + 10) + '\r');
49
- }
50
- }
51
-
52
- if (process.argv.length < 3) {
53
- console.log("You have to provide a name for your extension project.");
54
- console.log("For example:");
55
- console.log(" npx @moises.ai/extension my-extension");
56
- process.exit(1);
57
- }
58
-
59
- // Display ASCII banner
60
- console.log(`
61
- _ _
62
- (_) (_)
63
- _ __ ___ ___ _ ___ ___ ___ __ _ _
64
- | '_ \` _ \\ / _ \\| / __|/ _ \\/ __| / _\` | |
65
- | | | | | | (_) | \\__ \\ __/\\__ \\| (_| | |
66
- |_| |_| |_|\\___/|_|___/\\___||___(_)__,_|_|
67
-
68
- `);
69
-
70
- const projectName = process.argv[2];
71
- const currentPath = process.cwd();
72
- const projectPath = path.join(currentPath, projectName);
73
- const git_repo = "https://github.com/moises-ai/extensions-boilerplate.git";
74
-
75
- // create project directory
76
- if (fs.existsSync(projectPath)) {
77
- console.log(`The directory ${projectName} already exists in the current directory, please give it another name.`);
78
- process.exit(1);
79
- } else {
80
- fs.mkdirSync(projectPath);
81
- }
82
-
83
- try {
84
- const gitSpinner = new Spinner("Downloading boilerplate files...").start();
85
- // clone the repo into the project folder -> creates the new boilerplate
86
- await exec(`git clone --depth 1 ${git_repo} ${projectPath} --quiet`);
87
- gitSpinner.succeed();
88
-
89
- const cleanSpinner = new Spinner("Cleaning up template files...").start();
90
- // remove git history to start fresh
91
- const rmGit = rm(path.join(projectPath, ".git"), { recursive: true, force: true });
92
- await rmGit;
93
- cleanSpinner.succeed();
94
-
95
- // change to project directory for npm operations
96
- process.chdir(projectPath);
97
-
98
- const npmSpinner = new Spinner("Installing dependencies...").start();
99
- await exec("npm install");
100
- npmSpinner.succeed();
101
-
102
- console.log("\n🎉 Extension project created successfully!");
103
- console.log("\nNext steps:");
104
- console.log(` cd ${projectName}`);
105
- console.log(` npm run dev`);
106
- console.log("\nHappy coding! 🚀");
107
-
108
- } catch (error) {
109
- // clean up in case of error, so the user does not have to do it manually
110
- fs.rmSync(projectPath, { recursive: true, force: true });
111
- console.error("❌ Error creating extension project:");
112
- console.error(error.message);
113
- process.exit(1);
114
- }