@j-o-r/hello-dave 0.1.0 → 0.1.4
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/CHANGELOG.md +42 -25
- package/README.md +81 -221
- package/TODO.md +173 -35
- package/agents/agent_creator.js +105 -0
- package/agents/agent_creator.prompt.md +371 -0
- package/agents/ask_agent.js +64 -127
- package/agents/claude_agent.js +68 -0
- package/agents/code_agent.js +55 -135
- package/agents/code_agent.prompt.md +50 -0
- package/agents/echo_agent.js +76 -0
- package/agents/financial_expert.js +75 -0
- package/agents/gpt_agent.js +52 -103
- package/agents/gpt_code.js +81 -0
- package/agents/grok_agent.js +58 -114
- package/agents/minimax_agent.js +92 -0
- package/agents/mureka_agent.js +77 -0
- package/agents/planner_agent.js +172 -0
- package/agents/stability_agent.js +87 -0
- package/agents/test_agent.js +75 -157
- package/agents/weather_agent.js +73 -0
- package/agents/workflow_agent.js +189 -0
- package/bin/dave.js +436 -184
- package/docs/bin-dave.md +85 -35
- package/docs/cdn-ssh.md +100 -0
- package/docs/creating-agents.md +301 -0
- package/docs/creating-toolsets.md +336 -0
- package/docs/docs-organization.md +48 -0
- package/docs/project-overview.md +86 -51
- package/lib/API/elevenlabs.io/music.compose.md +441 -0
- package/lib/API/elevenlabs.io/music.create-composition-plan.md +370 -0
- package/lib/API/elevenlabs.io/music.stream.md +425 -0
- package/lib/API/lalal.ai/lalal.js +445 -0
- package/lib/API/lalal.ai/openapi.json +2614 -0
- package/lib/API/minimax/ImageToolset.js +82 -37
- package/lib/API/minimax/MusicToolset.js +125 -79
- package/lib/API/minimax/VideoToolset.js +170 -167
- package/lib/API/minimax/image.js +5 -1
- package/lib/API/minimax/music.js +210 -23
- package/lib/API/minimax/video.js +242 -53
- package/lib/API/mureka/MusicToolset.js +646 -0
- package/lib/API/mureka/README.md +41 -0
- package/lib/API/mureka/index.js +7 -0
- package/lib/API/mureka/music.js +658 -0
- package/lib/API/openai.com/index.js +7 -0
- package/lib/API/openai.com/{reponses/text.js → responses.js} +64 -18
- package/lib/API/openai.com/video.create.character.md +40 -0
- package/lib/API/openai.com/video.create.md +219 -0
- package/lib/API/openai.com/video.delete.md +44 -0
- package/lib/API/openai.com/video.download.md +31 -0
- package/lib/API/openai.com/video.edit.md +155 -0
- package/lib/API/openai.com/video.extend.md +166 -0
- package/lib/API/openai.com/video.fetch.character.md +43 -0
- package/lib/API/openai.com/video.js +784 -0
- package/lib/API/openai.com/video.list.md +201 -0
- package/lib/API/openai.com/video.remix.md +175 -0
- package/lib/API/openai.com/video.retrieve.md +139 -0
- package/lib/API/openai.com/videoToolset.js +616 -0
- package/lib/API/stability.ai/ImageToolset.js +131 -40
- package/lib/API/stability.ai/MusicToolset.js +79 -47
- package/lib/API/stability.ai/audio.js +63 -131
- package/lib/API/x.ai/chat.responses.md +1040 -0
- package/lib/API/x.ai/image.js +229 -59
- package/lib/API/x.ai/imageToolset.js +376 -0
- package/lib/API/x.ai/index.js +1 -3
- package/lib/API/x.ai/responses.js +9 -18
- package/lib/Agent.js +271 -0
- package/lib/Agent.js.old +284 -0
- package/lib/AgentLauncher.js +562 -0
- package/lib/Cli.js +87 -13
- package/lib/Prompt.js +23 -1
- package/lib/Session.js +5 -4
- package/lib/ToolSet.js +102 -6
- package/lib/agentLoader.js +369 -0
- package/lib/cdn.js +67 -231
- package/lib/{CdnToolset.js → cdnToolset.js} +47 -64
- package/lib/defaultToolsets.js +43 -0
- package/lib/fafs.js +1 -1
- package/lib/genericToolset.js +442 -119
- package/lib/handOffToolset.js +179 -0
- package/lib/index.js +34 -27
- package/lib/toolsetLoader.js +248 -0
- package/package.json +11 -5
- package/types/API/lalal.ai/lalal.d.ts +116 -0
- package/types/API/minimax/image.d.ts +2 -1
- package/types/API/minimax/music.d.ts +189 -26
- package/types/API/minimax/video.d.ts +100 -31
- package/types/API/mureka/index.d.ts +7 -0
- package/types/API/mureka/music.d.ts +472 -0
- package/types/API/openai.com/index.d.ts +7 -0
- package/types/API/openai.com/{reponses/text.d.ts → responses.d.ts} +11 -11
- package/types/API/openai.com/video.d.ts +409 -0
- package/types/API/openai.com/videoToolset.d.ts +24 -0
- package/types/API/stability.ai/audio.d.ts +14 -103
- package/types/API/stability.ai/image.d.ts +2 -2
- package/types/API/x.ai/image.d.ts +138 -26
- package/types/API/x.ai/imageToolset.d.ts +3 -0
- package/types/API/x.ai/index.d.ts +1 -3
- package/types/API/x.ai/responses.d.ts +4 -4
- package/types/Agent.d.ts +123 -0
- package/types/AgentLauncher.d.ts +222 -0
- package/types/Cli.d.ts +28 -8
- package/types/Prompt.d.ts +23 -5
- package/types/Session.d.ts +1 -1
- package/types/ToolSet.d.ts +10 -0
- package/types/agentLoader.d.ts +78 -0
- package/types/cdn.d.ts +15 -90
- package/types/defaultToolsets.d.ts +9 -0
- package/types/fafs.d.ts +1 -1
- package/types/genericToolset.d.ts +1 -1
- package/types/handOffToolset.d.ts +28 -0
- package/types/index.d.ts +19 -16
- package/types/toolsetLoader.d.ts +114 -0
- package/utils/format_log.js +101 -23
- package/utils/launch_agent.js +18 -0
- package/utils/list_sessions.sh +13 -5
- package/utils/search_sessions.sh +65 -29
- package/utils/toolsets.js +33 -0
- package/README.md.bak.1779452127 +0 -240
- package/agents/codeserver.sh +0 -47
- package/agents/daisy_agent.js +0 -173
- package/agents/docs_agent.js +0 -148
- package/agents/memory_agent.js +0 -263
- package/agents/minimax.js +0 -173
- package/agents/npm_agent.js +0 -202
- package/agents/prompt_agent.js +0 -133
- package/agents/readme_agent.js +0 -148
- package/agents/spawn_agent.js +0 -160
- package/agents/stability.js +0 -173
- package/agents/todo_agent.js +0 -175
- package/bin/codeDave +0 -58
- package/docs/agent-dave-websocket-protocol.md +0 -180
- package/docs/agent-manager.md +0 -244
- package/docs/codeserver-pattern.md +0 -191
- package/docs/generic-toolset.md +0 -326
- package/docs/howtos/agent-networking.md +0 -253
- package/docs/howtos/spawn-agents.md.bak +0 -200
- package/docs/howtos/spawn-agents.md.bak_new +0 -200
- package/docs/multi-agent-clusters.md +0 -265
- package/docs/music-toolsets.md +0 -137
- package/docs/path-resolution-best-practices.md +0 -104
- package/docs/plans/minimax-music-generation.md +0 -80
- package/docs/plans/unified-agent-architecture.md +0 -146
- package/docs/plans/websocket-streaming-plan.md.bak +0 -317
- package/docs/prompt/spawn_agent.md +0 -175
- package/docs/prompt/spawn_agent.md.bak +0 -201
- package/docs/prompt/task_clarification_and_documentation.md +0 -35
- package/docs/prompt-class.md +0 -141
- package/docs/todo-archive-infra-2026-04-21.md +0 -15
- package/docs/todo-archive-v0.0.8.md +0 -1
- package/docs/todo-archive-v0.1.0.md +0 -32
- package/docs/todo-archive.md +0 -44
- package/docs/tools-syntax-validation.md +0 -121
- package/docs/toolset.md +0 -164
- package/docs/xai-responses.md +0 -111
- package/docs/xai_collections.md +0 -106
- package/lib/API/x.ai/ImageToolset.js +0 -165
- package/lib/API/x.ai/text.js +0 -415
- package/lib/AgentClient.js +0 -248
- package/lib/AgentManager.js +0 -245
- package/lib/AgentServer.js +0 -404
- package/lib/wsCli.js +0 -287
- package/lib/wsIO.js +0 -90
- package/types/API/x.ai/text.d.ts +0 -286
- package/types/AgentClient.d.ts +0 -109
- package/types/AgentManager.d.ts +0 -100
- package/types/AgentServer.d.ts +0 -89
- package/types/wsCli.d.ts +0 -17
- package/types/wsIO.d.ts +0 -30
- package/utils/test.sh +0 -46
- /package/docs/{suggestions.md → _notes/token-counts.md} +0 -0
- /package/lib/API/openai.com/{reponses/MESSAGES.md → MESSAGES.md} +0 -0
- /package/types/API/{x.ai/ImageToolset.d.ts → mureka/MusicToolset.d.ts} +0 -0
- /package/types/{CdnToolset.d.ts → cdnToolset.d.ts} +0 -0
package/lib/API/minimax/music.js
CHANGED
|
@@ -9,13 +9,18 @@
|
|
|
9
9
|
*
|
|
10
10
|
* This is a clean library with four distinct workflows:
|
|
11
11
|
* 1. createMusic() → text-to-music (music-2.6 / music-2.6-free)
|
|
12
|
-
* 2. changeMusic() → cover generation (music-cover
|
|
13
|
-
* 3. analyzeMusic() → preprocess reference for two-step covers
|
|
12
|
+
* 2. changeMusic() → cover generation (music-cover) — model fixed to 'music-cover'
|
|
13
|
+
* 3. analyzeMusic() → preprocess reference for two-step covers (model fixed to 'music-cover')
|
|
14
14
|
* 4. generateLyrics() → create or edit song lyrics
|
|
15
15
|
*
|
|
16
16
|
* Notes on parameters:
|
|
17
17
|
* - Lyrics are optional for both instrumental and non-instrumental generation.
|
|
18
18
|
* - Streaming is not supported; stream is always false.
|
|
19
|
+
* - All functions use environment variable MINIMAX_API_KEY for auth.
|
|
20
|
+
* - Generated audio is automatically saved to .cache/minimax/ as MP3.
|
|
21
|
+
* - For music-cover models: prompt max 300 characters (enforced).
|
|
22
|
+
* - audio_setting is fixed internally (44100 Hz, 256 kbps, mp3) — no user override.
|
|
23
|
+
* - Model for changeMusic() and analyzeMusic() is fixed to 'music-cover' (no free variant).
|
|
19
24
|
*/
|
|
20
25
|
|
|
21
26
|
import { request as doRequest } from '@j-o-r/apiserver';
|
|
@@ -26,6 +31,12 @@ const BASE_URL = 'https://api.minimax.io/v1';
|
|
|
26
31
|
|
|
27
32
|
const TMP_DIR = path.join(process.cwd(), '.cache', 'minimax');
|
|
28
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Get authentication headers for Minimax API.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Object} Headers object with Authorization Bearer token.
|
|
38
|
+
* @throws {Error} If MINIMAX_API_KEY environment variable is not set.
|
|
39
|
+
*/
|
|
29
40
|
const getHeaders = () => {
|
|
30
41
|
if (!process.env.MINIMAX_API_KEY) {
|
|
31
42
|
throw new Error('Missing MINIMAX_API_KEY! Please export MINIMAX_API_KEY=your_key');
|
|
@@ -36,6 +47,13 @@ const getHeaders = () => {
|
|
|
36
47
|
};
|
|
37
48
|
};
|
|
38
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Saves audio data (URL or hex) to a local temporary MP3 file.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} audioData - Either a URL or hex-encoded audio data.
|
|
54
|
+
* @param {string} [filenamePrefix='minimax-music'] - Prefix for the local filename.
|
|
55
|
+
* @returns {Promise<string>} Absolute path to the saved local file.
|
|
56
|
+
*/
|
|
39
57
|
async function saveAudioToLocal(audioData, filenamePrefix = 'minimax-music') {
|
|
40
58
|
const tmpDir = path.join(process.cwd(), '.cache', 'minimax');
|
|
41
59
|
await fs.mkdir(tmpDir, { recursive: true });
|
|
@@ -62,6 +80,47 @@ async function saveAudioToLocal(audioData, filenamePrefix = 'minimax-music') {
|
|
|
62
80
|
WORKFLOW 1: CREATE MUSIC (Text-to-Music)
|
|
63
81
|
============================================================ */
|
|
64
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Generate music from a text prompt (text-to-music workflow).
|
|
85
|
+
*
|
|
86
|
+
* Uses models `music-2.6` or `music-2.6-free`.
|
|
87
|
+
* Does NOT support reference audio (use changeMusic() or analyzeMusic() instead).
|
|
88
|
+
*
|
|
89
|
+
* @param {string} prompt - Description of the music (style, mood, scenario). Max 2000 chars.
|
|
90
|
+
* @param {Object} [options={}] - Generation options.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} [options.model='music-2.6'] - Model to use.
|
|
93
|
+
* - 'music-2.6' (default, recommended, higher RPM)
|
|
94
|
+
* - 'music-2.6-free' (free tier, lower RPM)
|
|
95
|
+
*
|
|
96
|
+
* @param {string} [options.lyrics] - Song lyrics with structure tags (e.g. [Verse], [Chorus]).
|
|
97
|
+
* Required for non-instrumental. Max 3500 chars.
|
|
98
|
+
*
|
|
99
|
+
* @param {boolean} [options.is_instrumental=false] - Generate instrumental music (no vocals).
|
|
100
|
+
* When true, lyrics are optional.
|
|
101
|
+
*
|
|
102
|
+
* @param {boolean} [options.lyrics_optimizer=false] - Auto-generate lyrics from prompt when lyrics is empty.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} [options.output_format='url'] - 'url' or 'hex'. URL links expire after 24h.
|
|
105
|
+
*
|
|
106
|
+
* @param {Object} [options.extra] - Any additional undocumented parameters.
|
|
107
|
+
*
|
|
108
|
+
* @returns {Promise<{
|
|
109
|
+
* audio_url: string, // Original URL or hex data
|
|
110
|
+
* local_path: string, // Path in .cache/minimax/
|
|
111
|
+
* duration: number, // API call time in ms
|
|
112
|
+
* raw: object // Full API response
|
|
113
|
+
* }>}
|
|
114
|
+
*
|
|
115
|
+
* @throws {Error} If reference audio params are provided or invalid model.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* const result = await createMusic("Indie folk, melancholic", {
|
|
119
|
+
* model: "music-2.6",
|
|
120
|
+
* lyrics: "[Verse]\n...",
|
|
121
|
+
* is_instrumental: false
|
|
122
|
+
* });
|
|
123
|
+
*/
|
|
65
124
|
async function createMusic(prompt, options = {}) {
|
|
66
125
|
const model = options.model || 'music-2.6';
|
|
67
126
|
|
|
@@ -79,25 +138,85 @@ async function createMusic(prompt, options = {}) {
|
|
|
79
138
|
);
|
|
80
139
|
}
|
|
81
140
|
|
|
141
|
+
// Note: create allows up to 2000 chars; no strict enforcement here
|
|
82
142
|
return requestMusicInternal(prompt, { ...options, model });
|
|
83
143
|
}
|
|
84
144
|
|
|
85
145
|
/* ============================================================
|
|
86
|
-
WORKFLOW 2: CHANGE MUSIC (Cover / Reference-based)
|
|
146
|
+
WORKFLOW 2: CHANGE MUSIC (Cover / Reference-based) — MODEL FIXED
|
|
87
147
|
============================================================ */
|
|
88
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Generate a cover version of reference music (music-cover workflow).
|
|
151
|
+
*
|
|
152
|
+
* **Model is fixed to 'music-cover'** (the recommended paid model).
|
|
153
|
+
* The free variant ('music-cover-free') is not supported for changeMusic().
|
|
154
|
+
*
|
|
155
|
+
* Requires either direct reference audio OR a preprocessed cover_feature_id.
|
|
156
|
+
*
|
|
157
|
+
* **Critical rule for two-step covers (cover_feature_id)**:
|
|
158
|
+
* - When `cover_feature_id` is used **and** `is_instrumental` is false (non-instrumental),
|
|
159
|
+
* the `lyrics` parameter is **mandatory**.
|
|
160
|
+
* - When using direct `audio_url`/`audio_base64`, lyrics are optional (API can extract via ASR).
|
|
161
|
+
*
|
|
162
|
+
* **Prompt limit**: Max 300 characters (strictly enforced for music-cover models).
|
|
163
|
+
* **audio_setting**: Fixed internally to { sample_rate: 44100, bitrate: 256000, format: 'mp3' }.
|
|
164
|
+
* User-provided audio_setting is ignored.
|
|
165
|
+
*
|
|
166
|
+
* @param {string} prompt - Description of the target cover style. Max 300 chars.
|
|
167
|
+
* @param {Object} [options={}] - Generation options (model is ignored — always 'music-cover').
|
|
168
|
+
*
|
|
169
|
+
* @param {string} [options.audio_url] - URL of reference audio (6s–6min, ≤50MB).
|
|
170
|
+
* Mutually exclusive with cover_feature_id.
|
|
171
|
+
*
|
|
172
|
+
* @param {string} [options.audio_base64] - Base64 reference audio (alternative to audio_url).
|
|
173
|
+
*
|
|
174
|
+
* @param {string} [options.cover_feature_id] - Feature ID from analyzeMusic() for two-step covers.
|
|
175
|
+
* **Requires lyrics** when is_instrumental=false. Valid for 24h. Mutually exclusive with audio refs.
|
|
176
|
+
*
|
|
177
|
+
* @param {string} [options.lyrics] - Lyrics for the cover (mandatory for cover_feature_id + non-instrumental).
|
|
178
|
+
*
|
|
179
|
+
* @param {boolean} [options.lyrics_optimizer=false] - Auto-generate lyrics from prompt.
|
|
180
|
+
*
|
|
181
|
+
* @param {string} [options.output_format='url'] - 'url' or 'hex'.
|
|
182
|
+
*
|
|
183
|
+
* @param {Object} [options.extra] - Additional parameters.
|
|
184
|
+
*
|
|
185
|
+
* @returns {Promise<{audio_url: string, local_path: string, duration: number, raw: object}>}
|
|
186
|
+
*
|
|
187
|
+
* @throws {Error} On missing reference, conflicting params, prompt > 300 chars, or missing lyrics for two-step non-instrumental.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* // One-step cover
|
|
191
|
+
* const result = await changeMusic("Pop cover style", {
|
|
192
|
+
* audio_url: "https://example.com/reference.mp3"
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* // Two-step cover (after analyzeMusic) — lyrics REQUIRED
|
|
197
|
+
* const result = await changeMusic("New lyrics style", {
|
|
198
|
+
* cover_feature_id: "abc123...",
|
|
199
|
+
* lyrics: "[Verse]\nNew lyrics...",
|
|
200
|
+
* is_instrumental: false
|
|
201
|
+
* });
|
|
202
|
+
*/
|
|
89
203
|
async function changeMusic(prompt, options = {}) {
|
|
90
|
-
|
|
204
|
+
// Model is FIXED to 'music-cover' — ignore any provided value
|
|
205
|
+
const model = 'music-cover';
|
|
91
206
|
|
|
92
|
-
|
|
207
|
+
// Enforce prompt length for cover models
|
|
208
|
+
if (prompt && typeof prompt === 'string' && prompt.length > 300) {
|
|
93
209
|
throw new Error(
|
|
94
|
-
`changeMusic()
|
|
95
|
-
'
|
|
210
|
+
`changeMusic() prompt too long: ${prompt.length} characters. ` +
|
|
211
|
+
'music-cover models require prompt ≤ 300 characters. ' +
|
|
212
|
+
'Shorten your prompt (e.g. remove extra fidelity instructions).'
|
|
96
213
|
);
|
|
97
214
|
}
|
|
98
215
|
|
|
99
216
|
const hasAudioRef = !!(options.audio_url || options.audio_base64);
|
|
100
217
|
const hasFeatureId = !!options.cover_feature_id;
|
|
218
|
+
const isInstrumental = options.is_instrumental === true;
|
|
219
|
+
const hasLyrics = !!(options.lyrics && options.lyrics.trim() !== '');
|
|
101
220
|
|
|
102
221
|
if (hasAudioRef && hasFeatureId) {
|
|
103
222
|
throw new Error(
|
|
@@ -113,13 +232,44 @@ async function changeMusic(prompt, options = {}) {
|
|
|
113
232
|
);
|
|
114
233
|
}
|
|
115
234
|
|
|
235
|
+
// NEW: Enforce mandatory lyrics for two-step non-instrumental covers
|
|
236
|
+
if (hasFeatureId && !isInstrumental && !hasLyrics) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
'changeMusic() with cover_feature_id requires the "lyrics" parameter ' +
|
|
239
|
+
'when is_instrumental is false (non-instrumental cover). ' +
|
|
240
|
+
'Provide structured lyrics or set is_instrumental: true.'
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
116
244
|
return requestMusicInternal(prompt, { ...options, model });
|
|
117
245
|
}
|
|
118
246
|
|
|
119
247
|
/* ============================================================
|
|
120
|
-
WORKFLOW 3: ANALYZE MUSIC (Preprocess for Cover)
|
|
248
|
+
WORKFLOW 3: ANALYZE MUSIC (Preprocess for Cover) — MODEL FIXED
|
|
121
249
|
============================================================ */
|
|
122
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Preprocess a reference audio to extract features and structured lyrics.
|
|
253
|
+
*
|
|
254
|
+
* Used for the two-step cover workflow (analyze → changeMusic with cover_feature_id).
|
|
255
|
+
* **Model is fixed to 'music-cover'**.
|
|
256
|
+
*
|
|
257
|
+
* @param {string} audioUrl - URL of the reference audio (6s–6min, ≤50MB).
|
|
258
|
+
* @param {Object} [options={}] - Optional parameters (model is ignored).
|
|
259
|
+
*
|
|
260
|
+
* @returns {Promise<{
|
|
261
|
+
* cover_feature_id: string, // Valid 24h, use in changeMusic()
|
|
262
|
+
* formatted_lyrics: string, // Structured lyrics with [Verse] etc.
|
|
263
|
+
* structure_result: string, // JSON song structure analysis
|
|
264
|
+
* audio_duration: number,
|
|
265
|
+
* trace_id: string,
|
|
266
|
+
* raw: object
|
|
267
|
+
* }>}
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* const analysis = await analyzeMusic("https://example.com/song.mp3");
|
|
271
|
+
* // Then pass analysis.cover_feature_id to changeMusic()
|
|
272
|
+
*/
|
|
123
273
|
async function analyzeMusic(audioUrl, options = {}) {
|
|
124
274
|
return preprocessCoverInternal(audioUrl, options);
|
|
125
275
|
}
|
|
@@ -131,13 +281,34 @@ async function analyzeMusic(audioUrl, options = {}) {
|
|
|
131
281
|
/**
|
|
132
282
|
* Generate complete song lyrics or edit/continue existing lyrics.
|
|
133
283
|
*
|
|
134
|
-
* @param {string} prompt - Theme, style, or editing instruction.
|
|
135
|
-
* @param {Object} [options]
|
|
136
|
-
* @param {'write_full_song'|'edit'} [options.mode='write_full_song']
|
|
137
|
-
* @param {string} [options.lyrics] - Existing lyrics (required for edit mode)
|
|
138
|
-
* @param {string} [options.title]
|
|
284
|
+
* @param {string} prompt - Theme, style, or editing instruction. Max 2000 chars.
|
|
285
|
+
* @param {Object} [options={}] - Lyrics options.
|
|
139
286
|
*
|
|
140
|
-
* @
|
|
287
|
+
* @param {'write_full_song'|'edit'} [options.mode='write_full_song'] - Generation mode.
|
|
288
|
+
* - 'write_full_song': Create a new complete song.
|
|
289
|
+
* - 'edit': Edit or continue existing lyrics (requires options.lyrics).
|
|
290
|
+
*
|
|
291
|
+
* @param {string} [options.lyrics] - Existing lyrics (required for 'edit' mode). Max 3500 chars.
|
|
292
|
+
*
|
|
293
|
+
* @param {string} [options.title] - Desired song title (preserved if provided).
|
|
294
|
+
*
|
|
295
|
+
* @returns {Promise<{
|
|
296
|
+
* song_title: string,
|
|
297
|
+
* style_tags: string, // Comma-separated tags
|
|
298
|
+
* lyrics: string, // Structured lyrics ready for music generation
|
|
299
|
+
* raw: object
|
|
300
|
+
* }>}
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* // Full song
|
|
304
|
+
* const lyrics = await generateLyrics("Cheerful love song about summer beach");
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* // Edit mode
|
|
308
|
+
* const edited = await generateLyrics("Make it more upbeat", {
|
|
309
|
+
* mode: "edit",
|
|
310
|
+
* lyrics: existingLyrics
|
|
311
|
+
* });
|
|
141
312
|
*/
|
|
142
313
|
async function generateLyrics(prompt, options = {}) {
|
|
143
314
|
const headers = getHeaders();
|
|
@@ -168,20 +339,30 @@ async function generateLyrics(prompt, options = {}) {
|
|
|
168
339
|
INTERNAL IMPLEMENTATION
|
|
169
340
|
============================================================ */
|
|
170
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Internal helper for music generation (used by createMusic and changeMusic).
|
|
344
|
+
* Builds the request body with explicit defaults and calls the API.
|
|
345
|
+
* audio_setting is ALWAYS the fixed value (no user override).
|
|
346
|
+
*
|
|
347
|
+
* @private
|
|
348
|
+
*/
|
|
171
349
|
async function requestMusicInternal(prompt, options = {}) {
|
|
172
350
|
const headers = getHeaders();
|
|
173
351
|
const url = `${BASE_URL}/music_generation`;
|
|
174
352
|
|
|
353
|
+
// Fixed audio_setting — user-provided values are ignored
|
|
354
|
+
const fixedAudioSetting = {
|
|
355
|
+
sample_rate: 44100,
|
|
356
|
+
bitrate: 256000,
|
|
357
|
+
format: 'mp3'
|
|
358
|
+
};
|
|
359
|
+
|
|
175
360
|
const body = {
|
|
176
361
|
model: options.model || 'music-2.6',
|
|
177
362
|
prompt: prompt,
|
|
178
363
|
stream: false, // Streaming is not supported; always false
|
|
179
364
|
output_format: options.output_format || 'url',
|
|
180
|
-
audio_setting:
|
|
181
|
-
sample_rate: 44100,
|
|
182
|
-
bitrate: 256000,
|
|
183
|
-
format: 'mp3'
|
|
184
|
-
},
|
|
365
|
+
audio_setting: fixedAudioSetting,
|
|
185
366
|
lyrics_optimizer: options.lyrics_optimizer ?? false,
|
|
186
367
|
is_instrumental: options.is_instrumental ?? false,
|
|
187
368
|
...options.extra
|
|
@@ -202,11 +383,11 @@ async function requestMusicInternal(prompt, options = {}) {
|
|
|
202
383
|
if (res.status !== 200) {
|
|
203
384
|
throw new Error(`Minimax API error ${res.status}: ${JSON.stringify(res.response)}`);
|
|
204
385
|
}
|
|
205
|
-
|
|
206
386
|
const audioData = res.response?.data?.audio;
|
|
207
387
|
|
|
208
388
|
if (!audioData) {
|
|
209
|
-
|
|
389
|
+
const resStr = JSON.stringify(res.response, null, ' ');
|
|
390
|
+
throw new Error(`No audio data found in data.audio of Minimax response:\n${resStr}`);
|
|
210
391
|
}
|
|
211
392
|
|
|
212
393
|
const localPath = await saveAudioToLocal(audioData);
|
|
@@ -219,12 +400,18 @@ async function requestMusicInternal(prompt, options = {}) {
|
|
|
219
400
|
};
|
|
220
401
|
}
|
|
221
402
|
|
|
403
|
+
/**
|
|
404
|
+
* Internal helper for music cover preprocessing.
|
|
405
|
+
*
|
|
406
|
+
* @private
|
|
407
|
+
*/
|
|
222
408
|
async function preprocessCoverInternal(audioUrl, options = {}) {
|
|
223
409
|
const headers = getHeaders();
|
|
224
410
|
const url = `${BASE_URL}/music_cover_preprocess`;
|
|
225
411
|
|
|
412
|
+
// Model is fixed to 'music-cover' for analyzeMusic
|
|
226
413
|
const body = {
|
|
227
|
-
model:
|
|
414
|
+
model: 'music-cover',
|
|
228
415
|
audio_url: audioUrl,
|
|
229
416
|
...options
|
|
230
417
|
};
|
|
@@ -254,4 +441,4 @@ export {
|
|
|
254
441
|
changeMusic,
|
|
255
442
|
analyzeMusic,
|
|
256
443
|
generateLyrics
|
|
257
|
-
};
|
|
444
|
+
};
|