@moises.ai/extension 0.0.20 → 1.0.1

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,34 +1 @@
1
- # Moises Extensions SDK
2
-
3
- ```jsx
4
- "use client"
5
-
6
- import { useEffect } from "react";
7
- import { initMoisesExtension, Button } from "@moises.ai/extension";
8
-
9
- const useMoisesExtension = initMoisesExtension({
10
- id: "your-extension-id",
11
- name: "Sample extension",
12
- description: "A bit about this extension",
13
- version: "1.0.0",
14
- author: "Moises Systems Incs",
15
- });
16
-
17
- export default function Home() {
18
- const { moises, ModalLayout, isConnected } = useMoisesExtension();
19
-
20
- useEffect(() => {
21
- if (!moises) {
22
- return
23
- }
24
-
25
- moises.link("footer:menu", { label: "Audio Editor" }, async () => {
26
- moises.ui.open({ mountPoint: "bottomPanel" });
27
- })
28
- }, [moises]);
29
-
30
- return (
31
- <Button onClick={() => moises.ui.alert({ title: "Hello", message: "World" })}>Click me</Button>
32
- );
33
- }
34
- ```
1
+ # Moises Extensions SDK
@@ -0,0 +1,108 @@
1
+ class h {
2
+ constructor({ target: e }) {
3
+ this.target = e, this.handlers = /* @__PURE__ */ new Map(), this.pendingRequests = /* @__PURE__ */ new Map(), this.requestId = 0, this.connected = !1, this.boundHandler = this.handleMessage.bind(this), this.connect();
4
+ }
5
+ connect() {
6
+ window.addEventListener("message", this.boundHandler), this.connected = !0;
7
+ }
8
+ disconnect() {
9
+ window.removeEventListener("message", this.boundHandler);
10
+ for (const [e, { reject: s }] of this.pendingRequests.entries())
11
+ s(new Error("Connection closed")), this.pendingRequests.delete(e);
12
+ this.connected = !1;
13
+ }
14
+ handleMessage(e) {
15
+ const { data: s, source: t, origin: n } = e;
16
+ if (t === this.target) {
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));
20
+ return;
21
+ }
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}`);
26
+ return;
27
+ }
28
+ Promise.resolve().then(() => c(d)).then((a) => this.sendResponse(t, o, a)).catch((a) => this.sendResponse(t, o, null, a.message));
29
+ }
30
+ }
31
+ }
32
+ sendResponse(e, s, t, n = null) {
33
+ e.postMessage({
34
+ type: "response",
35
+ requestId: s,
36
+ result: t,
37
+ error: n
38
+ }, "*");
39
+ }
40
+ on(e, s) {
41
+ this.handlers.set(e, s);
42
+ }
43
+ off(e) {
44
+ this.handlers.delete(e);
45
+ }
46
+ once(e, s) {
47
+ const t = async (n) => (this.off(e), s(n));
48
+ this.on(e, t);
49
+ }
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({
54
+ type: "request",
55
+ method: e,
56
+ params: s,
57
+ requestId: t
58
+ }, "*");
59
+ });
60
+ }
61
+ }
62
+ class u {
63
+ constructor(e) {
64
+ this.rpc = new h(e), this.proxy = this.createProxy();
65
+ }
66
+ createProxy() {
67
+ return new Proxy(this.rpc, {
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);
72
+ }
73
+ })
74
+ });
75
+ }
76
+ // Proxy the on method to maintain the same interface
77
+ // on(method, handler) {
78
+ // return this.rpc.on(method, handler);
79
+ // }
80
+ }
81
+ function l(i) {
82
+ const e = {
83
+ id: i.id,
84
+ name: i.name,
85
+ description: i.description,
86
+ icon: i.icon,
87
+ author: i.author,
88
+ version: i.version,
89
+ isLoaded: !1,
90
+ events: {}
91
+ }, { proxy: s, rpc: t } = new u({
92
+ 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;
104
+ }
105
+ export {
106
+ l as M,
107
+ h as R
108
+ };
package/dist/client.js ADDED
@@ -0,0 +1,4 @@
1
+ import { M as e } from "./client-Bt6Snfq-.js";
2
+ export {
3
+ e as MoisesExtension
4
+ };
@@ -0,0 +1,450 @@
1
+
2
+ /** Controlling common UI elements */
3
+ export interface UiApi {
4
+
5
+ /** Displays a progress bar or loading indicator */
6
+ progress: (options: {
7
+
8
+ /** Progress title */
9
+ title?: string;
10
+
11
+ /** Progress value (0-100) */
12
+ value?: number;
13
+ }) => Promise<void>;
14
+
15
+ /** Displays an alert to the user */
16
+ alert: (options: {
17
+
18
+ /** Alert title */
19
+ title?: string;
20
+
21
+ /** Alert description */
22
+ description?: string;
23
+
24
+ /** Alert CTA label */
25
+ ctaLabel?: string;
26
+
27
+ /** Alert CTA color */
28
+ ctaColor?: string;
29
+ }) => Promise<void>;
30
+
31
+ /** Displays a confirmation dialog */
32
+ confirm: (options: {
33
+
34
+ /** Confirmation title */
35
+ title: string;
36
+
37
+ /** Confirmation description */
38
+ description: string;
39
+
40
+ /** Confirmation CTA label */
41
+ ctaLabel?: string;
42
+
43
+ /** Confirmation CTA color */
44
+ ctaColor?: string;
45
+ }) => Promise<boolean>;
46
+
47
+ /** Displays a text input dialog */
48
+ prompt: (options: {
49
+
50
+ /** Prompt title */
51
+ title: string;
52
+
53
+ /** Prompt description */
54
+ description: string;
55
+
56
+ /** Prompt label */
57
+ label?: string;
58
+
59
+ /** Prompt default value */
60
+ defaultValue?: string;
61
+
62
+ /** Prompt CTA label */
63
+ ctaLabel?: string;
64
+
65
+ /** Prompt CTA color */
66
+ ctaColor?: string;
67
+ }) => Promise<string>;
68
+
69
+ /** Creates a panel in the interface */
70
+ panel: (options: {
71
+
72
+ /** Panel title */
73
+ title: string;
74
+
75
+ /** Panel content */
76
+ content?: string;
77
+ }) => Promise<any>;
78
+
79
+ /** Closes the extension */
80
+ close: () => Promise<void>;
81
+
82
+ /** Opens the extension */
83
+ open: (params: {
84
+
85
+ /** Location where the extension will be mounted */
86
+ mountPoint: string;
87
+ }) => Promise<void>;
88
+ }
89
+
90
+
91
+ /** Session API for managing audio sessions, tracks, and playback controls */
92
+ export interface SessionApi {
93
+
94
+ /** Exports the audio from the current session */
95
+ export: () => Promise<any>;
96
+
97
+ /** Gets the list of tracks from the session */
98
+ tracks: () => Promise<any[]>;
99
+
100
+ /** Starts session playback */
101
+ play: () => void;
102
+
103
+ /** Pauses session playback */
104
+ pause: () => void;
105
+
106
+ /** Toggles between play and pause */
107
+ togglePlayback: () => void;
108
+
109
+ /** Clears the current selection in the session */
110
+ clearSelection: () => void;
111
+
112
+ /** Sets a selection in the session */
113
+ setSelection: (params: {
114
+
115
+ /** ID of the track to be selected */
116
+ trackId?: string;
117
+
118
+ /** Start position of the selection */
119
+ start: number;
120
+
121
+ /** End position of the selection */
122
+ end: number;
123
+ }) => void;
124
+ }
125
+
126
+
127
+ /** Track API for managing audio tracks */
128
+ export interface TrackApi {
129
+
130
+ /** Gets a track by its ID */
131
+ get: (trackId: string) => Promise<any>;
132
+
133
+ /** Creates a new track */
134
+ create: (params: {
135
+
136
+ /** The ID of the group to add the track to */
137
+ groupId: string;
138
+
139
+ /** The audio data for the track */
140
+ arrayBuffer: any;
141
+
142
+ /** The name of the track */
143
+ name: string;
144
+
145
+ /** The start position of the track in seconds */
146
+ startPositionSec: number;
147
+ }) => Promise<any>;
148
+
149
+ /** Updates a track */
150
+ update: (params: {
151
+
152
+ /** The ID of the track to update */
153
+ trackId: string;
154
+
155
+ /** The audio data for the track */
156
+ arrayBuffer: any;
157
+
158
+ /** Additional options for the track */
159
+ options?: any;
160
+ }) => Promise<any>;
161
+
162
+ /** Deletes a track */
163
+ delete: (trackId: string) => Promise<any>;
164
+ }
165
+
166
+
167
+ /** Group API for managing audio groups */
168
+ export interface GroupApi {
169
+
170
+ /** Creates a new group */
171
+ create: (params: {
172
+
173
+ /** The name of the group */
174
+ name: string;
175
+
176
+ /** The ID of the group */
177
+ id: string;
178
+
179
+ /** The type of the group */
180
+ type: string;
181
+
182
+ /** The order of the group */
183
+ order: number;
184
+
185
+ /** Whether the group is solo */
186
+ solo: boolean;
187
+
188
+ /** Whether the group is muted */
189
+ muted: boolean;
190
+
191
+ /** The pan of the group */
192
+ pan: number;
193
+
194
+ /** The volume of the group */
195
+ volume: number;
196
+
197
+ /** Additional options for the group */
198
+ options: any;
199
+ }) => Promise<any>;
200
+
201
+ /** Updates a group */
202
+ update: (params: {
203
+
204
+ /** The ID of the group to update */
205
+ groupId: string;
206
+
207
+ /** The name of the group */
208
+ name: string;
209
+
210
+ /** The type of the group */
211
+ type: string;
212
+
213
+ /** The order of the group */
214
+ order: number;
215
+
216
+ /** Whether the group is solo */
217
+ solo: boolean;
218
+
219
+ /** Whether the group is muted */
220
+ muted: boolean;
221
+
222
+ /** The pan of the group */
223
+ pan: number;
224
+
225
+ /** The volume of the group */
226
+ volume: number;
227
+ }) => Promise<any>;
228
+ }
229
+
230
+
231
+ /** Storage API for managing audio files */
232
+ export interface StorageApi {
233
+
234
+ /** Uploads a buffer to the storage */
235
+ upload: (params: {
236
+
237
+ /** The audio data to upload */
238
+ buffer: any;
239
+ }) => Promise<any>;
240
+
241
+ /** Downloads an audio file from the storage */
242
+ download: (params: {
243
+
244
+ /** The URL of the audio file to download */
245
+ url: string;
246
+ }) => Promise<any>;
247
+ }
248
+
249
+
250
+ /** Compute API for managing audio computations */
251
+ export interface ComputeApi {
252
+
253
+ /** Generates a session player */
254
+ sessionPlayerGenerate: (params: {
255
+
256
+ /** The context audio for the session player */
257
+ contextAudio: any;
258
+
259
+ /** The conditioning audio for the session player */
260
+ conditioningAudio: any;
261
+
262
+ /** The conditioning text for the session player */
263
+ conditioningText: string;
264
+
265
+ /** The number of steps for the session player */
266
+ steps: number;
267
+
268
+ /** The guidance scale for the session player */
269
+ guidanceScale: number;
270
+
271
+ /** The weight schedule for the session player */
272
+ weightSchedule: number;
273
+
274
+ /** The instrument for the session player */
275
+ instrument: string;
276
+
277
+ /** The preset ID for the session player */
278
+ presetId: string;
279
+
280
+ /** Whether to use chroma for the session player */
281
+ chroma: boolean;
282
+
283
+ /** The timestamps for the session player */
284
+ inpaintingTimestamps: any[];
285
+
286
+ /** The target for the session player */
287
+ inpaintingTarget: any[];
288
+ }) => Promise<void>;
289
+
290
+ /** Gets the list of session player presets */
291
+ sessionPlayerPresets: () => Promise<void>;
292
+
293
+ /** Inpaints an audio file */
294
+ sessionPlayerInpaint: (params: {
295
+
296
+ /** The input audio data */
297
+ input: any;
298
+
299
+ /** The mask for the inpainting */
300
+ mask: any;
301
+ }) => Promise<void>;
302
+
303
+ /** Runs a workflow */
304
+ workflow: (params: {
305
+
306
+ /** The ID of the workflow to run */
307
+ workflowId: string;
308
+
309
+ /** The parameters for the workflow TODO: add type */
310
+ params: any;
311
+ }) => Promise<void>;
312
+
313
+ /** Runs an automix job */
314
+ automix: (params: {
315
+
316
+ /** The ID of the workflow to run TODO: add type */
317
+ workflowId: string;
318
+
319
+ /** The parameters for the workflow TODO: add type */
320
+ params: any;
321
+ }) => Promise<void>;
322
+
323
+ /** Detects instruments in an audio file */
324
+ instruments: (params: {
325
+
326
+ /** The input audio data */
327
+ input: string;
328
+ }) => Promise<void>;
329
+
330
+ /** Detects chords in an audio file */
331
+ chords: (params: {
332
+
333
+ /** The input audio data */
334
+ input: string;
335
+ }) => Promise<void>;
336
+
337
+ /** Detects beats in an audio file */
338
+ beats: (params: {
339
+
340
+ /** The input audio data */
341
+ input: string;
342
+ }) => Promise<void>;
343
+
344
+ /** Detects sections in an audio file */
345
+ sections: (params: {
346
+
347
+ /** The input audio data */
348
+ input: string;
349
+ }) => Promise<void>;
350
+
351
+ /** Detects lyrics in an audio file */
352
+ lyrics: (params: {
353
+
354
+ /** The input audio data */
355
+ input: string;
356
+ }) => Promise<void>;
357
+
358
+ /** Extracts stems from an audio file */
359
+ stems: (params: {
360
+
361
+ /** The input audio data */
362
+ input: string;
363
+
364
+ /** The stems to extract */
365
+ stemsToExtract: any[];
366
+ }) => void;
367
+ }
368
+
369
+
370
+ /** Registration methods for extensions */
371
+ export interface RegisterApi {
372
+
373
+ /** Register the extension with the parent application */
374
+ extension: (plugin: any) => any;
375
+
376
+ /** Register a link connection for data streaming */
377
+ link: (options: any) => any;
378
+ }
379
+
380
+
381
+ export interface MoisesAPI {
382
+ /** Controlling common UI elements */
383
+ ui: UiApi;
384
+ /** Session API for managing audio sessions, tracks, and playback controls */
385
+ session: SessionApi;
386
+ /** Track API for managing audio tracks */
387
+ track: TrackApi;
388
+ /** Group API for managing audio groups */
389
+ group: GroupApi;
390
+ /** Storage API for managing audio files */
391
+ storage: StorageApi;
392
+ /** Compute API for managing audio computations */
393
+ compute: ComputeApi;
394
+ /** Registration methods for extensions */
395
+ register: RegisterApi;
396
+
397
+ /** Custom link method for easy connection setup (convenience wrapper around register.link) */
398
+ link: (category: string, options: any, cb: (data: any) => void) => Promise<void>;
399
+
400
+ /** Function to connect the extension to the parent application */
401
+ connect: () => Promise<any>;
402
+ /** Plugin metadata and configuration */
403
+ plugin: any;
404
+ }
405
+
406
+
407
+ export interface ExtensionInstance {
408
+ /** Function to connect the extension to the parent application */
409
+ connect: () => Promise<any>;
410
+ /** Plugin metadata and configuration */
411
+ plugin: any;
412
+ /** API to control Moises */
413
+ api: MoisesAPI;
414
+ }
415
+
416
+ export interface MoisesHook {
417
+ /** The complete Moises API with all functionality */
418
+ moises: MoisesAPI;
419
+ /** Plugin instance information */
420
+ plugin: any;
421
+ /** Connection status */
422
+ isConnected: boolean;
423
+ /** Modal layout component for plugin UI */
424
+ ModalLayout: (props: { children: any; width?: number; height?: number; }) => any;
425
+ }
426
+
427
+ export interface ExtensionOptions {
428
+ /** Unique identifier for the extension */
429
+ id: string;
430
+ /** Display name of the extension */
431
+ name: string;
432
+ /** Description of what the extension does */
433
+ description: string;
434
+ /** Icon to represent the extension */
435
+ icon: string;
436
+ /** Author of the extension */
437
+ author?: string;
438
+ /** Version number of the extension */
439
+ version?: string;
440
+ }
441
+
442
+ /**
443
+ * Creates a new Moises Extension instance (internal client)
444
+ */
445
+ export function MoisesExtension(options: ExtensionOptions): MoisesAPI;
446
+
447
+ /**
448
+ * Initializes a Moises extension hook for React components
449
+ */
450
+ export function initMoisesExtension(options: ExtensionOptions): () => MoisesHook;