fix(short-drama-agent-front): 修复代码格式检查问题
This commit is contained in:
1 parent
81d6a85260
commit
48fce3975f
87 files changed
+5714
-1436
No files matched your search
+14
-5
@@ -73,12 +73,21 @@ export function nodeLabel(name?: string): string {
|
||||
*/
|
||||
export function workflowLabel(name?: string): string {
|
||||
const labels: Record<string, string> = {
|
||||
'create-drama': '剧本创作', breakdown: '剧本拆解', 'visual-style': '视觉风格',
|
||||
'subject-identity': '主体身份', 'subject-images': '形态图片', storyboard: '分镜设计', production: '镜头制作',
|
||||
'storyboard-direction': '镜头设计', 'storyboard-visual-state': '画面状态', 'video-prompt': '视频描述',
|
||||
'keyframe-generation': '首帧生成', 'keyframe-quality': '首帧检查', 'video-quality': '视频检查'
|
||||
'create-drama': '剧本创作',
|
||||
breakdown: '剧本拆解',
|
||||
'visual-style': '视觉风格',
|
||||
'subject-identity': '主体身份',
|
||||
'subject-images': '形态图片',
|
||||
storyboard: '分镜设计',
|
||||
production: '镜头制作',
|
||||
'storyboard-direction': '镜头设计',
|
||||
'storyboard-visual-state': '画面状态',
|
||||
'video-prompt': '视频描述',
|
||||
'keyframe-generation': '首帧生成',
|
||||
'keyframe-quality': '首帧检查',
|
||||
'video-quality': '视频检查'
|
||||
}
|
||||
return name ? labels[name] ?? userFacingText(name, '其他制作任务') : '未标注制作任务'
|
||||
return name ? (labels[name] ?? userFacingText(name, '其他制作任务')) : '未标注制作任务'
|
||||
}
|
||||
|
||||
/** 下载纯文本或 JSON,不将模型内容作为 HTML 渲染。 */
|
||||
|
||||
+10
-2
@@ -102,9 +102,17 @@ export async function optionalResource<T>(promise: Promise<T>): Promise<T | null
|
||||
export function errorMessage(error: unknown): string {
|
||||
const fallback = '操作失败,请刷新后重试。'
|
||||
if (error instanceof ApiError) {
|
||||
const configurationMessage = configurationErrorText(error.code) ?? configurationErrorText(isRecord(error.details) ? error.details.code : undefined)
|
||||
const configurationMessage =
|
||||
configurationErrorText(error.code) ??
|
||||
configurationErrorText(isRecord(error.details) ? error.details.code : undefined)
|
||||
if (configurationMessage) return configurationMessage
|
||||
return [...new Set([userFacingText(error.message, fallback), ...businessErrorMessages(error.details)].filter(Boolean))].join(';') || fallback
|
||||
return (
|
||||
[
|
||||
...new Set(
|
||||
[userFacingText(error.message, fallback), ...businessErrorMessages(error.details)].filter(Boolean)
|
||||
)
|
||||
].join(';') || fallback
|
||||
)
|
||||
}
|
||||
return error instanceof Error ? userFacingText(error.message, fallback) || fallback : fallback
|
||||
}
|
||||
+74
-29
@@ -1,9 +1,11 @@
|
||||
/** 项目配置的确定性业务状态说明,不将配置限制显示为系统故障。 */
|
||||
const configurationErrorLabels: Record<string, string> = {
|
||||
CREATIVE_PROFILE_REQUIRED: '请先保存项目生成配置,再重新检查制作计划。',
|
||||
CANVAS_CHANGE_REQUIRES_REVALIDATION: '已有分镜,暂时不能直接修改作品画幅。需要先重新核对镜头设计和相关素材,当前配置未保存。',
|
||||
CANVAS_CHANGE_REQUIRES_REVALIDATION:
|
||||
'已有分镜,暂时不能直接修改作品画幅。需要先重新核对镜头设计和相关素材,当前配置未保存。',
|
||||
CREATIVE_PROFILE_ACTIVE_WORKFLOW: '项目仍有任务进行中,请等待任务结束后再保存生成配置。',
|
||||
GENERATION_CONFIG_CHANGE_REQUIRES_REVALIDATION: '已有首帧或视频,暂时不能直接修改相关模型或参数。需要先处理现有素材的更新关系,当前配置未保存。'
|
||||
GENERATION_CONFIG_CHANGE_REQUIRES_REVALIDATION:
|
||||
'已有首帧或视频,暂时不能直接修改相关模型或参数。需要先处理现有素材的更新关系,当前配置未保存。'
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -12,35 +14,66 @@ const configurationErrorLabels: Record<string, string> = {
|
||||
* @returns 对应中文操作说明,非配置业务码时返回 null
|
||||
*/
|
||||
export function configurationErrorText(code: unknown): string | null {
|
||||
return typeof code === 'string' ? configurationErrorLabels[code] ?? null : null
|
||||
return typeof code === 'string' ? (configurationErrorLabels[code] ?? null) : null
|
||||
}
|
||||
|
||||
/** 系统说明中允许统一翻译的术语;不处理剧本、提示词正文、文件名或请求字段。 */
|
||||
const terms: [RegExp, string][] = [
|
||||
[/\bneeds_review\b/g, '需人工核对'], [/\binsufficient_evidence\b/g, '证据尚不完整'], [/\bblocked\b/g, '存在待处理问题'],
|
||||
[/由项目 Creative Profile Canvas 决定;单次图片或视频生成不可覆盖。/g, '使用项目配置中的画面比例,单次生成时不能单独更改。'],
|
||||
[/\bneeds_review\b/g, '需人工核对'],
|
||||
[/\binsufficient_evidence\b/g, '证据尚不完整'],
|
||||
[/\bblocked\b/g, '存在待处理问题'],
|
||||
[
|
||||
/由项目 Creative Profile Canvas 决定;单次图片或视频生成不可覆盖。/g,
|
||||
'使用项目配置中的画面比例,单次生成时不能单独更改。'
|
||||
],
|
||||
[/业务层必须显式选择,不能依赖 Provider 默认值。/g, '请明确选择是否开启。'],
|
||||
[/业务默认关闭/g, '默认关闭'], [/业务参考图/g, '参考图'],
|
||||
[/业务默认关闭/g, '默认关闭'],
|
||||
[/业务参考图/g, '参考图'],
|
||||
[/Creative Profile Canvas/gi, '项目画幅设置'],
|
||||
[/Prompt\s*扩写模式/gi, '画面描述补充方式'], [/Prompt\s*扩写/gi, '自动补充画面描述'],
|
||||
[/Storyboard Shot/gi, '分镜镜头'], [/Primary Keyframe/gi, '首帧'],
|
||||
[/\bBreakdown\b/gi, '剧本拆解'], [/\bKeyframe\b/gi, '首帧'],
|
||||
[/Creative Profile/gi, '项目生成配置'], [/Visual Style/gi, '视觉风格'],
|
||||
[/GenerationSpec/gi, '镜头生成方案'], [/generationPrompt/gi, '正式生图提示词'],
|
||||
[/VisualState/gi, '画面即时状态'], [/\bSubjectRefs?\b/gi, '主体引用'],
|
||||
[/\bSubjectForms?\b/gi, '主体形态'], [/Identity Anchor/gi, '身份母版'],
|
||||
[/Motion Plan/gi, '动作设计'], [/Video Prompt/gi, '视频提示词'],
|
||||
[/Negative\s*prompt/gi, '避免出现的内容'], [/Episode Shots?/gi, '单集镜头'],
|
||||
[/checkpoints?/gi, '保存记录'], [/Storyboard/gi, '分镜'],
|
||||
[/\bDirection\b/gi, '镜头设计'], [/\bVisual Form\b/gi, '视觉形态'],
|
||||
[/\bForm\b/g, '形态'], [/\bBeat\b/gi, '剧情段落'], [/\bShot\b/gi, '镜头'],
|
||||
[/\bProvider\b/gi, '模型服务'], [/\bPrompt\b/gi, '提示词'],
|
||||
[/\bThinking\b/gi, '深度思考'], [/\bLLM\b/g, '文字生成模型'], [/\bVision\b/g, '画面检查'], [/\bJSON\b/gi, '数据格式'],
|
||||
[/\bexecutionId\b/g, '任务编号'], [/\bID\b/g, '编号'], [/\bAPI\b/g, '服务'],
|
||||
[/\bbackend\b|后端/gi, '系统'], [/\bfrontend\b|前端/gi, '页面'],
|
||||
[/\bcompleted\b/g, '已完成'], [/下游资产/g, '后续制作成果'],
|
||||
[/后台状态/g, '任务状态'], [/入库/g, '保存'], [/指纹/g, '内容版本'],
|
||||
[/^auto$/i, '自动'], [/^direct$/i, '直接增强'], [/^agent$/i, '智能补充']
|
||||
[/Prompt\s*扩写模式/gi, '画面描述补充方式'],
|
||||
[/Prompt\s*扩写/gi, '自动补充画面描述'],
|
||||
[/Storyboard Shot/gi, '分镜镜头'],
|
||||
[/Primary Keyframe/gi, '首帧'],
|
||||
[/\bBreakdown\b/gi, '剧本拆解'],
|
||||
[/\bKeyframe\b/gi, '首帧'],
|
||||
[/Creative Profile/gi, '项目生成配置'],
|
||||
[/Visual Style/gi, '视觉风格'],
|
||||
[/GenerationSpec/gi, '镜头生成方案'],
|
||||
[/generationPrompt/gi, '正式生图提示词'],
|
||||
[/VisualState/gi, '画面即时状态'],
|
||||
[/\bSubjectRefs?\b/gi, '主体引用'],
|
||||
[/\bSubjectForms?\b/gi, '主体形态'],
|
||||
[/Identity Anchor/gi, '身份母版'],
|
||||
[/Motion Plan/gi, '动作设计'],
|
||||
[/Video Prompt/gi, '视频提示词'],
|
||||
[/Negative\s*prompt/gi, '避免出现的内容'],
|
||||
[/Episode Shots?/gi, '单集镜头'],
|
||||
[/checkpoints?/gi, '保存记录'],
|
||||
[/Storyboard/gi, '分镜'],
|
||||
[/\bDirection\b/gi, '镜头设计'],
|
||||
[/\bVisual Form\b/gi, '视觉形态'],
|
||||
[/\bForm\b/g, '形态'],
|
||||
[/\bBeat\b/gi, '剧情段落'],
|
||||
[/\bShot\b/gi, '镜头'],
|
||||
[/\bProvider\b/gi, '模型服务'],
|
||||
[/\bPrompt\b/gi, '提示词'],
|
||||
[/\bThinking\b/gi, '深度思考'],
|
||||
[/\bLLM\b/g, '文字生成模型'],
|
||||
[/\bVision\b/g, '画面检查'],
|
||||
[/\bJSON\b/gi, '数据格式'],
|
||||
[/\bexecutionId\b/g, '任务编号'],
|
||||
[/\bID\b/g, '编号'],
|
||||
[/\bAPI\b/g, '服务'],
|
||||
[/\bbackend\b|后端/gi, '系统'],
|
||||
[/\bfrontend\b|前端/gi, '页面'],
|
||||
[/\bcompleted\b/g, '已完成'],
|
||||
[/下游资产/g, '后续制作成果'],
|
||||
[/后台状态/g, '任务状态'],
|
||||
[/入库/g, '保存'],
|
||||
[/指纹/g, '内容版本'],
|
||||
[/^auto$/i, '自动'],
|
||||
[/^direct$/i, '直接增强'],
|
||||
[/^agent$/i, '智能补充']
|
||||
]
|
||||
|
||||
/**
|
||||
@@ -61,13 +94,23 @@ export function userFacingText(value: string | null | undefined, fallback = '暂
|
||||
QUALITY_POLICY_SNAPSHOT_STALE: '分镜与质量规则版本不一致,请核对最新拆解结果。',
|
||||
STORYBOARD_SOURCE_MISMATCH: '镜头与已提交分镜不一致,请刷新后核对。'
|
||||
}
|
||||
const code = Object.keys(codeLabels).find(key => text === key || text.startsWith(`${key}:`) || text.startsWith(`${key}:`))
|
||||
if (code) text = text.slice(code.length).replace(/^[::]\s*/, '').trim() || codeLabels[code]!
|
||||
const code = Object.keys(codeLabels).find(
|
||||
key => text === key || text.startsWith(`${key}:`) || text.startsWith(`${key}:`)
|
||||
)
|
||||
if (code)
|
||||
text =
|
||||
text
|
||||
.slice(code.length)
|
||||
.replace(/^[::]\s*/, '')
|
||||
.trim() || codeLabels[code]!
|
||||
|
||||
if (!text) return ''
|
||||
if (/fetch failed|failed to fetch|network error|ECONNREFUSED|ETIMEDOUT/i.test(text))
|
||||
return '暂时无法连接服务,请检查网络后重试;已提交的任务可能仍在运行。'
|
||||
if (/PrismaClient|TypeError:|ReferenceError:|SyntaxError:|\bat \S+ \([^)]*:\d+:\d+\)|SELECT\s+.+\s+FROM/i.test(text)) return fallback
|
||||
if (
|
||||
/PrismaClient|TypeError:|ReferenceError:|SyntaxError:|\bat \S+ \([^)]*:\d+:\d+\)|SELECT\s+.+\s+FROM/i.test(text)
|
||||
)
|
||||
return fallback
|
||||
for (const [pattern, label] of terms) text = text.replace(pattern, label)
|
||||
return /[\u4e00-\u9fff]/.test(text) ? text : fallback
|
||||
}
|
||||
@@ -88,7 +131,9 @@ export function businessErrorMessages(details: unknown): string[] {
|
||||
if (Array.isArray(value)) return value.slice(0, 8).flatMap(item => collect(item, depth + 1))
|
||||
if (!value || typeof value !== 'object') return []
|
||||
const record = value as Record<string, unknown>
|
||||
const result = ['message', 'reason', 'issues', 'errors', 'formErrors'].flatMap(key => collect(record[key], depth + 1))
|
||||
const result = ['message', 'reason', 'issues', 'errors', 'formErrors'].flatMap(key =>
|
||||
collect(record[key], depth + 1)
|
||||
)
|
||||
if (record.fieldErrors && typeof record.fieldErrors === 'object')
|
||||
result.push(...Object.values(record.fieldErrors).flatMap(item => collect(item, depth + 1)))
|
||||
return result
|
||||
|
||||
Reference in new issue
Block a user