refactor: 收口剩余草稿打开 intent

This commit is contained in:
2026-06-04 06:12:26 +08:00
parent e570d50e9f
commit c93b8fb570
6 changed files with 422 additions and 41 deletions
@@ -148,6 +148,61 @@ export type Match3DDraftOpenIntent =
noticeKeys: string[];
};
export type BigFishDraftOpenIntent =
| {
type: 'active-generation';
noticeKeys: string[];
sourceSessionId: string;
}
| {
type: 'restore-draft';
noticeKeys: string[];
sourceSessionId: string;
};
export type SquareHoleDraftOpenIntent =
| {
type: 'open-published-detail';
noticeKeys: string[];
}
| {
type: 'missing-session';
noticeKeys: string[];
errorMessage: string;
}
| {
type: 'active-generation';
noticeKeys: string[];
sourceSessionId: string;
}
| {
type: 'restore-draft';
noticeKeys: string[];
sourceSessionId: string;
shouldClearGenerationState: boolean;
};
export type VisualNovelDraftOpenIntent =
| {
type: 'open-published-detail';
noticeKeys: string[];
}
| {
type: 'active-generation';
noticeKeys: string[];
profileId: string;
}
| {
type: 'current-result';
noticeKeys: string[];
profileId: string;
}
| {
type: 'load-detail';
noticeKeys: string[];
profileId: string;
};
export function buildDraftNoticeKey(
kind: CreationWorkShelfKind,
id: string,
@@ -433,6 +488,29 @@ export function buildMatch3DDraftOpenNoticeKeys(item: Match3DWorkSummary) {
]);
}
export function buildBigFishDraftOpenNoticeKeys(item: BigFishWorkSummary) {
return collectDraftNoticeKeys('big-fish', [
item.workId,
item.sourceSessionId,
]);
}
export function buildSquareHoleDraftOpenNoticeKeys(
item: SquareHoleWorkSummary,
) {
return collectDraftNoticeKeys('square-hole', [
item.workId,
item.profileId,
item.sourceSessionId,
]);
}
export function buildVisualNovelDraftOpenNoticeKeys(
item: VisualNovelWorkSummary,
) {
return collectDraftNoticeKeys('visual-novel', [item.profileId]);
}
export function resolvePuzzleDraftOpenIntent(params: {
item: PuzzleWorkSummary;
notices: DraftGenerationNoticeMap;
@@ -628,6 +706,117 @@ export function resolveMatch3DDraftOpenIntent(params: {
return { type: 'restore-draft', noticeKeys };
}
export function resolveBigFishDraftOpenIntent(params: {
item: BigFishWorkSummary;
activeSessionId?: string | null;
hasActiveGenerationRunning: boolean;
}): BigFishDraftOpenIntent {
const { item, activeSessionId, hasActiveGenerationRunning } = params;
const noticeKeys = buildBigFishDraftOpenNoticeKeys(item);
if (item.sourceSessionId === activeSessionId && hasActiveGenerationRunning) {
return {
type: 'active-generation',
noticeKeys,
sourceSessionId: item.sourceSessionId,
};
}
return {
type: 'restore-draft',
noticeKeys,
sourceSessionId: item.sourceSessionId,
};
}
export function resolveSquareHoleDraftOpenIntent(params: {
item: SquareHoleWorkSummary;
forceDraft?: boolean;
activeSessionId?: string | null;
hasActiveGenerationRunning: boolean;
isGenerationReady: boolean;
}): SquareHoleDraftOpenIntent {
const {
item,
forceDraft = false,
activeSessionId,
hasActiveGenerationRunning,
isGenerationReady,
} = params;
const noticeKeys = buildSquareHoleDraftOpenNoticeKeys(item);
if (item.publicationStatus === 'published' && !forceDraft) {
return { type: 'open-published-detail', noticeKeys };
}
const sourceSessionId = normalizeDraftNoticeId(item.sourceSessionId);
if (!sourceSessionId) {
return {
type: 'missing-session',
noticeKeys,
errorMessage: '这份方洞挑战草稿缺少会话信息,请重新开始创作。',
};
}
if (sourceSessionId === activeSessionId && hasActiveGenerationRunning) {
return {
type: 'active-generation',
noticeKeys,
sourceSessionId,
};
}
return {
type: 'restore-draft',
noticeKeys,
sourceSessionId,
shouldClearGenerationState: !isGenerationReady,
};
}
export function resolveVisualNovelDraftOpenIntent(params: {
item: VisualNovelWorkSummary;
forceDraft?: boolean;
activeSessionId?: string | null;
hasActiveGenerationRunning: boolean;
hasActiveSessionDraft: boolean;
}): VisualNovelDraftOpenIntent {
const {
item,
forceDraft = false,
activeSessionId,
hasActiveGenerationRunning,
hasActiveSessionDraft,
} = params;
const noticeKeys = buildVisualNovelDraftOpenNoticeKeys(item);
if (item.publishStatus === 'published' && !forceDraft) {
return { type: 'open-published-detail', noticeKeys };
}
const isCurrentSession = item.profileId === activeSessionId;
if (isCurrentSession && hasActiveGenerationRunning) {
return {
type: 'active-generation',
noticeKeys,
profileId: item.profileId,
};
}
if (isCurrentSession && hasActiveSessionDraft) {
return {
type: 'current-result',
noticeKeys,
profileId: item.profileId,
};
}
return {
type: 'load-detail',
noticeKeys,
profileId: item.profileId,
};
}
export function buildCreationWorkShelfRuntimeState(params: {
item: CreationWorkShelfItem;
notices: DraftGenerationNoticeMap;