cdcbaf4cee
平台壳生成完成和失败收口消费 notification.showLocal 新增 HostBridge 草稿通知 payload 与去重模型测试 迁移生成状态纯函数以通过组件 Fast Refresh 约束 更新原生壳方案、HostBridge 协议和共享决策记录
86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import type { CreationWorkShelfKind } from '../custom-world-home/creationWorkShelf';
|
|
import { PLATFORM_TASK_COMPLETION_MESSAGE } from './platformDialogStateModel';
|
|
import {
|
|
buildDraftCompletionDialogSource,
|
|
collectDraftNoticeKeys,
|
|
} from './platformDraftGenerationShelfModel';
|
|
|
|
export type PlatformHostDraftNotification = {
|
|
key: string;
|
|
title: string;
|
|
body: string;
|
|
};
|
|
|
|
export type PlatformHostDraftNotificationSender = (
|
|
notification: Pick<PlatformHostDraftNotification, 'title' | 'body'>,
|
|
) => void | Promise<unknown>;
|
|
|
|
export function buildPlatformHostDraftReadyNotification(
|
|
kind: CreationWorkShelfKind,
|
|
ids: Array<string | null | undefined>,
|
|
): PlatformHostDraftNotification | null {
|
|
const noticeKeys = collectDraftNoticeKeys(kind, ids);
|
|
if (noticeKeys.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const source = buildDraftCompletionDialogSource(kind, ids);
|
|
return {
|
|
key: `draft-ready:${kind}:${source}`,
|
|
title: '生成完成',
|
|
body: `${source} ${PLATFORM_TASK_COMPLETION_MESSAGE}`,
|
|
};
|
|
}
|
|
|
|
export function buildPlatformHostDraftFailureNotification(
|
|
kind: CreationWorkShelfKind,
|
|
ids: Array<string | null | undefined>,
|
|
errorMessage?: string | null,
|
|
): PlatformHostDraftNotification | null {
|
|
const noticeKeys = collectDraftNoticeKeys(kind, ids);
|
|
const normalizedErrorMessage = errorMessage?.trim();
|
|
if (noticeKeys.length === 0 || !normalizedErrorMessage) {
|
|
return null;
|
|
}
|
|
|
|
const source = buildDraftCompletionDialogSource(kind, ids);
|
|
return {
|
|
key: `draft-failed:${kind}:${source}`,
|
|
title: '生成失败',
|
|
body: `${source} ${normalizedErrorMessage}`,
|
|
};
|
|
}
|
|
|
|
export function buildPlatformHostDraftNotificationResetKeys(
|
|
kind: CreationWorkShelfKind,
|
|
ids: Array<string | null | undefined>,
|
|
) {
|
|
const noticeKeys = collectDraftNoticeKeys(kind, ids);
|
|
if (noticeKeys.length === 0) {
|
|
return [];
|
|
}
|
|
|
|
const keySuffix = buildDraftCompletionDialogSource(kind, ids);
|
|
return [
|
|
`draft-ready:${kind}:${keySuffix}`,
|
|
`draft-failed:${kind}:${keySuffix}`,
|
|
];
|
|
}
|
|
|
|
export function sendPlatformHostDraftNotificationOnce(
|
|
sentKeys: Set<string>,
|
|
notification: PlatformHostDraftNotification | null,
|
|
send: PlatformHostDraftNotificationSender,
|
|
) {
|
|
if (!notification || sentKeys.has(notification.key)) {
|
|
return false;
|
|
}
|
|
|
|
sentKeys.add(notification.key);
|
|
void send({
|
|
title: notification.title,
|
|
body: notification.body,
|
|
});
|
|
return true;
|
|
}
|