@elizaos/plugin-suno 1.0.5 → 1.0.6-alpha.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.
@@ -0,0 +1,156 @@
1
+ import type { Action, IAgentRuntime, Memory, State, HandlerCallback } from "@elizaos/core";
2
+ import { SunoProvider } from "../providers/suno";
3
+ import type { CustomGenerateParams } from "../types";
4
+
5
+ const customGenerateMusic: Action = {
6
+ name: "custom-generate-music",
7
+ description: "Generate music with custom parameters using Suno AI",
8
+ similes: [
9
+ "CREATE_CUSTOM_MUSIC",
10
+ "GENERATE_CUSTOM_AUDIO",
11
+ "MAKE_CUSTOM_MUSIC",
12
+ "COMPOSE_CUSTOM_MUSIC",
13
+ "COMPOSE_MUSIC",
14
+ "CREATE_MUSIC",
15
+ "GENERATE_MUSIC"
16
+
17
+ ],
18
+
19
+ validate: async (runtime: IAgentRuntime, _message: Memory) => {
20
+ return !!runtime.getSetting("SUNO_API_KEY");
21
+ },
22
+
23
+ handler: async (
24
+ runtime: IAgentRuntime,
25
+ message: Memory,
26
+ state: State,
27
+ _options: { [key: string]: unknown },
28
+ callback?: HandlerCallback
29
+ ): Promise<boolean> => {
30
+ try {
31
+ const provider = await SunoProvider.get(runtime, message, state);
32
+ const content = message.content as unknown as CustomGenerateParams;
33
+
34
+ if (!content.prompt) {
35
+ throw new Error("Missing required parameter: prompt");
36
+ }
37
+
38
+ const response = await provider.request('/custom-generate', {
39
+ method: 'POST',
40
+ body: JSON.stringify({
41
+ prompt: content.prompt,
42
+ duration: content.duration || 30,
43
+ temperature: content.temperature || 1.0,
44
+ top_k: content.topK || 250,
45
+ top_p: content.topP || 0.95,
46
+ classifier_free_guidance: content.classifier_free_guidance || 3.0,
47
+ reference_audio: content.reference_audio,
48
+ style: content.style,
49
+ bpm: content.bpm,
50
+ key: content.key,
51
+ mode: content.mode
52
+ })
53
+ });
54
+
55
+ if (callback) {
56
+ callback({
57
+ text: 'Successfully generated custom music',
58
+ content: response
59
+ });
60
+ }
61
+
62
+ return true;
63
+ } catch (error) {
64
+ if (callback) {
65
+ callback({
66
+ text: `Failed to generate custom music: ${(error as Error).message}`,
67
+ error: error
68
+ });
69
+ }
70
+ return false;
71
+ }
72
+ },
73
+
74
+ examples: [
75
+ [
76
+ {
77
+ user: "{{user1}}",
78
+ content: {
79
+ text: "Create an upbeat electronic dance track with heavy bass",
80
+ prompt: "An upbeat electronic dance track with heavy bass and energetic synths",
81
+ duration: 60,
82
+ style: "electronic",
83
+ bpm: 128
84
+ }
85
+ },
86
+ {
87
+ user: "{{agent}}",
88
+ content: {
89
+ text: "I'll generate an energetic EDM track for you.",
90
+ action: "custom-generate-music"
91
+ }
92
+ },
93
+ {
94
+ user: "{{agent}}",
95
+ content: {
96
+ text: "Successfully generated your EDM track with heavy bass and synths."
97
+ }
98
+ }
99
+ ],
100
+ [
101
+ {
102
+ user: "{{user1}}",
103
+ content: {
104
+ text: "Generate a calm piano melody in C major",
105
+ prompt: "A gentle, flowing piano melody with soft dynamics",
106
+ duration: 45,
107
+ style: "classical",
108
+ key: "C",
109
+ mode: "major",
110
+ temperature: 0.8
111
+ }
112
+ },
113
+ {
114
+ user: "{{agent}}",
115
+ content: {
116
+ text: "I'll create a calming piano piece in C major for you.",
117
+ action: "custom-generate-music"
118
+ }
119
+ },
120
+ {
121
+ user: "{{agent}}",
122
+ content: {
123
+ text: "Successfully generated your peaceful piano melody in C major."
124
+ }
125
+ }
126
+ ],
127
+ [
128
+ {
129
+ user: "{{user1}}",
130
+ content: {
131
+ text: "Make a rock song with guitar solos",
132
+ prompt: "A rock song with powerful electric guitar solos and driving drums",
133
+ duration: 90,
134
+ style: "rock",
135
+ bpm: 120,
136
+ classifier_free_guidance: 4.0
137
+ }
138
+ },
139
+ {
140
+ user: "{{agent}}",
141
+ content: {
142
+ text: "I'll generate a rock track with guitar solos for you.",
143
+ action: "custom-generate-music"
144
+ }
145
+ },
146
+ {
147
+ user: "{{agent}}",
148
+ content: {
149
+ text: "Successfully generated your rock song with guitar solos."
150
+ }
151
+ }
152
+ ]
153
+ ]
154
+ };
155
+
156
+ export default customGenerateMusic;
@@ -0,0 +1,134 @@
1
+ import type { Action, IAgentRuntime, Memory, State, HandlerCallback } from "@elizaos/core";
2
+ import { SunoProvider } from "../providers/suno";
3
+ import type { ExtendParams } from "../types";
4
+
5
+ const extendAudio: Action = {
6
+ name: "extend-audio",
7
+ description: "Extend the duration of an existing audio generation",
8
+ similes: [
9
+ "LENGTHEN_AUDIO",
10
+ "PROLONG_AUDIO",
11
+ "INCREASE_DURATION",
12
+ "MAKE_AUDIO_LONGER"
13
+ ],
14
+
15
+ validate: async (runtime: IAgentRuntime, _message: Memory) => {
16
+ return !!runtime.getSetting("SUNO_API_KEY");
17
+ },
18
+
19
+ handler: async (
20
+ runtime: IAgentRuntime,
21
+ message: Memory,
22
+ state: State,
23
+ _options: { [key: string]: unknown },
24
+ callback?: HandlerCallback
25
+ ): Promise<boolean> => {
26
+ try {
27
+ const provider = await SunoProvider.get(runtime, message, state);
28
+ const content = message.content as unknown as ExtendParams;
29
+
30
+ if (!content.audio_id || !content.duration) {
31
+ throw new Error("Missing required parameters: audio_id and duration");
32
+ }
33
+
34
+ const response = await provider.request('/extend', {
35
+ method: 'POST',
36
+ body: JSON.stringify({
37
+ audio_id: content.audio_id,
38
+ duration: content.duration
39
+ })
40
+ });
41
+
42
+ if (callback) {
43
+ callback({
44
+ text: `Successfully extended audio ${content.audio_id}`,
45
+ content: response
46
+ });
47
+ }
48
+
49
+ return true;
50
+ } catch (error) {
51
+ if (callback) {
52
+ callback({
53
+ text: `Failed to extend audio: ${(error as Error).message}`,
54
+ error: error
55
+ });
56
+ }
57
+ return false;
58
+ }
59
+ },
60
+
61
+ examples: [
62
+ [
63
+ {
64
+ user: "{{user1}}",
65
+ content: {
66
+ text: "Make this song longer by 30 seconds",
67
+ audio_id: "abc123",
68
+ duration: 30
69
+ }
70
+ },
71
+ {
72
+ user: "{{agent}}",
73
+ content: {
74
+ text: "I'll extend your song by 30 seconds.",
75
+ action: "extend-audio"
76
+ }
77
+ },
78
+ {
79
+ user: "{{agent}}",
80
+ content: {
81
+ text: "Successfully extended your song by 30 seconds."
82
+ }
83
+ }
84
+ ],
85
+ [
86
+ {
87
+ user: "{{user1}}",
88
+ content: {
89
+ text: "Double the length of this track",
90
+ audio_id: "xyz789",
91
+ duration: 60
92
+ }
93
+ },
94
+ {
95
+ user: "{{agent}}",
96
+ content: {
97
+ text: "I'll double the duration of your track.",
98
+ action: "extend-audio"
99
+ }
100
+ },
101
+ {
102
+ user: "{{agent}}",
103
+ content: {
104
+ text: "Successfully doubled the length of your track to 60 seconds."
105
+ }
106
+ }
107
+ ],
108
+ [
109
+ {
110
+ user: "{{user1}}",
111
+ content: {
112
+ text: "Add 15 more seconds to this melody",
113
+ audio_id: "def456",
114
+ duration: 15
115
+ }
116
+ },
117
+ {
118
+ user: "{{agent}}",
119
+ content: {
120
+ text: "I'll add 15 seconds to your melody.",
121
+ action: "extend-audio"
122
+ }
123
+ },
124
+ {
125
+ user: "{{agent}}",
126
+ content: {
127
+ text: "Successfully added 15 seconds to your melody."
128
+ }
129
+ }
130
+ ]
131
+ ]
132
+ };
133
+
134
+ export default extendAudio;
@@ -0,0 +1,145 @@
1
+ import type { Action, IAgentRuntime, Memory, State, HandlerCallback } from "@elizaos/core";
2
+ import { SunoProvider } from "../providers/suno";
3
+ import type { GenerateParams } from "../types";
4
+
5
+ const generateMusic: Action = {
6
+ name: "generate-music",
7
+ description: "Generate music using Suno AI",
8
+ similes: [
9
+ "CREATE_MUSIC",
10
+ "MAKE_MUSIC",
11
+ "COMPOSE_MUSIC",
12
+ "GENERATE_AUDIO",
13
+ "CREATE_SONG",
14
+ "MAKE_SONG"
15
+ ],
16
+
17
+ validate: async (runtime: IAgentRuntime, _message: Memory) => {
18
+ return !!runtime.getSetting("SUNO_API_KEY");
19
+ },
20
+
21
+ handler: async (
22
+ runtime: IAgentRuntime,
23
+ message: Memory,
24
+ state: State,
25
+ _options: { [key: string]: unknown },
26
+ callback?: HandlerCallback
27
+ ): Promise<boolean> => {
28
+ try {
29
+ const provider = await SunoProvider.get(runtime, message, state);
30
+ const content = message.content as unknown as GenerateParams;
31
+
32
+ if (!content.prompt) {
33
+ throw new Error("Missing required parameter: prompt");
34
+ }
35
+
36
+ const response = await provider.request('/generate', {
37
+ method: 'POST',
38
+ body: JSON.stringify({
39
+ prompt: content.prompt,
40
+ duration: content.duration || 30,
41
+ temperature: content.temperature || 1.0,
42
+ top_k: content.topK || 250,
43
+ top_p: content.topP || 0.95,
44
+ classifier_free_guidance: content.classifier_free_guidance || 3.0
45
+ })
46
+ });
47
+
48
+ if (callback) {
49
+ callback({
50
+ text: 'Successfully generated music based on your prompt',
51
+ content: response
52
+ });
53
+ }
54
+
55
+ return true;
56
+ } catch (error) {
57
+ if (callback) {
58
+ callback({
59
+ text: `Failed to extend audio: ${(error as Error).message}`,
60
+ error: error
61
+ });
62
+ }
63
+ return false;
64
+ }
65
+ },
66
+
67
+ examples: [
68
+ [
69
+ {
70
+ user: "{{user1}}",
71
+ content: {
72
+ text: "Create a happy and energetic song",
73
+ prompt: "A cheerful and energetic melody with upbeat rhythm",
74
+ duration: 30,
75
+ temperature: 1.0
76
+ }
77
+ },
78
+ {
79
+ user: "{{agent}}",
80
+ content: {
81
+ text: "I'll generate a happy and energetic song for you.",
82
+ action: "generate-music"
83
+ }
84
+ },
85
+ {
86
+ user: "{{agent}}",
87
+ content: {
88
+ text: "Successfully generated your upbeat and energetic song."
89
+ }
90
+ }
91
+ ],
92
+ [
93
+ {
94
+ user: "{{user1}}",
95
+ content: {
96
+ text: "Generate a relaxing ambient track",
97
+ prompt: "A peaceful ambient soundscape with gentle waves and soft pads",
98
+ duration: 45,
99
+ temperature: 0.8,
100
+ classifier_free_guidance: 4.0
101
+ }
102
+ },
103
+ {
104
+ user: "{{agent}}",
105
+ content: {
106
+ text: "I'll create a calming ambient piece for you.",
107
+ action: "generate-music"
108
+ }
109
+ },
110
+ {
111
+ user: "{{agent}}",
112
+ content: {
113
+ text: "Successfully generated your relaxing ambient soundscape."
114
+ }
115
+ }
116
+ ],
117
+ [
118
+ {
119
+ user: "{{user1}}",
120
+ content: {
121
+ text: "Make a short jingle for my podcast",
122
+ prompt: "A catchy and professional podcast intro jingle",
123
+ duration: 15,
124
+ temperature: 1.2,
125
+ top_k: 300
126
+ }
127
+ },
128
+ {
129
+ user: "{{agent}}",
130
+ content: {
131
+ text: "I'll generate a podcast jingle for you.",
132
+ action: "generate-music"
133
+ }
134
+ },
135
+ {
136
+ user: "{{agent}}",
137
+ content: {
138
+ text: "Successfully generated your podcast jingle."
139
+ }
140
+ }
141
+ ]
142
+ ]
143
+ };
144
+
145
+ export default generateMusic;
package/src/index.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from "@elizaos/core";
2
+ import generateMusic from "./actions/generate";
3
+ import customGenerateMusic from "./actions/customGenerate";
4
+ import extendAudio from "./actions/extend";
5
+ import { SunoProvider } from "./providers/suno";
6
+
7
+ export {
8
+ SunoProvider,
9
+ generateMusic as GenerateMusic,
10
+ customGenerateMusic as CustomGenerateMusic,
11
+ extendAudio as ExtendAudio
12
+ };
13
+
14
+ export const sunoPlugin: Plugin = {
15
+ name: "suno",
16
+ description: "Suno AI Music Generation Plugin for Eliza",
17
+ actions: [generateMusic, customGenerateMusic, extendAudio],
18
+ evaluators: [],
19
+ providers: [SunoProvider],
20
+ };
21
+
22
+ export default sunoPlugin;
@@ -0,0 +1,78 @@
1
+ import type { IAgentRuntime, Memory, State } from "@elizaos/core"; // Added type keyword
2
+ import type { Provider } from "@elizaos/core"; // Added type keyword
3
+
4
+ export interface SunoConfig {
5
+ apiKey: string;
6
+ baseUrl?: string;
7
+ }
8
+
9
+ export class SunoProvider implements Provider {
10
+ private apiKey: string;
11
+ private baseUrl: string;
12
+
13
+ static async get(runtime: IAgentRuntime, _message: Memory, _state?: State): Promise<SunoProvider> {
14
+ const apiKey = runtime.getSetting("SUNO_API_KEY");
15
+ if (!apiKey) {
16
+ throw new Error("SUNO_API_KEY is required");
17
+ }
18
+ return new SunoProvider({ apiKey });
19
+ }
20
+
21
+ constructor(config: SunoConfig) {
22
+ this.apiKey = config.apiKey;
23
+ this.baseUrl = config.baseUrl || 'https://api.suno.ai/v1';
24
+ }
25
+
26
+ async get(_runtime: IAgentRuntime, _message: Memory, _state?: State): Promise<{ status: string }> {
27
+ return { status: 'ready' };
28
+ }
29
+
30
+ async request(endpoint: string, options: RequestInit = {}) {
31
+ const url = `${this.baseUrl}${endpoint}`;
32
+ const headers = {
33
+ 'Authorization': `Bearer ${this.apiKey}`,
34
+ 'Content-Type': 'application/json',
35
+ ...options.headers,
36
+ };
37
+
38
+ const response = await fetch(url, {
39
+ ...options,
40
+ headers,
41
+ });
42
+
43
+ if (!response.ok) {
44
+ throw new Error(`Suno API error: ${response.statusText}`);
45
+ }
46
+
47
+ return response.json();
48
+ }
49
+ }
50
+
51
+ export interface GenerateParams {
52
+ prompt: string;
53
+ duration?: number;
54
+ temperature?: number;
55
+ topK?: number;
56
+ topP?: number;
57
+ classifier_free_guidance?: number;
58
+ }
59
+
60
+ export interface CustomGenerateParams extends GenerateParams {
61
+ reference_audio?: string;
62
+ style?: string;
63
+ bpm?: number;
64
+ key?: string;
65
+ mode?: string;
66
+ }
67
+
68
+ export interface ExtendParams {
69
+ audio_id: string;
70
+ duration: number;
71
+ }
72
+
73
+ export interface GenerationResponse {
74
+ id: string;
75
+ status: 'pending' | 'processing' | 'completed' | 'failed';
76
+ audio_url?: string;
77
+ error?: string;
78
+ }
@@ -0,0 +1,34 @@
1
+ export interface GenerateParams {
2
+ prompt: string;
3
+ duration?: number;
4
+ temperature?: number;
5
+ topK?: number;
6
+ topP?: number;
7
+ classifier_free_guidance?: number;
8
+ }
9
+
10
+ export interface CustomGenerateParams {
11
+ prompt: string;
12
+ duration?: number;
13
+ temperature?: number;
14
+ topK?: number;
15
+ topP?: number;
16
+ classifier_free_guidance?: number;
17
+ reference_audio?: string;
18
+ style?: string;
19
+ bpm?: number;
20
+ key?: string;
21
+ mode?: string;
22
+ }
23
+
24
+ export interface ExtendParams {
25
+ audio_id: string;
26
+ duration: number;
27
+ }
28
+
29
+ export interface GenerationResponse {
30
+ id: string;
31
+ status: string;
32
+ url?: string;
33
+ error?: string;
34
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "rootDir": "src",
5
+ "lib": ["ESNext", "dom"],
6
+ "module": "Preserve",
7
+ "moduleResolution": "Bundler",
8
+ "strict": false,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": false,
12
+ "allowImportingTsExtensions": true,
13
+ "declaration": true,
14
+ "emitDeclarationOnly": true,
15
+ "resolveJsonModule": true,
16
+ "noImplicitAny": false,
17
+ "allowJs": true,
18
+ "checkJs": false,
19
+ "noEmitOnError": false,
20
+ "moduleDetection": "force",
21
+ "allowArbitraryExtensions": true
22
+ },
23
+ "include": ["src/**/*.ts"]
24
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts"],
5
+ format: ["cjs", "esm"],
6
+ dts: true,
7
+ splitting: false,
8
+ sourcemap: true,
9
+ clean: true,
10
+ external: ["@elizaos/core"]
11
+ });
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 ElizaOS
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.