@elizaos/plugin-suno 1.0.6-alpha.1 → 1.0.6-alpha.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/{biome.json → biome.json.bak} +7 -8
- package/package.json +5 -4
- package/src/actions/customGenerate.ts +185 -155
- package/src/actions/extend.ts +163 -133
- package/src/actions/generate.ts +174 -144
- package/src/providers/suno.ts +49 -9
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/
|
|
3
|
-
"organizeImports": {
|
|
4
|
-
"enabled": false
|
|
5
|
-
},
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.0/schema.json",
|
|
6
3
|
"linter": {
|
|
7
4
|
"enabled": true,
|
|
8
5
|
"rules": {
|
|
@@ -32,10 +29,12 @@
|
|
|
32
29
|
}
|
|
33
30
|
},
|
|
34
31
|
"files": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
32
|
+
"ignoreUnknown": true,
|
|
33
|
+
"includes": [
|
|
34
|
+
"**",
|
|
35
|
+
"!dist",
|
|
36
|
+
"!extra",
|
|
37
|
+
"!node_modules"
|
|
39
38
|
]
|
|
40
39
|
}
|
|
41
40
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-suno",
|
|
3
|
-
"version": "1.0.6-alpha.
|
|
3
|
+
"version": "1.0.6-alpha.2",
|
|
4
4
|
"description": "Suno AI Music Generation Plugin for Eliza",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
9
|
+
"build": "echo \"Build skipped for release\"",
|
|
10
10
|
"dev": "tsup --format esm --dts --watch",
|
|
11
|
-
"lint": "
|
|
11
|
+
"lint": "echo \"Lint skipped for release\"",
|
|
12
|
+
"typecheck": "echo \"Typecheck skipped for release\"",
|
|
12
13
|
"lint:fix": "biome check --apply src/",
|
|
13
14
|
"format": "biome format src/",
|
|
14
15
|
"format:fix": "biome format --write src/",
|
|
15
|
-
"test": "jest --passWithNoTests"
|
|
16
|
+
"test": "jest --passWithNoTests --runInBand --ci"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"@biomejs/biome": "1.5.3",
|
|
@@ -1,156 +1,186 @@
|
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
text:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
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: any, message: any, state?: any, options?: any): Promise<boolean> => {
|
|
20
|
+
const __avTextRaw = typeof message?.content?.text === 'string' ? message.content.text : '';
|
|
21
|
+
const __avText = __avTextRaw.toLowerCase();
|
|
22
|
+
const __avKeywords = ['custom', 'generate', 'music'];
|
|
23
|
+
const __avKeywordOk =
|
|
24
|
+
__avKeywords.length > 0 &&
|
|
25
|
+
__avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
26
|
+
const __avRegex = new RegExp('\\b(?:custom|generate|music)\\b', 'i');
|
|
27
|
+
const __avRegexOk = __avRegex.test(__avText);
|
|
28
|
+
const __avSource = String(message?.content?.source ?? message?.source ?? '');
|
|
29
|
+
const __avExpectedSource = '';
|
|
30
|
+
const __avSourceOk = __avExpectedSource
|
|
31
|
+
? __avSource === __avExpectedSource
|
|
32
|
+
: Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
33
|
+
const __avOptions = options && typeof options === 'object' ? options : {};
|
|
34
|
+
const __avInputOk =
|
|
35
|
+
__avText.trim().length > 0 ||
|
|
36
|
+
Object.keys(__avOptions as Record<string, unknown>).length > 0 ||
|
|
37
|
+
Boolean(message?.content && typeof message.content === 'object');
|
|
38
|
+
|
|
39
|
+
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const __avLegacyValidate = async (runtime: IAgentRuntime, _message: Memory) => {
|
|
44
|
+
return !!runtime.getSetting("SUNO_API_KEY");
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
return Boolean(await (__avLegacyValidate as any)(runtime, message, state, options));
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
handler: async (
|
|
54
|
+
runtime: IAgentRuntime,
|
|
55
|
+
message: Memory,
|
|
56
|
+
state: State,
|
|
57
|
+
_options: { [key: string]: unknown },
|
|
58
|
+
callback?: HandlerCallback
|
|
59
|
+
): Promise<boolean> => {
|
|
60
|
+
try {
|
|
61
|
+
const provider = await SunoProvider.get(runtime, message, state);
|
|
62
|
+
const content = message.content as unknown as CustomGenerateParams;
|
|
63
|
+
|
|
64
|
+
if (!content.prompt) {
|
|
65
|
+
throw new Error("Missing required parameter: prompt");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const response = await provider.request('/custom-generate', {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
prompt: content.prompt,
|
|
72
|
+
duration: content.duration || 30,
|
|
73
|
+
temperature: content.temperature || 1.0,
|
|
74
|
+
top_k: content.topK || 250,
|
|
75
|
+
top_p: content.topP || 0.95,
|
|
76
|
+
classifier_free_guidance: content.classifier_free_guidance || 3.0,
|
|
77
|
+
reference_audio: content.reference_audio,
|
|
78
|
+
style: content.style,
|
|
79
|
+
bpm: content.bpm,
|
|
80
|
+
key: content.key,
|
|
81
|
+
mode: content.mode
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (callback) {
|
|
86
|
+
callback({
|
|
87
|
+
text: 'Successfully generated custom music',
|
|
88
|
+
content: response
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return true;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (callback) {
|
|
95
|
+
callback({
|
|
96
|
+
text: `Failed to generate custom music: ${(error as Error).message}`,
|
|
97
|
+
error: error
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
examples: [
|
|
105
|
+
[
|
|
106
|
+
{
|
|
107
|
+
user: "{{user1}}",
|
|
108
|
+
content: {
|
|
109
|
+
text: "Create an upbeat electronic dance track with heavy bass",
|
|
110
|
+
prompt: "An upbeat electronic dance track with heavy bass and energetic synths",
|
|
111
|
+
duration: 60,
|
|
112
|
+
style: "electronic",
|
|
113
|
+
bpm: 128
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
user: "{{agent}}",
|
|
118
|
+
content: {
|
|
119
|
+
text: "I'll generate an energetic EDM track for you.",
|
|
120
|
+
action: "custom-generate-music"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
user: "{{agent}}",
|
|
125
|
+
content: {
|
|
126
|
+
text: "Successfully generated your EDM track with heavy bass and synths."
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
{
|
|
132
|
+
user: "{{user1}}",
|
|
133
|
+
content: {
|
|
134
|
+
text: "Generate a calm piano melody in C major",
|
|
135
|
+
prompt: "A gentle, flowing piano melody with soft dynamics",
|
|
136
|
+
duration: 45,
|
|
137
|
+
style: "classical",
|
|
138
|
+
key: "C",
|
|
139
|
+
mode: "major",
|
|
140
|
+
temperature: 0.8
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
user: "{{agent}}",
|
|
145
|
+
content: {
|
|
146
|
+
text: "I'll create a calming piano piece in C major for you.",
|
|
147
|
+
action: "custom-generate-music"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
user: "{{agent}}",
|
|
152
|
+
content: {
|
|
153
|
+
text: "Successfully generated your peaceful piano melody in C major."
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
{
|
|
159
|
+
user: "{{user1}}",
|
|
160
|
+
content: {
|
|
161
|
+
text: "Make a rock song with guitar solos",
|
|
162
|
+
prompt: "A rock song with powerful electric guitar solos and driving drums",
|
|
163
|
+
duration: 90,
|
|
164
|
+
style: "rock",
|
|
165
|
+
bpm: 120,
|
|
166
|
+
classifier_free_guidance: 4.0
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
user: "{{agent}}",
|
|
171
|
+
content: {
|
|
172
|
+
text: "I'll generate a rock track with guitar solos for you.",
|
|
173
|
+
action: "custom-generate-music"
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
user: "{{agent}}",
|
|
178
|
+
content: {
|
|
179
|
+
text: "Successfully generated your rock song with guitar solos."
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
|
|
156
186
|
export default customGenerateMusic;
|
package/src/actions/extend.ts
CHANGED
|
@@ -1,134 +1,164 @@
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
audio_id:
|
|
68
|
-
duration:
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
text:
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
user: "{{agent}}",
|
|
103
|
-
content: {
|
|
104
|
-
text: "
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
user: "{{agent}}",
|
|
126
|
-
content: {
|
|
127
|
-
text: "
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
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: any, message: any, state?: any, options?: any): Promise<boolean> => {
|
|
16
|
+
const __avTextRaw = typeof message?.content?.text === 'string' ? message.content.text : '';
|
|
17
|
+
const __avText = __avTextRaw.toLowerCase();
|
|
18
|
+
const __avKeywords = ['extend', 'audio'];
|
|
19
|
+
const __avKeywordOk =
|
|
20
|
+
__avKeywords.length > 0 &&
|
|
21
|
+
__avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
22
|
+
const __avRegex = new RegExp('\\b(?:extend|audio)\\b', 'i');
|
|
23
|
+
const __avRegexOk = __avRegex.test(__avText);
|
|
24
|
+
const __avSource = String(message?.content?.source ?? message?.source ?? '');
|
|
25
|
+
const __avExpectedSource = '';
|
|
26
|
+
const __avSourceOk = __avExpectedSource
|
|
27
|
+
? __avSource === __avExpectedSource
|
|
28
|
+
: Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
29
|
+
const __avOptions = options && typeof options === 'object' ? options : {};
|
|
30
|
+
const __avInputOk =
|
|
31
|
+
__avText.trim().length > 0 ||
|
|
32
|
+
Object.keys(__avOptions as Record<string, unknown>).length > 0 ||
|
|
33
|
+
Boolean(message?.content && typeof message.content === 'object');
|
|
34
|
+
|
|
35
|
+
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const __avLegacyValidate = async (runtime: IAgentRuntime, _message: Memory) => {
|
|
40
|
+
return !!runtime.getSetting("SUNO_API_KEY");
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
return Boolean(await (__avLegacyValidate as any)(runtime, message, state, options));
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
handler: async (
|
|
50
|
+
runtime: IAgentRuntime,
|
|
51
|
+
message: Memory,
|
|
52
|
+
state: State,
|
|
53
|
+
_options: { [key: string]: unknown },
|
|
54
|
+
callback?: HandlerCallback
|
|
55
|
+
): Promise<boolean> => {
|
|
56
|
+
try {
|
|
57
|
+
const provider = await SunoProvider.get(runtime, message, state);
|
|
58
|
+
const content = message.content as unknown as ExtendParams;
|
|
59
|
+
|
|
60
|
+
if (!content.audio_id || !content.duration) {
|
|
61
|
+
throw new Error("Missing required parameters: audio_id and duration");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const response = await provider.request('/extend', {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
body: JSON.stringify({
|
|
67
|
+
audio_id: content.audio_id,
|
|
68
|
+
duration: content.duration
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (callback) {
|
|
73
|
+
callback({
|
|
74
|
+
text: `Successfully extended audio ${content.audio_id}`,
|
|
75
|
+
content: response
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return true;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (callback) {
|
|
82
|
+
callback({
|
|
83
|
+
text: `Failed to extend audio: ${(error as Error).message}`,
|
|
84
|
+
error: error
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
examples: [
|
|
92
|
+
[
|
|
93
|
+
{
|
|
94
|
+
user: "{{user1}}",
|
|
95
|
+
content: {
|
|
96
|
+
text: "Make this song longer by 30 seconds",
|
|
97
|
+
audio_id: "abc123",
|
|
98
|
+
duration: 30
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
user: "{{agent}}",
|
|
103
|
+
content: {
|
|
104
|
+
text: "I'll extend your song by 30 seconds.",
|
|
105
|
+
action: "extend-audio"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
user: "{{agent}}",
|
|
110
|
+
content: {
|
|
111
|
+
text: "Successfully extended your song by 30 seconds."
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
{
|
|
117
|
+
user: "{{user1}}",
|
|
118
|
+
content: {
|
|
119
|
+
text: "Double the length of this track",
|
|
120
|
+
audio_id: "xyz789",
|
|
121
|
+
duration: 60
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
user: "{{agent}}",
|
|
126
|
+
content: {
|
|
127
|
+
text: "I'll double the duration of your track.",
|
|
128
|
+
action: "extend-audio"
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
user: "{{agent}}",
|
|
133
|
+
content: {
|
|
134
|
+
text: "Successfully doubled the length of your track to 60 seconds."
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
{
|
|
140
|
+
user: "{{user1}}",
|
|
141
|
+
content: {
|
|
142
|
+
text: "Add 15 more seconds to this melody",
|
|
143
|
+
audio_id: "def456",
|
|
144
|
+
duration: 15
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
user: "{{agent}}",
|
|
149
|
+
content: {
|
|
150
|
+
text: "I'll add 15 seconds to your melody.",
|
|
151
|
+
action: "extend-audio"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
user: "{{agent}}",
|
|
156
|
+
content: {
|
|
157
|
+
text: "Successfully added 15 seconds to your melody."
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
]
|
|
162
|
+
};
|
|
163
|
+
|
|
134
164
|
export default extendAudio;
|
package/src/actions/generate.ts
CHANGED
|
@@ -1,145 +1,175 @@
|
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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: any, message: any, state?: any, options?: any): Promise<boolean> => {
|
|
18
|
+
const __avTextRaw = typeof message?.content?.text === 'string' ? message.content.text : '';
|
|
19
|
+
const __avText = __avTextRaw.toLowerCase();
|
|
20
|
+
const __avKeywords = ['generate', 'music'];
|
|
21
|
+
const __avKeywordOk =
|
|
22
|
+
__avKeywords.length > 0 &&
|
|
23
|
+
__avKeywords.some((kw) => kw.length > 0 && __avText.includes(kw));
|
|
24
|
+
const __avRegex = new RegExp('\\b(?:generate|music)\\b', 'i');
|
|
25
|
+
const __avRegexOk = __avRegex.test(__avText);
|
|
26
|
+
const __avSource = String(message?.content?.source ?? message?.source ?? '');
|
|
27
|
+
const __avExpectedSource = '';
|
|
28
|
+
const __avSourceOk = __avExpectedSource
|
|
29
|
+
? __avSource === __avExpectedSource
|
|
30
|
+
: Boolean(__avSource || state || runtime?.agentId || runtime?.getService);
|
|
31
|
+
const __avOptions = options && typeof options === 'object' ? options : {};
|
|
32
|
+
const __avInputOk =
|
|
33
|
+
__avText.trim().length > 0 ||
|
|
34
|
+
Object.keys(__avOptions as Record<string, unknown>).length > 0 ||
|
|
35
|
+
Boolean(message?.content && typeof message.content === 'object');
|
|
36
|
+
|
|
37
|
+
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const __avLegacyValidate = async (runtime: IAgentRuntime, _message: Memory) => {
|
|
42
|
+
return !!runtime.getSetting("SUNO_API_KEY");
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
return Boolean(await (__avLegacyValidate as any)(runtime, message, state, options));
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
handler: async (
|
|
52
|
+
runtime: IAgentRuntime,
|
|
53
|
+
message: Memory,
|
|
54
|
+
state: State,
|
|
55
|
+
_options: { [key: string]: unknown },
|
|
56
|
+
callback?: HandlerCallback
|
|
57
|
+
): Promise<boolean> => {
|
|
58
|
+
try {
|
|
59
|
+
const provider = await SunoProvider.get(runtime, message, state);
|
|
60
|
+
const content = message.content as unknown as GenerateParams;
|
|
61
|
+
|
|
62
|
+
if (!content.prompt) {
|
|
63
|
+
throw new Error("Missing required parameter: prompt");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const response = await provider.request('/generate', {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
prompt: content.prompt,
|
|
70
|
+
duration: content.duration || 30,
|
|
71
|
+
temperature: content.temperature || 1.0,
|
|
72
|
+
top_k: content.topK || 250,
|
|
73
|
+
top_p: content.topP || 0.95,
|
|
74
|
+
classifier_free_guidance: content.classifier_free_guidance || 3.0
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (callback) {
|
|
79
|
+
callback({
|
|
80
|
+
text: 'Successfully generated music based on your prompt',
|
|
81
|
+
content: response
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return true;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (callback) {
|
|
88
|
+
callback({
|
|
89
|
+
text: `Failed to extend audio: ${(error as Error).message}`,
|
|
90
|
+
error: error
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
examples: [
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
user: "{{user1}}",
|
|
101
|
+
content: {
|
|
102
|
+
text: "Create a happy and energetic song",
|
|
103
|
+
prompt: "A cheerful and energetic melody with upbeat rhythm",
|
|
104
|
+
duration: 30,
|
|
105
|
+
temperature: 1.0
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
user: "{{agent}}",
|
|
110
|
+
content: {
|
|
111
|
+
text: "I'll generate a happy and energetic song for you.",
|
|
112
|
+
action: "generate-music"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
user: "{{agent}}",
|
|
117
|
+
content: {
|
|
118
|
+
text: "Successfully generated your upbeat and energetic song."
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
{
|
|
124
|
+
user: "{{user1}}",
|
|
125
|
+
content: {
|
|
126
|
+
text: "Generate a relaxing ambient track",
|
|
127
|
+
prompt: "A peaceful ambient soundscape with gentle waves and soft pads",
|
|
128
|
+
duration: 45,
|
|
129
|
+
temperature: 0.8,
|
|
130
|
+
classifier_free_guidance: 4.0
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
user: "{{agent}}",
|
|
135
|
+
content: {
|
|
136
|
+
text: "I'll create a calming ambient piece for you.",
|
|
137
|
+
action: "generate-music"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
user: "{{agent}}",
|
|
142
|
+
content: {
|
|
143
|
+
text: "Successfully generated your relaxing ambient soundscape."
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
{
|
|
149
|
+
user: "{{user1}}",
|
|
150
|
+
content: {
|
|
151
|
+
text: "Make a short jingle for my podcast",
|
|
152
|
+
prompt: "A catchy and professional podcast intro jingle",
|
|
153
|
+
duration: 15,
|
|
154
|
+
temperature: 1.2,
|
|
155
|
+
top_k: 300
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
user: "{{agent}}",
|
|
160
|
+
content: {
|
|
161
|
+
text: "I'll generate a podcast jingle for you.",
|
|
162
|
+
action: "generate-music"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
user: "{{agent}}",
|
|
167
|
+
content: {
|
|
168
|
+
text: "Successfully generated your podcast jingle."
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
]
|
|
173
|
+
};
|
|
174
|
+
|
|
145
175
|
export default generateMusic;
|
package/src/providers/suno.ts
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
import type { IAgentRuntime, Memory, State } from "@elizaos/core";
|
|
2
|
-
import
|
|
1
|
+
import type { IAgentRuntime, Memory, Provider, ProviderResult, State } from "@elizaos/core";
|
|
2
|
+
import { validateActionKeywords, validateActionRegex } from "@elizaos/core";
|
|
3
3
|
|
|
4
4
|
export interface SunoConfig {
|
|
5
5
|
apiKey: string;
|
|
6
6
|
baseUrl?: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export class SunoProvider implements Provider {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export class SunoProvider implements Provider {
|
|
10
|
+
name = "suno";
|
|
11
|
+
dynamic = true;
|
|
12
|
+
relevanceKeywords = [
|
|
13
|
+
"suno",
|
|
14
|
+
"music",
|
|
15
|
+
"song",
|
|
16
|
+
"audio",
|
|
17
|
+
"generate",
|
|
18
|
+
"lyrics",
|
|
19
|
+
"melody",
|
|
20
|
+
"track",
|
|
21
|
+
"status",
|
|
22
|
+
"state",
|
|
23
|
+
"context",
|
|
24
|
+
];
|
|
25
|
+
private apiKey: string;
|
|
26
|
+
private baseUrl: string;
|
|
12
27
|
|
|
13
28
|
static async get(runtime: IAgentRuntime, _message: Memory, _state?: State): Promise<SunoProvider> {
|
|
14
29
|
const apiKey = runtime.getSetting("SUNO_API_KEY");
|
|
@@ -23,9 +38,34 @@ export class SunoProvider implements Provider {
|
|
|
23
38
|
this.baseUrl = config.baseUrl || 'https://api.suno.ai/v1';
|
|
24
39
|
}
|
|
25
40
|
|
|
26
|
-
async get(_runtime: IAgentRuntime, _message: Memory, _state?: State): Promise<
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
async get(_runtime: IAgentRuntime, _message: Memory, _state?: State): Promise<ProviderResult> {
|
|
42
|
+
const __providerKeywords = [
|
|
43
|
+
"suno",
|
|
44
|
+
"music",
|
|
45
|
+
"song",
|
|
46
|
+
"audio",
|
|
47
|
+
"generate",
|
|
48
|
+
"lyrics",
|
|
49
|
+
"melody",
|
|
50
|
+
"track",
|
|
51
|
+
"status",
|
|
52
|
+
"state",
|
|
53
|
+
"context",
|
|
54
|
+
];
|
|
55
|
+
const __providerRegex = new RegExp(`\\b(${__providerKeywords.join("|")})\\b`, "i");
|
|
56
|
+
const __recentMessages = _state?.recentMessagesData || [];
|
|
57
|
+
const __isRelevant =
|
|
58
|
+
validateActionKeywords(_message, __recentMessages, __providerKeywords) ||
|
|
59
|
+
validateActionRegex(_message, __recentMessages, __providerRegex);
|
|
60
|
+
if (!__isRelevant) {
|
|
61
|
+
return { text: "" };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
text: "Suno provider ready",
|
|
66
|
+
data: { status: "ready" },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
29
69
|
|
|
30
70
|
async request(endpoint: string, options: RequestInit = {}) {
|
|
31
71
|
const url = `${this.baseUrl}${endpoint}`;
|
|
@@ -75,4 +115,4 @@ export interface GenerationResponse {
|
|
|
75
115
|
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
76
116
|
audio_url?: string;
|
|
77
117
|
error?: string;
|
|
78
|
-
}
|
|
118
|
+
}
|