Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(music): carry the trigger on router attempts and label prices (#23019)

Rdmclin2934eef0b7522
diff --git a/apps/server/src/routers/async/__tests__/music.test.ts b/apps/server/src/routers/async/__tests__/music.test.ts
index 60696a24878..9b11dfdf956 100644
--- a/apps/server/src/routers/async/__tests__/music.test.ts
+++ b/apps/server/src/routers/async/__tests__/music.test.ts
@@ -153,6 +153,8 @@ describe('musicRouter.createMusic', () => {
},
expect.objectContaining({
callbackUrl: 'https://app.example.com/api/webhooks/music/acme?token=token-1',
+ // The LobeHub router records the request source on the route attempt
+ metadata: { trigger: 'music' },
}),
);
expect(runtime.handlePollMusicStatus).not.toHaveBeenCalled();
diff --git a/apps/server/src/routers/async/music.ts b/apps/server/src/routers/async/music.ts
index 4076a57209a..af252c32050 100644
--- a/apps/server/src/routers/async/music.ts
+++ b/apps/server/src/routers/async/music.ts
@@ -236,7 +236,11 @@ export const musicRouter = router({
try {
submitted = await modelRuntime.createMusic(
{ model: resolvedModelId, params: toRuntimeMusicParams(params) },
- { callbackUrl: callbackUrl.toString(), signal },
+ {
+ callbackUrl: callbackUrl.toString(),
+ metadata: { trigger: RequestTrigger.Music },
+ signal,
+ },
);
} catch (error) {
throw new MusicStageError('submit', error);
diff --git a/locales/en-US/components.json b/locales/en-US/components.json
index 43ff5eb60f7..0a9c68e622d 100644
--- a/locales/en-US/components.json
+++ b/locales/en-US/components.json
@@ -207,6 +207,7 @@
"ModelSwitchPanel.detail.pricing.suffix.millionCharacters": "/M chars",
"ModelSwitchPanel.detail.pricing.suffix.millionTokens": "/M tokens",
"ModelSwitchPanel.detail.pricing.suffix.second": "/s",
+ "ModelSwitchPanel.detail.pricing.suffix.song": "/song",
"ModelSwitchPanel.detail.pricing.unit.audioInput": "Audio Input",
"ModelSwitchPanel.detail.pricing.unit.audioInput_cacheRead": "Audio Input (Cached)",
"ModelSwitchPanel.detail.pricing.unit.audioOutput": "Audio Output",
@@ -214,6 +215,7 @@
"ModelSwitchPanel.detail.pricing.unit.imageInput": "Image Input",
"ModelSwitchPanel.detail.pricing.unit.imageInput_cacheRead": "Image Input (Cached)",
"ModelSwitchPanel.detail.pricing.unit.imageOutput": "Image Output",
+ "ModelSwitchPanel.detail.pricing.unit.musicGeneration": "Music Generation",
"ModelSwitchPanel.detail.pricing.unit.textInput": "Input",
"ModelSwitchPanel.detail.pricing.unit.textInput_cacheRead": "Input (Cached)",
"ModelSwitchPanel.detail.pricing.unit.textInput_cacheWrite": "Input (Cache Write)",
diff --git a/locales/zh-CN/components.json b/locales/zh-CN/components.json
index 3995fc25431..51af0baaea1 100644
--- a/locales/zh-CN/components.json
+++ b/locales/zh-CN/components.json
@@ -207,6 +207,7 @@
"ModelSwitchPanel.detail.pricing.suffix.millionCharacters": "/百万字符",
"ModelSwitchPanel.detail.pricing.suffix.millionTokens": "/百万 token",
"ModelSwitchPanel.detail.pricing.suffix.second": "/秒",
+ "ModelSwitchPanel.detail.pricing.suffix.song": "/首",
"ModelSwitchPanel.detail.pricing.unit.audioInput": "音频输入",
"ModelSwitchPanel.detail.pricing.unit.audioInput_cacheRead": "音频输入(缓存读取)",
"ModelSwitchPanel.detail.pricing.unit.audioOutput": "音频输出",
@@ -214,6 +215,7 @@
"ModelSwitchPanel.detail.pricing.unit.imageInput": "图像输入",
"ModelSwitchPanel.detail.pricing.unit.imageInput_cacheRead": "图像输入(缓存读取)",
"ModelSwitchPanel.detail.pricing.unit.imageOutput": "图像输出",
+ "ModelSwitchPanel.detail.pricing.unit.musicGeneration": "音乐生成",
"ModelSwitchPanel.detail.pricing.unit.textInput": "输入",
"ModelSwitchPanel.detail.pricing.unit.textInput_cacheRead": "输入(缓存读取)",
"ModelSwitchPanel.detail.pricing.unit.textInput_cacheWrite": "输入(缓存写入)",
diff --git a/packages/locales/src/default/components.ts b/packages/locales/src/default/components.ts
index 0f5235cbc12..0dd6c92d425 100644
--- a/packages/locales/src/default/components.ts
+++ b/packages/locales/src/default/components.ts
@@ -238,6 +238,7 @@ export default {
'ModelSwitchPanel.detail.pricing.suffix.millionCharacters': '/M chars',
'ModelSwitchPanel.detail.pricing.suffix.millionTokens': '/M tokens',
'ModelSwitchPanel.detail.pricing.suffix.second': '/s',
+ 'ModelSwitchPanel.detail.pricing.suffix.song': '/song',
'ModelSwitchPanel.detail.pricing.unit.audioInput': 'Audio Input',
'ModelSwitchPanel.detail.pricing.unit.audioInput_cacheRead': 'Audio Input (Cached)',
'ModelSwitchPanel.detail.pricing.unit.audioOutput': 'Audio Output',
@@ -245,6 +246,7 @@ export default {
'ModelSwitchPanel.detail.pricing.unit.imageInput': 'Image Input',
'ModelSwitchPanel.detail.pricing.unit.imageInput_cacheRead': 'Image Input (Cached)',
'ModelSwitchPanel.detail.pricing.unit.imageOutput': 'Image Output',
+ 'ModelSwitchPanel.detail.pricing.unit.musicGeneration': 'Music Generation',
'ModelSwitchPanel.detail.pricing.unit.textInput': 'Input',
'ModelSwitchPanel.detail.pricing.unit.textInput_cacheRead': 'Input (Cached)',
'ModelSwitchPanel.detail.pricing.unit.textInput_cacheWrite': 'Input (Cache Write)',
diff --git a/packages/model-runtime/src/core/RouterRuntime/createRuntime.music.test.ts b/packages/model-runtime/src/core/RouterRuntime/createRuntime.music.test.ts
index 1854f6c2db9..dfc566f77cd 100644
--- a/packages/model-runtime/src/core/RouterRuntime/createRuntime.music.test.ts
+++ b/packages/model-runtime/src/core/RouterRuntime/createRuntime.music.test.ts
@@ -293,6 +293,38 @@ describe('createRouterRuntime music', () => {
);
});
+ it('carries the request trigger so a lobehub route attempt passes the dev context guard', async () => {
+ vi.stubEnv('NODE_ENV', 'development');
+ const createMusic = vi.fn(async () => ({ inferenceId: 'task-1', status: 'pending' as const }));
+
+ class MockMusicRuntime implements LobeRuntimeAI {
+ createMusic = createMusic;
+ }
+
+ const Runtime = createRouterRuntime({
+ id: 'lobehub',
+ routers: [
+ {
+ apiType: 'fal',
+ models: ['song-model'],
+ options: [{ apiKey: 'channel-a', id: 'a' }],
+ runtime: MockMusicRuntime as any,
+ },
+ ],
+ });
+ const runtime = new Runtime({ userId: 'user-1' });
+
+ // Without a trigger the development guard rejects the attempt before it reaches the channel
+ await expect(runtime.createMusic(payload)).rejects.toThrow('"missingTrigger":true');
+ expect(createMusic).not.toHaveBeenCalled();
+
+ await expect(runtime.createMusic(payload, { metadata: { trigger: 'music' } })).resolves.toEqual(
+ expect.objectContaining({ inferenceId: 'task-1' }),
+ );
+ expect(createMusic).toHaveBeenCalledTimes(1);
+ vi.unstubAllEnvs();
+ });
+
it('reports runtimes without music support', async () => {
class ChatOnlyRuntime implements LobeRuntimeAI {}
diff --git a/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts b/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
index 1ffa2b4a23b..2bf6c60a988 100644
--- a/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
+++ b/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
@@ -549,7 +549,7 @@ export const createRouterRuntime = ({
async createMusic(payload: CreateMusicPayload, options?: CreateMusicOptions) {
// One attempt on the first sorted channel, through the normal route lifecycle so attempt
// reporting and `onRouteSuccess` affinity still apply; music never falls back.
- const routeContext = { method: 'createMusic' as const };
+ const routeContext = { metadata: options?.metadata, method: 'createMusic' as const };
const { matchedRouter: router, routerOptions } = await selectRouteOptions(
this.deps,
payload.model,
diff --git a/packages/model-runtime/src/types/music.ts b/packages/model-runtime/src/types/music.ts
index 7d8f16f217c..fd2bf383bc8 100644
--- a/packages/model-runtime/src/types/music.ts
+++ b/packages/model-runtime/src/types/music.ts
@@ -59,6 +59,8 @@ export interface MusicPollingOptions {
export interface CreateMusicOptions extends MusicPollingOptions {
/** Webhook the provider calls on completion. Some providers require it even when polling. */
callbackUrl?: string;
+ /** Request metadata (e.g. `trigger`) the router records on the route attempt. */
+ metadata?: Record<string, unknown>;
signal?: AbortSignal;
/**
* For asynchronous providers: poll until the task finishes and return the tracks instead
diff --git a/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.test.ts b/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.test.ts
index cd5f7adb1f4..777862ccae0 100644
--- a/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.test.ts
+++ b/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.test.ts
@@ -170,6 +170,8 @@ describe('useModelDetailPanel', () => {
});
expect(result.current.hasCachedInputPricing).toBe(true);
expect(result.current.getUnitPriceSuffix('millionTokens')).toBe('/M tokens');
+ // Per-song music prices need their unit, or "$0.174" reads as a flat fee
+ expect(result.current.getUnitPriceSuffix('song')).toBe('/song');
});
it('formats original unit prices for tiered and lookup units', () => {
diff --git a/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.ts b/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.ts
index 4a7ddd93bf4..75e18ead84c 100644
--- a/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.ts
+++ b/src/features/ModelSwitchPanel/hooks/useModelDetailPanel.ts
@@ -166,6 +166,7 @@ const UNIT_LABEL_MAP: Record<string, string> = {
millionCharacters: '/M chars',
millionTokens: '/M tokens',
second: '/s',
+ song: '/song',
};
const formatUnitRate = (unit: PricingUnit, currency?: ModelPriceCurrency): FormattedUnitPrice => {