@elizaos/plugin-suno 0.1.9

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,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,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "./src",
6
+ "typeRoots": ["./node_modules/@types", "./src/types"],
7
+ "declaration": true,
8
+ "strictNullChecks": true
9
+ },
10
+ "include": ["src/**/*.ts"]
11
+ }
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
+ });