合并主分支

解决简单冲突
This commit is contained in:
2026-08-06 18:54:32 +08:00
55 changed files with 11232 additions and 270 deletions
@@ -1,3 +1,7 @@
import type {
BackgroundMusicPromptAssistRequest,
BackgroundMusicPromptAssistResponse,
} from '../../../packages/shared/src/contracts/editorAudio';
import type { ExternalGenerationJobStatusRecord } from '../../../packages/shared/src/contracts/externalGeneration';
import { requestJson } from '../apiClient';
import { EDITOR_GENERATION_REQUEST_RETRY_OPTIONS } from './editorRetryOptions';
@@ -34,6 +38,15 @@ const EDITOR_SOUND_EFFECT_GENERATION_API =
'/api/editor/audios/sound-effects/generations';
const EDITOR_BACKGROUND_MUSIC_GENERATION_API =
'/api/editor/audios/background-music/generations';
const EDITOR_BACKGROUND_MUSIC_PROMPT_COMPLETION_API =
'/api/editor/audios/background-music/prompts/completions';
const EDITOR_BACKGROUND_MUSIC_PROMPT_SIMPLIFICATION_API =
'/api/editor/audios/background-music/prompts/simplifications';
/**
* 覆盖简化两个业务语义轮加单轮 transport retry 的服务端预算,同时为浏览器到 BFF 的
* 悬挂连接提供有界退出;超时后走既有失败路径恢复 idle,不写回候选。
*/
export const EDITOR_BACKGROUND_MUSIC_PROMPT_ASSIST_TIMEOUT_MS = 180_000;
const EDITOR_GENERATION_PRICING_API = '/api/editor/generation-pricing';
const EDITOR_IMAGE_MODEL_NANOBANANA2 = 'gemini-3.1-flash-image-preview';
const EDITOR_IMAGE_REFERENCE_LIMIT = 5;
@@ -620,6 +633,10 @@ export type EditorBackgroundMusicGenerationInput = {
assetLabel?: string | null;
};
export type EditorBackgroundMusicPromptAssistOptions = {
signal?: AbortSignal;
};
export type EditorAudioGenerationResult = {
audioSrc: string;
objectKey?: string | null;
@@ -1487,6 +1504,51 @@ export async function generateEditorSoundEffect(
);
}
function requestEditorBackgroundMusicPromptAssist(
path: string,
input: BackgroundMusicPromptAssistRequest,
fallbackMessage: string,
options: EditorBackgroundMusicPromptAssistOptions,
) {
return requestJson<BackgroundMusicPromptAssistResponse>(
path,
{
...jsonRequest('POST', {
currentPrompt: input.currentPrompt,
}),
signal: options.signal,
},
fallbackMessage,
{
timeoutMs: EDITOR_BACKGROUND_MUSIC_PROMPT_ASSIST_TIMEOUT_MS,
},
);
}
export function completeEditorBackgroundMusicPrompt(
input: BackgroundMusicPromptAssistRequest,
options: EditorBackgroundMusicPromptAssistOptions = {},
) {
return requestEditorBackgroundMusicPromptAssist(
EDITOR_BACKGROUND_MUSIC_PROMPT_COMPLETION_API,
input,
'AI 补全背景音乐提示词失败',
options,
);
}
export function simplifyEditorBackgroundMusicPrompt(
input: BackgroundMusicPromptAssistRequest,
options: EditorBackgroundMusicPromptAssistOptions = {},
) {
return requestEditorBackgroundMusicPromptAssist(
EDITOR_BACKGROUND_MUSIC_PROMPT_SIMPLIFICATION_API,
input,
'简化背景音乐提示词失败',
options,
);
}
export async function generateEditorBackgroundMusic(
input: EditorBackgroundMusicGenerationInput,
) {
@@ -1508,7 +1570,6 @@ export async function generateEditorBackgroundMusic(
'生成游戏背景音乐失败',
{
timeoutMs: 1_200_000,
retry: EDITOR_GENERATION_REQUEST_RETRY_OPTIONS,
},
);
}