73a17193d4
将 external_generation_job 扩展为含价格、确认时间、退款流水和事件审计的正式生成任务事实源 新增外部生成任务列表与确认 BFF,并让平台入口按后端任务补弹完成或失败提示 保护画布生成队列超时、快照回写和自动保存覆盖场景 将 worker 计费退款流水写入 externalGenerationJobId,并补充冷备份后 worker/controller 恢复守护
87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import type { PlatformErrorDialogPayload } from './PlatformErrorDialog';
|
|
import type { PlatformTaskCompletionDialogPayload } from './PlatformTaskCompletionDialog';
|
|
|
|
export type PlatformErrorDialogState = PlatformErrorDialogPayload & {
|
|
key: string;
|
|
};
|
|
|
|
export type PlatformTaskFailureDialogState = PlatformErrorDialogState & {
|
|
failedAtMs: number;
|
|
};
|
|
|
|
export type PlatformTaskCompletionDialogState =
|
|
PlatformTaskCompletionDialogPayload & {
|
|
key: string;
|
|
completedAtMs: number | null;
|
|
taskJobIds?: string[];
|
|
};
|
|
|
|
export type PlatformDialogCandidate = {
|
|
key: string;
|
|
source: string;
|
|
message: string | null | undefined;
|
|
};
|
|
|
|
export const PLATFORM_TASK_COMPLETION_MESSAGE =
|
|
'生成任务已完成,可以继续查看草稿。';
|
|
|
|
/** 收口平台弹窗候选的纯状态规则,壳层只负责副作用清理。 */
|
|
export function normalizePlatformDialogMessage(
|
|
message: string | null | undefined,
|
|
) {
|
|
const normalized = message?.trim();
|
|
return normalized ? normalized : null;
|
|
}
|
|
|
|
export function formatPlatformDialogSource(label: string, id?: string | null) {
|
|
const normalizedId = id?.trim();
|
|
return normalizedId ? `${label} ${normalizedId}` : label;
|
|
}
|
|
|
|
export function isBackgroundGenerationStillRunningMessage(message: string) {
|
|
return /仍在后台处理|后台仍在处理|仍在生成|后台生成/u.test(message);
|
|
}
|
|
|
|
export function resolvePlatformErrorDialog(
|
|
candidates: readonly PlatformDialogCandidate[],
|
|
): PlatformErrorDialogState | null {
|
|
for (const candidate of candidates) {
|
|
const message = normalizePlatformDialogMessage(candidate.message);
|
|
if (message) {
|
|
return {
|
|
key: candidate.key,
|
|
source: candidate.source,
|
|
message,
|
|
};
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function buildPlatformErrorDialogDismissKey(
|
|
error: PlatformErrorDialogState | null,
|
|
) {
|
|
return error ? `${error.key}:${error.source}:${error.message}` : null;
|
|
}
|
|
|
|
export function buildPlatformTaskCompletionDialogDismissKey(
|
|
completion: PlatformTaskCompletionDialogState | null,
|
|
) {
|
|
return completion
|
|
? `${completion.key}:${completion.source}:${completion.message}:${completion.completedAtMs ?? 0}:${completion.taskJobIds?.join(',') ?? ''}`
|
|
: null;
|
|
}
|
|
|
|
export function resolveActivePlatformDialog<TDialog>(
|
|
currentDialog: TDialog | null,
|
|
dismissedDialogKey: string | null,
|
|
buildDismissKey: (dialog: TDialog | null) => string | null,
|
|
): TDialog | null {
|
|
const currentDialogDismissKey = buildDismissKey(currentDialog);
|
|
return currentDialogDismissKey &&
|
|
currentDialogDismissKey === dismissedDialogKey
|
|
? null
|
|
: currentDialog;
|
|
}
|