Skip to content

feat(media): add MiniMax music generation - #1242

Open
octo-patch wants to merge 1 commit into
f:mainfrom
octo-patch:octo/20260812-music-generation-tool-recvrXOElW1p5C
Open

feat(media): add MiniMax music generation#1242
octo-patch wants to merge 1 commit into
f:mainfrom
octo-patch:octo/20260812-music-generation-tool-recvrXOElW1p5C

Conversation

@octo-patch

@octo-patch octo-patch commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Reason: Add MiniMax music generation to the existing media generator registry.

  • Register current music generation models for audio output.
  • Route requests to the selected global or China endpoint with configurable lyrics and audio settings.
  • Parse completed URL and hex audio responses and reject unsafe or invalid output.
  • Document the optional runtime configuration and cover the registry, request payloads, formats, and errors with focused tests.

Checks:

  • npm test -- src/__tests__/lib/plugins/media-generators/minimax.test.ts
  • npm run lint -- src/lib/plugins/media-generators/minimax.ts src/lib/plugins/media-generators/index.ts src/__tests__/lib/plugins/media-generators/minimax.test.ts
  • git diff --check

Summary

  • Add MiniMax music generation to the media generator registry.
  • Support global and China endpoints.
  • Support configurable lyrics, audio format, sampling, bitrate, instrumental mode, and watermark settings.
  • Parse URL and hexadecimal audio responses.
  • Validate models, API responses, HTTPS URLs, and hexadecimal data.
  • Add focused tests for configuration, requests, responses, and errors.
  • Document optional MiniMax environment variables.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request adds a MiniMax music-generation plugin. It supports regional endpoints, configurable audio settings, URL and hexadecimal audio responses, validation, plugin registration, and Vitest coverage.

Changes

MiniMax music generation

Layer / File(s) Summary
Music configuration and contracts
.env.example, src/lib/plugins/media-generators/minimax.ts
Defines MiniMax environment settings, supported models and formats, response types, and value parsers.
Generation and response validation
src/lib/plugins/media-generators/minimax.ts, src/__tests__/lib/plugins/media-generators/minimax.test.ts
Submits synchronous requests to global or China endpoints. It validates API responses, HTTPS URLs, and hexadecimal audio. Tests cover request construction, errors, and audio conversion.
Plugin registration and interface integration
src/lib/plugins/media-generators/minimax.ts, src/lib/plugins/media-generators/index.ts, src/__tests__/lib/plugins/media-generators/minimax.test.ts
Exposes the generator through the media-generator interface and adds it to the registered plugin list. Tests verify supported models, formats, registration, and completed results.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Mergeability Score: 🟡 Moderate · up to adff0

The new music-generation path can reject default requests, wait indefinitely on an unresponsive provider, and accept malformed audio response data. These are bounded but concrete correctness and availability risks, so the PR is not merge-ready until they are fixed or explicitly accepted by the owner.

Sequence Diagram(s)

sequenceDiagram
  participant generateMiniMaxMusic
  participant MiniMaxAPI
  participant parseMiniMaxMusicResponse
  generateMiniMaxMusic->>MiniMaxAPI: Submit regional music-generation request
  MiniMaxAPI-->>generateMiniMaxMusic: Return generation response
  generateMiniMaxMusic->>parseMiniMaxMusicResponse: Parse completed audio
  parseMiniMaxMusicResponse-->>generateMiniMaxMusic: Return secure URL or WAV data URL
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding MiniMax music generation to the media generators.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/plugins/media-generators/minimax.ts`:
- Around line 141-148: Add an AbortController and configured timeout around the
MiniMax fetch request, pass its signal to fetch, and abort when the deadline
expires. Ensure the timeout is cleared in a finally block after the request
completes or fails.
- Around line 77-90: Validate that result.data.audio is a string immediately
after confirming completed audio and before the outputFormat URL branch or
hexadecimal checks. Reject arrays and all other non-string values, while
preserving secure URL validation and hex decoding for valid strings; add a
regression test covering a truthy array input.
- Around line 122-136: Update the MiniMax payload construction around the
lyrics, lyricsOptimizer, and isInstrumental variables so every request has a
valid lyric mode: preserve lyrics when provided, otherwise enable
lyrics_optimizer or is_instrumental, or reject the configuration before the
provider request. Keep the existing valid .env.example values at .env.example
lines 72-74 unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b58fd63-341f-48fa-bd25-d697790f58c8

📥 Commits

Reviewing files that changed from the base of the PR and between cfae460 and adff081.

📒 Files selected for processing (4)
  • .env.example
  • src/__tests__/lib/plugins/media-generators/minimax.test.ts
  • src/lib/plugins/media-generators/index.ts
  • src/lib/plugins/media-generators/minimax.ts

Comment on lines +77 to +90
if (result.data?.status !== 2 || !result.data.audio) {
throw new Error("MiniMax music generation did not return completed audio");
}
if (outputFormat === "url") {
return assertSecureAudioUrl(result.data.audio);
}
if (
result.data.audio.length % 2 !== 0 ||
!/^[0-9a-f]+$/i.test(result.data.audio)
) {
throw new Error("MiniMax music generation returned invalid hex audio");
}
const mediaType = audioFormat === "mp3" ? "mpeg" : audioFormat;
return `data:audio/${mediaType};base64,${Buffer.from(result.data.audio, "hex").toString("base64")}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

file="src/lib/plugins/media-generators/minimax.ts"
if [ -f "$file" ]; then
  wc -l "$file"
  ast-grep outline "$file" --view compact || true
  sed -n '1,220p' "$file"
fi

printf '\n--- related symbols ---\n'
rg -n --glob '*.{ts,tsx}' 'assertSecureAudioUrl|parseMiniMaxMusicResponse|MiniMax music generation|audioFormat|outputFormat' src tests 2>/dev/null | head -200 || true

printf '\n--- candidate test files ---\n'
git ls-files | rg '(^|/)(test|tests|__tests__)/|minimax|media-generators' | head -200

Repository: f/prompts.chat

Length of output: 17177


🏁 Script executed:

#!/bin/bash
set -eu

rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
  'assertSecureAudioUrl|parseMiniMaxMusicResponse|MiniMax' . | head -250

Repository: f/prompts.chat

Length of output: 4770


🏁 Script executed:

#!/bin/bash
set -eu
sed -n '1,220p' src/lib/plugins/media-generators/minimax.ts
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
  'function assertSecureAudioUrl|const assertSecureAudioUrl|assertSecureAudioUrl' .

Repository: f/prompts.chat

Length of output: 6493


🏁 Script executed:

#!/bin/bash
set -eu

sed -n '1,190p' src/__tests__/lib/plugins/media-generators/minimax.test.ts

node - <<'JS'
function assertSecureAudioUrl(audio) {
  let url;
  try {
    url = new URL(audio);
  } catch {
    throw new Error("invalid");
  }
  if (url.protocol !== "https:") throw new Error("insecure");
  return audio;
}

const audio = ["https://cdn.example/audio.mp3"];
const returned = assertSecureAudioUrl(audio);
console.log(JSON.stringify({
  inputType: typeof audio,
  coercedUrl: new URL(audio).href,
  returnedIsSameArray: returned === audio,
  returnedType: typeof returned,
  returnedValue: returned,
}));
JS

Repository: f/prompts.chat

Length of output: 4735


Validate data.audio as a string before parsing it.

A truthy array containing an HTTPS URL passes new URL() coercion, then assertSecureAudioUrl returns the array as a value declared string. Reject non-string values before URL or hexadecimal processing, and add a regression test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/plugins/media-generators/minimax.ts` around lines 77 - 90, Validate
that result.data.audio is a string immediately after confirming completed audio
and before the outputFormat URL branch or hexadecimal checks. Reject arrays and
all other non-string values, while preserving secure URL validation and hex
decoding for valid strings; add a regression test covering a truthy array input.

Comment on lines +122 to +136
const lyrics = process.env.MINIMAX_LYRICS?.trim();
const lyricsOptimizer = readBoolean(process.env.MINIMAX_LYRICS_OPTIMIZER);
const isInstrumental = readBoolean(process.env.MINIMAX_IS_INSTRUMENTAL);
const aigcWatermark = readBoolean(process.env.MINIMAX_AIGC_WATERMARK);

const payload: Record<string, unknown> = {
model: request.model,
prompt: request.prompt,
stream: false,
output_format: "url",
audio_setting: audioSetting,
};
if (lyrics) payload.lyrics = lyrics;
if (lyricsOptimizer !== undefined) payload.lyrics_optimizer = lyricsOptimizer;
if (isInstrumental !== undefined) payload.is_instrumental = isInstrumental;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- minimax implementation ---'
sed -n '1,220p' src/lib/plugins/media-generators/minimax.ts

printf '%s\n' '--- environment documentation ---'
sed -n '55,85p' .env.example

printf '%s\n' '--- related request types and call sites ---'
rg -n -S 'GenerationRequest|MINIMAX_LYRICS|lyrics_optimizer|is_instrumental|MiniMax' src .env.example

Repository: f/prompts.chat

Length of output: 13377


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- GenerationRequest definition ---'
sed -n '1,55p' src/lib/plugins/media-generators/types.ts

printf '%s\n' '--- MiniMax tests ---'
sed -n '1,115p' src/__tests__/lib/plugins/media-generators/minimax.test.ts

printf '%s\n' '--- all MiniMax environment references ---'
rg -n -S 'MINIMAX_' --glob '!src/lib/plugins/media-generators/minimax.ts' --glob '!*minimax.test.ts' .

Repository: f/prompts.chat

Length of output: 6903


🌐 Web query:

MiniMax music generation API music_generation lyrics lyrics_optimizer is_instrumental required parameters

💡 Result:

For the MiniMax music generation API, the lyrics, lyrics_optimizer, and is_instrumental parameters work together to determine how a song's content and vocals are generated [1][2][3]. The prompt parameter (describing style, mood, instrumentation, etc.) is generally required for all requests [4][3]. The requirements for the other parameters are as follows: 1. is_instrumental (boolean): When set to true, the model generates instrumental-only music without vocals [4][5][3]. In this mode, lyrics should be omitted, and lyrics_optimizer should generally not be enabled [4][2][3]. 2. lyrics_optimizer (boolean): When set to true and the lyrics field is left empty, the model will automatically generate lyrics based on the provided prompt [1][4][5]. 3. lyrics (string): This field provides specific lyrics for the song [1][2]. - It is required if both is_instrumental and lyrics_optimizer are set to false [2][3]. - It is optional or can be omitted if either is_instrumental is true (for instrumental tracks) or lyrics_optimizer is true (to trigger auto-generation) [1][4][2][3]. In summary, you must provide either specific lyrics, enable lyrics_optimizer for auto-generated lyrics, or set is_instrumental to true to create a track without vocals [4][2][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
import json

def read_boolean(value):
    if value is None:
        return None
    if value == "true":
        return True
    if value == "false":
        return False
    return None

def build_payload(env):
    payload = {
        "model": "music-3.0",
        "prompt": "test prompt",
        "stream": False,
        "output_format": "url",
        "audio_setting": {"format": "mp3"},
    }
    lyrics = env.get("MINIMAX_LYRICS", "").strip()
    lyrics_optimizer = read_boolean(env.get("MINIMAX_LYRICS_OPTIMIZER"))
    is_instrumental = read_boolean(env.get("MINIMAX_IS_INSTRUMENTAL"))
    if lyrics:
        payload["lyrics"] = lyrics
    if lyrics_optimizer is not None:
        payload["lyrics_optimizer"] = lyrics_optimizer
    if is_instrumental is not None:
        payload["is_instrumental"] = is_instrumental
    return payload

cases = {
    "all variables unset": {},
    "documented example": {
        "MINIMAX_LYRICS": "",
        "MINIMAX_LYRICS_OPTIMIZER": "false",
        "MINIMAX_IS_INSTRUMENTAL": "true",
    },
    "automatic lyrics": {
        "MINIMAX_LYRICS_OPTIMIZER": "true",
        "MINIMAX_IS_INSTRUMENTAL": "false",
    },
    "explicit lyrics": {
        "MINIMAX_LYRICS": "[Verse] test",
        "MINIMAX_LYRICS_OPTIMIZER": "false",
        "MINIMAX_IS_INSTRUMENTAL": "false",
    },
}

for name, env in cases.items():
    print(name + ": " + json.dumps(build_payload(env), sort_keys=True))
PY

Repository: f/prompts.chat

Length of output: 911


Set a valid MiniMax lyric mode before sending the request.

When all three lyric variables are unset, the payload contains neither lyrics nor a mode selector. MiniMax requires lyrics, lyrics_optimizer: true, or is_instrumental: true; a default GenerationRequest.prompt request therefore fails. Enable lyrics_optimizer or is_instrumental when lyrics are absent, or reject the configuration before the provider request. The .env.example values are valid when enabled.

📍 Affects 2 files
  • src/lib/plugins/media-generators/minimax.ts#L122-L136 (this comment)
  • .env.example#L72-L74
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/plugins/media-generators/minimax.ts` around lines 122 - 136, Update
the MiniMax payload construction around the lyrics, lyricsOptimizer, and
isInstrumental variables so every request has a valid lyric mode: preserve
lyrics when provided, otherwise enable lyrics_optimizer or is_instrumental, or
reject the configuration before the provider request. Keep the existing valid
.env.example values at .env.example lines 72-74 unchanged.

Comment on lines +141 to +148
const response = await fetch(MINIMAX_MUSIC_CONFIG.endpoints[region], {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu
file="src/lib/plugins/media-generators/minimax.ts"
printf '%s\n' "== outline =="
ast-grep outline "$file" --lang typescript || true
printf '%s\n' "== relevant source =="
cat -n "$file" | sed -n '1,230p'
printf '%s\n' "== related symbols and config =="
rg -n --glob '*.ts' --glob '*.tsx' 'parseMiniMaxMusicResponse|MINIMAX_MUSIC_CONFIG|startGeneration|lyrics_optimizer|instrumental|MiniMax' src

Repository: f/prompts.chat

Length of output: 15737


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '== media generation route =='
cat -n src/app/api/media-generate/route.ts | sed -n '80,135p'
printf '%s\n' '== fetch timeout patterns =='
rg -n --glob '*.ts' --glob '*.tsx' 'AbortController|AbortSignal|setTimeout\(|signal:' src
printf '%s\n' '== MiniMax tests =='
cat -n src/__tests__/lib/plugins/media-generators/minimax.test.ts | sed -n '1,180p'

Repository: f/prompts.chat

Length of output: 14673


🏁 Script executed:

#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path

plugin = Path("src/lib/plugins/media-generators/minimax.ts").read_text()
route = Path("src/app/api/media-generate/route.ts").read_text()

fetch_start = plugin.index("const response = await fetch(")
fetch_end = plugin.index("\n  });", fetch_start) + len("\n  });")
fetch_call = plugin[fetch_start:fetch_end]

assert "signal:" not in fetch_call
assert "AbortController" not in fetch_call
assert "setTimeout" not in fetch_call
assert "await plugin.startGeneration" in route
assert "await db.user.update" in route

print("MiniMax fetch options have no signal, AbortController, or timeout.")
print("The API route awaits startGeneration before the credit update and response.")
PY
printf '%s\n' '== route configuration =='
sed -n '1,82p' src/app/api/media-generate/route.ts

Repository: f/prompts.chat

Length of output: 2468


Add an application timeout to the MiniMax request.

This fetch call has no application-controlled deadline or abort signal. An unresponsive MiniMax endpoint can keep the POST request pending before credit deduction and response. Use an AbortController with a configured timeout, and clear the timer in finally.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/plugins/media-generators/minimax.ts` around lines 141 - 148, Add an
AbortController and configured timeout around the MiniMax fetch request, pass
its signal to fetch, and abort when the deadline expires. Ensure the timeout is
cleared in a finally block after the request completes or fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant