feat: add puzzle and big fish draft generation progress

This commit is contained in:
2026-04-25 15:17:01 +08:00
parent 1b2daf4796
commit 9cb3c6a27e
10 changed files with 898 additions and 33 deletions

View File

@@ -1,4 +1,5 @@
import { AnimatePresence, motion } from 'motion/react';
import { Loader2 } from 'lucide-react';
import { AnimatePresence, motion } from 'motion/react';
import {
lazy,
Suspense,
@@ -9,6 +10,7 @@ import {
useState,
} from 'react';
import type { PublicUserSummary } from '../../../packages/shared/src/contracts/auth';
import type {
BigFishRuntimeSnapshotResponse,
BigFishSessionSnapshotResponse,
@@ -21,6 +23,7 @@ import type {
PuzzleAgentActionRequest,
PuzzleAgentOperationRecord,
} from '../../../packages/shared/src/contracts/puzzleAgentActions';
import type { PuzzleGeneratedImageCandidate } from '../../../packages/shared/src/contracts/puzzleAgentDraft';
import type {
PuzzleAgentSessionSnapshot,
SendPuzzleAgentMessageRequest,
@@ -31,7 +34,6 @@ import type {
CustomWorldGalleryCard,
CustomWorldLibraryEntry,
} from '../../../packages/shared/src/contracts/runtime';
import type { PublicUserSummary } from '../../../packages/shared/src/contracts/auth';
import { buildCustomWorldPlayableCharacters } from '../../data/characterPresets';
import {
getPublicAuthUserByCode,
@@ -43,15 +45,22 @@ import {
getBigFishCreationSession,
streamBigFishCreationMessage,
} from '../../services/big-fish-creation';
import {
deleteBigFishWork,
listBigFishWorks,
} from '../../services/big-fish-works';
import {
startBigFishRuntimeRun,
submitBigFishRuntimeInput,
} from '../../services/big-fish-runtime';
import {
deleteBigFishWork,
listBigFishWorks,
} from '../../services/big-fish-works';
import { readCustomWorldAgentUiState } from '../../services/customWorldAgentUiState';
import {
buildBigFishGenerationAnchorEntries,
buildMiniGameDraftGenerationProgress,
buildPuzzleGenerationAnchorEntries,
createMiniGameDraftGenerationState,
type MiniGameDraftGenerationState,
} from '../../services/miniGameDraftGenerationProgress';
import { getPlatformProfileDashboard } from '../../services/platform-entry';
import {
createPuzzleAgentSession,
@@ -59,18 +68,22 @@ import {
getPuzzleAgentSession,
streamPuzzleAgentMessage,
} from '../../services/puzzle-agent';
import { getPuzzleGalleryDetail } from '../../services/puzzle-gallery';
import {
getPuzzleGalleryDetail,
listPuzzleGallery,
} from '../../services/puzzle-gallery';
import {
advanceLocalPuzzleLevel,
advanceLocalPuzzleLevelWithWork,
dragLocalPuzzlePiece,
startLocalPuzzleRun,
swapLocalPuzzlePieces,
} from '../../services/puzzle-runtime/puzzleLocalRuntime';
import { deletePuzzleWork, listPuzzleWorks } from '../../services/puzzle-works';
import { deleteRpgEntryWorldProfile } from '../../services/rpg-entry';
import { getRpgEntryWorldGalleryDetailByCode } from '../../services/rpg-entry/rpgEntryLibraryClient';
import { deleteRpgCreationAgentSession } from '../../services/rpg-creation';
import { rpgCreationPreviewAdapter } from '../../services/rpg-creation/rpgCreationPreviewAdapter';
import { deleteRpgEntryWorldProfile } from '../../services/rpg-entry';
import { getRpgEntryWorldGalleryDetailByCode } from '../../services/rpg-entry/rpgEntryLibraryClient';
import type { CustomWorldProfile } from '../../types';
import { useAuthUi } from '../auth/AuthUiContext';
import { CustomWorldCreationHub } from '../custom-world-home/CustomWorldCreationHub';
@@ -83,13 +96,13 @@ import { useRpgCreationEnterWorld } from '../rpg-entry/useRpgCreationEnterWorld'
import { useRpgCreationResultAutosave } from '../rpg-entry/useRpgCreationResultAutosave';
import { useRpgCreationSessionController } from '../rpg-entry/useRpgCreationSessionController';
import { PlatformEntryCreationTypeModal } from './PlatformEntryCreationTypeModal';
import type { PlatformCreationTypeId } from './platformEntryCreationTypes';
import { PlatformEntryHomeView } from './PlatformEntryHomeView';
import {
buildCreationHubFallbackItems,
normalizeAgentBackedProfile,
resolveRpgCreationErrorMessage,
} from './platformEntryShared';
import type { PlatformCreationTypeId } from './platformEntryCreationTypes';
import type { PlatformEntryFlowShellProps } from './platformEntryTypes';
import { PlatformEntryWorldDetailView } from './PlatformEntryWorldDetailView';
import { usePlatformEntryBootstrap } from './usePlatformEntryBootstrap';
@@ -101,6 +114,53 @@ type AgentResultPublishGateView = {
publishReady: boolean;
};
function buildPuzzleCandidateWorkSummary(
candidate: PuzzleGeneratedImageCandidate,
session: PuzzleAgentSessionSnapshot,
levelIndex: number,
): PuzzleWorkSummary {
const draft = session.draft;
const nowIso = new Date().toISOString();
return {
workId: `${session.sessionId}-${candidate.candidateId}-level-${levelIndex}-runtime-work`,
profileId: `${session.sessionId}-${candidate.candidateId}-level-${levelIndex}-runtime-profile`,
ownerUserId: 'local-runtime',
sourceSessionId: session.sessionId,
authorDisplayName: '当前草稿',
levelName: draft?.levelName
? `${draft.levelName} · 候选 ${levelIndex}`
: `候选拼图 ${levelIndex}`,
summary: draft?.summary ?? candidate.prompt,
themeTags: draft?.themeTags ?? [],
coverImageSrc: candidate.imageSrc,
coverAssetId: candidate.assetId,
publicationStatus: 'published',
updatedAt: nowIso,
publishedAt: nowIso,
playCount: 0,
publishReady: true,
};
}
function pickPuzzleCandidateForLevel(
candidates: PuzzleGeneratedImageCandidate[],
playedProfileIds: string[],
) {
return candidates.find(
(candidate) =>
candidate.imageSrc &&
!playedProfileIds.some((profileId) =>
profileId.includes(candidate.candidateId),
),
);
}
function pickFreshGeneratedPuzzleCandidate(
candidates: PuzzleGeneratedImageCandidate[],
) {
return candidates.find((candidate) => candidate.imageSrc);
}
type AgentResultBlockerView = {
code?: string;
message: string;
@@ -312,6 +372,8 @@ export function PlatformEntryFlowShellImpl({
const [bigFishError, setBigFishError] = useState<string | null>(null);
const [isBigFishBusy, setIsBigFishBusy] = useState(false);
const [isBigFishLoadingLibrary, setIsBigFishLoadingLibrary] = useState(false);
const [bigFishGenerationState, setBigFishGenerationState] =
useState<MiniGameDraftGenerationState | null>(null);
const [streamingBigFishReplyText, setStreamingBigFishReplyText] =
useState('');
const [isStreamingBigFishReply, setIsStreamingBigFishReply] = useState(false);
@@ -327,6 +389,10 @@ export function PlatformEntryFlowShellImpl({
const [puzzleError, setPuzzleError] = useState<string | null>(null);
const [isPuzzleBusy, setIsPuzzleBusy] = useState(false);
const [isPuzzleLoadingLibrary, setIsPuzzleLoadingLibrary] = useState(false);
const [puzzleGenerationState, setPuzzleGenerationState] =
useState<MiniGameDraftGenerationState | null>(null);
const [isPuzzleNextLevelGenerating, setIsPuzzleNextLevelGenerating] =
useState(false);
const [isSearchingPublicCode, setIsSearchingPublicCode] = useState(false);
const [publicSearchError, setPublicSearchError] = useState<string | null>(null);
const [searchedPublicUser, setSearchedPublicUser] =
@@ -791,6 +857,7 @@ export function PlatformEntryFlowShellImpl({
const leaveBigFishFlow = useCallback(() => {
setBigFishError(null);
setBigFishRun(null);
setBigFishGenerationState(null);
setStreamingBigFishReplyText('');
setIsStreamingBigFishReply(false);
enterCreateTab();
@@ -801,6 +868,8 @@ export function PlatformEntryFlowShellImpl({
setPuzzleError(null);
setPuzzleOperation(null);
setPuzzleRun(null);
setPuzzleGenerationState(null);
setIsPuzzleNextLevelGenerating(false);
setStreamingPuzzleReplyText('');
setIsStreamingPuzzleReply(false);
enterCreateTab();
@@ -913,15 +982,45 @@ export function PlatformEntryFlowShellImpl({
setBigFishError(null);
try {
if (payload.action === 'big_fish_compile_draft') {
setSelectionStage('big-fish-generating');
setBigFishGenerationState(createMiniGameDraftGenerationState('big-fish'));
const { session } = await executeBigFishCreationAction(
bigFishSession.sessionId,
payload,
);
setBigFishSession(session);
setBigFishGenerationState((current) =>
current
? {
...current,
phase: 'ready',
completedAssetCount: session.assetSlots.filter(
(slot) => slot.status === 'ready',
).length,
totalAssetCount: session.assetSlots.length,
}
: current,
);
setSelectionStage('big-fish-result');
return;
}
const { session } = await executeBigFishCreationAction(
bigFishSession.sessionId,
payload,
);
setBigFishSession(session);
if (payload.action === 'big_fish_compile_draft') {
setSelectionStage('big-fish-result');
}
} catch (error) {
setBigFishGenerationState((current) =>
current
? {
...current,
phase: 'failed',
error: resolveBigFishErrorMessage(error, '执行大鱼吃小鱼操作失败。'),
}
: current,
);
setBigFishError(
resolveBigFishErrorMessage(error, '执行大鱼吃小鱼操作失败。'),
);
@@ -947,7 +1046,30 @@ export function PlatformEntryFlowShellImpl({
setPuzzleError(null);
try {
const { operation } = await executePuzzleAgentAction(
if (payload.action === 'compile_puzzle_draft') {
setSelectionStage('puzzle-generating');
setPuzzleGenerationState(createMiniGameDraftGenerationState('puzzle'));
const { operation, session } = await executePuzzleAgentAction(
puzzleSession.sessionId,
payload,
);
setPuzzleOperation(operation);
setPuzzleSession(session);
setPuzzleGenerationState((current) =>
current
? {
...current,
phase: 'ready',
completedAssetCount: 1,
totalAssetCount: 1,
}
: current,
);
setSelectionStage('puzzle-result');
return;
}
const { operation, session } = await executePuzzleAgentAction(
puzzleSession.sessionId,
payload,
);
@@ -957,14 +1079,8 @@ export function PlatformEntryFlowShellImpl({
await refreshPuzzleShelf();
}
const { session } = await getPuzzleAgentSession(
puzzleSession.sessionId,
);
setPuzzleSession(session);
if (payload.action === 'compile_puzzle_draft') {
setSelectionStage('puzzle-result');
}
if (
payload.action === 'publish_puzzle_work' &&
session.publishedProfileId
@@ -976,6 +1092,15 @@ export function PlatformEntryFlowShellImpl({
setSelectionStage('puzzle-gallery-detail');
}
} catch (error) {
setPuzzleGenerationState((current) =>
current
? {
...current,
phase: 'failed',
error: resolvePuzzleErrorMessage(error, '执行拼图操作失败。'),
}
: current,
);
setPuzzleError(resolvePuzzleErrorMessage(error, '执行拼图操作失败。'));
} finally {
setIsPuzzleBusy(false);
@@ -1095,9 +1220,123 @@ export function PlatformEntryFlowShellImpl({
return;
}
const currentLevel = puzzleRun.currentLevel;
if (!currentLevel || currentLevel.status !== 'cleared') {
return;
}
setIsPuzzleBusy(true);
setPuzzleError(null);
setPuzzleRun(advanceLocalPuzzleLevel(puzzleRun));
}, [isPuzzleBusy, puzzleRun]);
try {
const galleryResponse = await listPuzzleGallery();
setPuzzleWorks(galleryResponse.items);
const galleryNext = galleryResponse.items.find(
(item) =>
item.publicationStatus === 'published' &&
item.coverImageSrc &&
!puzzleRun.playedProfileIds.includes(item.profileId),
);
if (galleryNext) {
const { item } = await getPuzzleGalleryDetail(galleryNext.profileId);
setSelectedPuzzleDetail(item);
setPuzzleRun(advanceLocalPuzzleLevelWithWork(puzzleRun, item));
return;
}
const existingCandidate = pickPuzzleCandidateForLevel(
puzzleSession?.draft?.candidates ?? [],
puzzleRun.playedProfileIds,
);
if (existingCandidate && puzzleSession) {
setPuzzleRun(
advanceLocalPuzzleLevelWithWork(
puzzleRun,
buildPuzzleCandidateWorkSummary(
existingCandidate,
puzzleSession,
puzzleRun.currentLevelIndex + 1,
),
),
);
return;
}
if (!puzzleSession?.draft) {
const sourceSessionId = selectedPuzzleDetail?.sourceSessionId?.trim();
if (sourceSessionId) {
const { session } = await getPuzzleAgentSession(sourceSessionId);
setPuzzleSession(session);
if (session.draft) {
setIsPuzzleNextLevelGenerating(true);
const response = await executePuzzleAgentAction(session.sessionId, {
action: 'generate_puzzle_images',
candidateCount: 2,
});
setPuzzleOperation(response.operation);
setPuzzleSession(response.session);
const sourceSessionCandidate = pickPuzzleCandidateForLevel(
response.session.draft?.candidates ?? [],
puzzleRun.playedProfileIds,
);
if (sourceSessionCandidate) {
setPuzzleRun(
advanceLocalPuzzleLevelWithWork(
puzzleRun,
buildPuzzleCandidateWorkSummary(
sourceSessionCandidate,
response.session,
puzzleRun.currentLevelIndex + 1,
),
),
);
return;
}
}
}
throw new Error('当前拼图缺少可用于生成下一关的草稿会话。');
}
setIsPuzzleNextLevelGenerating(true);
const response = await executePuzzleAgentAction(puzzleSession.sessionId, {
action: 'generate_puzzle_images',
candidateCount: 2,
});
setPuzzleOperation(response.operation);
setPuzzleSession(response.session);
const generatedCandidate = pickPuzzleCandidateForLevel(
response.session.draft?.candidates ?? [],
puzzleRun.playedProfileIds,
);
if (generatedCandidate) {
setPuzzleRun(
advanceLocalPuzzleLevelWithWork(
puzzleRun,
buildPuzzleCandidateWorkSummary(
generatedCandidate,
response.session,
puzzleRun.currentLevelIndex + 1,
),
),
);
return;
}
setPuzzleRun(advanceLocalPuzzleLevel(puzzleRun));
} catch (error) {
setPuzzleError(resolvePuzzleErrorMessage(error, '准备下一关失败。'));
} finally {
setIsPuzzleNextLevelGenerating(false);
setIsPuzzleBusy(false);
}
}, [
isPuzzleBusy,
puzzleRun,
puzzleSession,
resolvePuzzleErrorMessage,
selectedPuzzleDetail,
]);
const leaveAgentWorkspace = useCallback(() => {
enterCreateTab();
@@ -1802,6 +2041,49 @@ export function PlatformEntryFlowShellImpl({
</motion.div>
)}
{selectionStage === 'big-fish-generating' && (
<motion.div
key="big-fish-generating"
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -12 }}
className="flex h-full min-h-0 flex-col"
>
<Suspense
fallback={<LazyPanelFallback label="正在加载大鱼吃小鱼生成面板..." />}
>
<CustomWorldGenerationView
settingText={
bigFishSession?.lastAssistantReply ?? '正在整理当前玩法草稿。'
}
anchorEntries={buildBigFishGenerationAnchorEntries(bigFishSession)}
progress={buildMiniGameDraftGenerationProgress(
bigFishGenerationState,
)}
isGenerating={isBigFishBusy}
error={bigFishError}
onBack={leaveBigFishFlow}
onEditSetting={() => {
setSelectionStage('big-fish-agent-workspace');
}}
onRetry={() => {
void executeBigFishAction({ action: 'big_fish_compile_draft' });
}}
onInterrupt={undefined}
backLabel="返回创作中心"
settingActionLabel={null}
retryLabel="重新生成草稿"
settingTitle="当前玩法信息"
settingDescription={null}
progressTitle="大鱼吃小鱼草稿生成进度"
activeBadgeLabel="草稿生成中"
pausedBadgeLabel="草稿生成已暂停"
idleBadgeLabel="等待返回工作区"
/>
</Suspense>
</motion.div>
)}
{selectionStage === 'big-fish-result' && bigFishSession?.draft && (
<motion.div
key="big-fish-result"
@@ -1884,6 +2166,49 @@ export function PlatformEntryFlowShellImpl({
</motion.div>
)}
{selectionStage === 'puzzle-generating' && (
<motion.div
key="puzzle-generating"
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -12 }}
className="flex h-full min-h-0 flex-col"
>
<Suspense
fallback={<LazyPanelFallback label="正在加载拼图生成面板..." />}
>
<CustomWorldGenerationView
settingText={
puzzleSession?.lastAssistantReply ?? '正在整理当前拼图草稿。'
}
anchorEntries={buildPuzzleGenerationAnchorEntries(puzzleSession)}
progress={buildMiniGameDraftGenerationProgress(
puzzleGenerationState,
)}
isGenerating={isPuzzleBusy}
error={puzzleError}
onBack={leavePuzzleFlow}
onEditSetting={() => {
setSelectionStage('puzzle-agent-workspace');
}}
onRetry={() => {
void executePuzzleAction({ action: 'compile_puzzle_draft' });
}}
onInterrupt={undefined}
backLabel="返回创作中心"
settingActionLabel={null}
retryLabel="重新生成草稿"
settingTitle="当前拼图信息"
settingDescription={null}
progressTitle="拼图草稿生成进度"
activeBadgeLabel="草稿生成中"
pausedBadgeLabel="草稿生成已暂停"
idleBadgeLabel="等待返回工作区"
/>
</Suspense>
</motion.div>
)}
{selectionStage === 'puzzle-result' && puzzleSession?.draft && (
<motion.div
key="puzzle-result"
@@ -1940,7 +2265,7 @@ export function PlatformEntryFlowShellImpl({
>
<PuzzleRuntimeShell
run={puzzleRun}
isBusy={isPuzzleBusy}
isBusy={isPuzzleBusy || isPuzzleNextLevelGenerating}
error={puzzleError}
onBack={() => {
setSelectionStage('puzzle-gallery-detail');
@@ -1955,6 +2280,17 @@ export function PlatformEntryFlowShellImpl({
void advancePuzzleLevel();
}}
/>
{isPuzzleNextLevelGenerating ? (
<div className="fixed inset-0 z-[120] flex items-center justify-center bg-slate-950/62 px-5 backdrop-blur-sm">
<div className="flex max-w-[18rem] flex-col items-center gap-3 rounded-[1.5rem] border border-white/12 bg-slate-950/92 px-6 py-5 text-center text-white shadow-[0_28px_80px_rgba(0,0,0,0.35)]">
<Loader2 className="h-6 w-6 animate-spin text-amber-200" />
<div className="text-sm font-bold"></div>
<div className="text-xs leading-5 text-white/68">
广
</div>
</div>
</div>
) : null}
</motion.div>
)}

View File

@@ -9,9 +9,11 @@ export type SelectionStage =
| 'detail'
| 'agent-workspace'
| 'big-fish-agent-workspace'
| 'big-fish-generating'
| 'big-fish-result'
| 'big-fish-runtime'
| 'puzzle-agent-workspace'
| 'puzzle-generating'
| 'puzzle-result'
| 'puzzle-gallery-detail'
| 'puzzle-runtime'

View File

@@ -0,0 +1,283 @@
import type { BigFishSessionSnapshotResponse } from '../../packages/shared/src/contracts/bigFish';
import type { PuzzleAgentSessionSnapshot } from '../../packages/shared/src/contracts/puzzleAgentSession';
import type {
CustomWorldGenerationProgress,
CustomWorldGenerationStep,
} from '../../packages/shared/src/contracts/runtime';
import type { CustomWorldStructuredAnchorEntry } from './customWorldAgentGenerationProgress';
export type MiniGameDraftGenerationKind = 'puzzle' | 'big-fish';
export type MiniGameDraftGenerationPhase =
| 'idle'
| 'compile'
| 'puzzle-images'
| 'puzzle-select-image'
| 'big-fish-main-images'
| 'big-fish-motions'
| 'big-fish-background'
| 'ready'
| 'failed';
export type MiniGameDraftGenerationState = {
kind: MiniGameDraftGenerationKind;
phase: MiniGameDraftGenerationPhase;
startedAtMs: number;
completedAssetCount: number;
totalAssetCount: number;
error: string | null;
};
type MiniGameStepDefinition = {
id: MiniGameDraftGenerationPhase;
label: string;
detail: string;
weight: number;
};
type MiniGameAnchorSource = {
key: string;
label: string;
value: string;
};
const PUZZLE_STEPS = [
{
id: 'compile',
label: '编译拼图草稿',
detail: '整理主题、主体、构图与标签。',
weight: 34,
},
{
id: 'puzzle-images',
label: '生成拼图图片',
detail: '根据草稿生成候选图。',
weight: 33,
},
{
id: 'puzzle-select-image',
label: '确认正式图片',
detail: '选择候选图写入结果页。',
weight: 33,
},
] as const satisfies ReadonlyArray<MiniGameStepDefinition>;
const BIG_FISH_STEPS = [
{
id: 'compile',
label: '编译玩法草稿',
detail: '生成关卡角色描述、生态背景与运行参数。',
weight: 25,
},
{
id: 'big-fish-main-images',
label: '生成角色图片',
detail: '为每个成长阶段生成主形象。',
weight: 30,
},
{
id: 'big-fish-motions',
label: '生成动作素材',
detail: '补齐漂浮与游动动作素材。',
weight: 30,
},
{
id: 'big-fish-background',
label: '生成场地背景',
detail: '生成玩法场地背景图。',
weight: 15,
},
] as const satisfies ReadonlyArray<MiniGameStepDefinition>;
function clampProgress(value: number) {
return Math.max(0, Math.min(100, Math.round(value)));
}
function getStepDefinitions(kind: MiniGameDraftGenerationKind) {
return kind === 'puzzle' ? PUZZLE_STEPS : BIG_FISH_STEPS;
}
function getActiveStepIndex(
steps: ReadonlyArray<MiniGameStepDefinition>,
phase: MiniGameDraftGenerationPhase,
) {
if (phase === 'ready') {
return steps.length - 1;
}
const index = steps.findIndex((step) => step.id === phase);
return index >= 0 ? index : 0;
}
function buildMiniGameProgressSteps(
steps: ReadonlyArray<MiniGameStepDefinition>,
activeStepIndex: number,
state: MiniGameDraftGenerationState,
) {
return steps.map((step, index) => {
const isCompleted = state.phase === 'ready' || index < activeStepIndex;
const isActive = state.phase !== 'failed' && !isCompleted && index === activeStepIndex;
const isAssetStep = step.id === state.phase && state.totalAssetCount > 0;
return {
id: step.id,
label: step.label,
detail: step.detail,
completed: isCompleted
? 1
: isAssetStep
? state.completedAssetCount
: 0,
total: isAssetStep ? state.totalAssetCount : 1,
status: isCompleted ? 'completed' : isActive ? 'active' : 'pending',
} satisfies CustomWorldGenerationStep;
});
}
export function createMiniGameDraftGenerationState(
kind: MiniGameDraftGenerationKind,
): MiniGameDraftGenerationState {
return {
kind,
phase: 'compile',
startedAtMs: Date.now(),
completedAssetCount: 0,
totalAssetCount: 0,
error: null,
};
}
export function buildMiniGameDraftGenerationProgress(
state: MiniGameDraftGenerationState | null,
nowMs = Date.now(),
): CustomWorldGenerationProgress | null {
if (!state) {
return null;
}
const steps = getStepDefinitions(state.kind);
const activeStepIndex = getActiveStepIndex(steps, state.phase);
const completedWeight = steps
.slice(0, state.phase === 'ready' ? steps.length : activeStepIndex)
.reduce((sum, step) => sum + step.weight, 0);
const activeStep = steps[activeStepIndex] ?? steps[0];
const assetRatio =
state.totalAssetCount > 0
? Math.min(1, state.completedAssetCount / state.totalAssetCount)
: state.phase === 'ready'
? 1
: 0;
const overallProgress =
state.phase === 'failed'
? Math.max(1, completedWeight)
: state.phase === 'ready'
? 100
: completedWeight + activeStep.weight * assetRatio;
return {
phaseId: state.phase,
phaseLabel:
state.phase === 'failed'
? '生成失败'
: state.phase === 'ready'
? '生成完成'
: activeStep.label,
phaseDetail:
state.error ??
(state.phase === 'ready'
? '完整草稿与资产已准备完成。'
: activeStep.detail),
batchLabel: activeStep.label,
overallProgress: clampProgress(overallProgress),
completedWeight: clampProgress(overallProgress),
totalWeight: 100,
elapsedMs: Math.max(0, nowMs - state.startedAtMs),
estimatedRemainingMs: state.phase === 'ready' ? 0 : null,
activeStepIndex,
steps: buildMiniGameProgressSteps(steps, activeStepIndex, state),
};
}
export function buildPuzzleGenerationAnchorEntries(
session: PuzzleAgentSessionSnapshot | null | undefined,
): CustomWorldStructuredAnchorEntry[] {
if (!session) {
return [];
}
const draft = session.draft;
const entries: Array<MiniGameAnchorSource | null> = [
session.anchorPack.themePromise,
session.anchorPack.visualSubject,
session.anchorPack.visualMood,
session.anchorPack.compositionHooks,
session.anchorPack.tagsAndForbidden,
draft
? {
key: 'draft-summary',
label: '草稿摘要',
value: draft.summary,
}
: null,
draft?.coverImageSrc
? {
key: 'cover-image',
label: '正式图片',
value: '已生成并应用',
}
: null,
];
return entries
.filter((entry): entry is MiniGameAnchorSource => Boolean(entry))
.map((entry) => ({
id: entry.key,
label: entry.label,
value: entry.value,
}))
.filter((entry) => entry.value.trim());
}
export function buildBigFishGenerationAnchorEntries(
session: BigFishSessionSnapshotResponse | null | undefined,
): CustomWorldStructuredAnchorEntry[] {
if (!session) {
return [];
}
const draft = session.draft;
const assetReadyCount = session.assetSlots.filter(
(slot) => slot.status === 'ready',
).length;
const entries: Array<MiniGameAnchorSource | null> = [
session.anchorPack.gameplayPromise,
session.anchorPack.ecologyVisualTheme,
session.anchorPack.growthLadder,
session.anchorPack.riskTempo,
draft
? {
key: 'level-characters',
label: '角色描述',
value: draft.levels
.map((level) => `Lv.${level.level} ${level.name}${level.oneLineFantasy}`)
.join('\n'),
}
: null,
draft
? {
key: 'asset-coverage',
label: '图片与动作',
value: `已生成 ${assetReadyCount}/${session.assetSlots.length} 个资产`,
}
: null,
];
return entries
.filter((entry): entry is MiniGameAnchorSource => Boolean(entry))
.map((entry) => ({
id: entry.key,
label: entry.label,
value: entry.value,
}))
.filter((entry) => entry.value.trim());
}