This commit is contained in:
2026-04-21 10:30:12 +08:00
parent ae28dab032
commit 13bc79306f
49 changed files with 3691 additions and 1357 deletions

View File

@@ -20,6 +20,8 @@ import type {
import type {
CustomWorldGalleryCard,
CustomWorldLibraryEntry,
PlatformBrowseHistoryEntry,
PlatformBrowseHistoryWriteEntry,
ProfileDashboardSummary,
ProfileSaveArchiveSummary,
} from '../../../packages/shared/src/contracts/runtime';
@@ -46,14 +48,6 @@ import {
writeCustomWorldAgentUiState,
} from '../../services/customWorldAgentUiState';
import { buildCustomWorldCreatorIntentFoundationText } from '../../services/customWorldCreatorIntent';
import {
hasPendingPlatformBrowseHistoryMigration,
markPlatformBrowseHistoryMigrated,
type PlatformBrowseHistoryEntry,
type PlatformBrowseHistoryWriteEntry,
readPlatformBrowseHistory,
writePlatformBrowseHistory,
} from '../../services/platformBrowseHistory';
import {
deleteCustomWorldProfile,
getCustomWorldGalleryDetail,
@@ -64,7 +58,6 @@ import {
listProfileSaveArchives,
publishCustomWorldProfile,
resumeProfileSaveArchive,
syncProfileBrowseHistory,
unpublishCustomWorldProfile,
upsertCustomWorldProfile,
upsertProfileBrowseHistory,
@@ -381,18 +374,11 @@ export function PreGameSelectionFlow({
const appendBrowseHistoryEntry = useCallback(
async (entry: PlatformBrowseHistoryWriteEntry) => {
const nextEntries = writePlatformBrowseHistory(authUi?.user, entry);
setHistoryEntries(nextEntries);
setHistoryError(null);
if (!authUi?.user) {
return;
}
try {
const syncedEntries = await upsertProfileBrowseHistory(entry);
setHistoryEntries(syncedEntries);
markPlatformBrowseHistoryMigrated(authUi?.user);
} catch (error) {
setHistoryError(resolveErrorMessage(error, '写入浏览历史失败。'));
}
@@ -444,8 +430,7 @@ export function PreGameSelectionFlow({
let isActive = true;
void (async () => {
const localHistoryEntries = readPlatformBrowseHistory(authUi?.user);
setHistoryEntries(localHistoryEntries);
setHistoryEntries([]);
setHistoryError(null);
setSaveError(null);
setIsLoadingPlatform(true);
@@ -472,22 +457,7 @@ export function PreGameSelectionFlow({
isAuthenticated ? listCustomWorldWorks() : Promise.resolve([]),
listCustomWorldGallery(),
isAuthenticated ? getProfileDashboard() : Promise.resolve(null),
isAuthenticated
? (async () => {
let nextEntries = await listProfileBrowseHistory();
if (
hasPendingPlatformBrowseHistoryMigration(authUi?.user) &&
localHistoryEntries.length > 0
) {
nextEntries =
await syncProfileBrowseHistory(localHistoryEntries);
markPlatformBrowseHistoryMigrated(authUi?.user);
}
return nextEntries;
})()
: Promise.resolve(localHistoryEntries),
isAuthenticated ? listProfileBrowseHistory() : Promise.resolve([]),
isAuthenticated ? listProfileSaveArchives() : Promise.resolve([]),
]);
if (!isActive) {
@@ -881,8 +851,6 @@ export function PreGameSelectionFlow({
const isAgentDraftGenerationView =
customWorldGenerationViewSource === 'agent-draft-foundation';
const isAgentDraftResultView = customWorldResultViewSource === 'agent-draft';
const isAgentDraftResultEditingFrozen =
customWorldResultViewSource === 'agent-draft';
const activeGenerationSettingText = agentDraftSettingPreview;
const activeGenerationProgress = agentDraftGenerationProgress;
const isActiveGenerationRunning =
@@ -1096,7 +1064,8 @@ export function PreGameSelectionFlow({
setCustomWorldAutoSaveState('idle');
setCustomWorldGenerationViewSource(null);
setCustomWorldResultViewSource(null);
setSelectionStage('agent-workspace');
setPlatformTab('create');
setSelectionStage('platform');
};
const retryAgentDraftGeneration = () => {
@@ -1133,17 +1102,39 @@ export function PreGameSelectionFlow({
const handleOpenCreationWork = useCallback(
async (work: CustomWorldWorkSummary) => {
if (work.status === 'draft' && work.sessionId) {
// 阶段二要求草稿优先回到 Agent 工作区,而不是再次自动顶回结果页。
isAgentDraftResultAutoOpenSuppressedRef.current = true;
persistAgentUiState(work.sessionId, null);
setGeneratedCustomWorldProfile(null);
setCustomWorldError(null);
setCustomWorldAutoSaveError(null);
setCustomWorldAutoSaveState('idle');
setCustomWorldGenerationViewSource(null);
setCustomWorldResultViewSource(null);
const shouldOpenAgentWorkspace =
work.playableNpcCount <= 0 && work.landmarkCount <= 0;
if (shouldOpenAgentWorkspace) {
// 仅八锚点未整理成底稿时才恢复 Agent 对话工作区。
isAgentDraftResultAutoOpenSuppressedRef.current = true;
setGeneratedCustomWorldProfile(null);
setCustomWorldResultViewSource(null);
setPlatformTab('create');
setSelectionStage('agent-workspace');
return;
}
isAgentDraftResultAutoOpenSuppressedRef.current = false;
const latestSession = await syncAgentSessionSnapshot(work.sessionId);
const nextProfile = buildCustomWorldProfileFromAgentDraft(latestSession);
if (!nextProfile) {
setPlatformError('当前草稿还没有可编辑的结果页数据,请先继续补齐锚点。');
setPlatformTab('create');
setSelectionStage('agent-workspace');
return;
}
setGeneratedCustomWorldProfile(normalizeAgentBackedProfile(nextProfile));
setCustomWorldResultViewSource('agent-draft');
setPlatformTab('create');
setSelectionStage('agent-workspace');
setSelectionStage('custom-world-result');
return;
}
@@ -1179,6 +1170,7 @@ export function PreGameSelectionFlow({
openLibraryDetail,
persistAgentUiState,
savedCustomWorldEntries,
syncAgentSessionSnapshot,
setSelectionStage,
],
);
@@ -1583,32 +1575,9 @@ export function PreGameSelectionFlow({
});
}}
onCreateNew={openCreationTypePicker}
onResumeDraft={(sessionId) => {
onOpenDraft={(item) => {
runProtectedAction(() => {
void handleOpenCreationWork({
workId: `draft:${sessionId}`,
sourceType: 'agent_session',
status: 'draft',
title: '',
subtitle: '',
summary: '',
coverImageSrc: null,
coverRenderMode: 'image',
coverCharacterImageSrcs: [],
updatedAt: new Date().toISOString(),
publishedAt: null,
stage: null,
stageLabel: '',
playableNpcCount: 0,
landmarkCount: 0,
roleVisualReadyCount: 0,
roleAnimationReadyCount: 0,
roleAssetSummaryLabel: null,
sessionId,
profileId: null,
canResume: true,
canEnterWorld: false,
});
void handleOpenCreationWork(item);
});
}}
onEnterPublished={(profileId) => {
@@ -1918,10 +1887,10 @@ export function PreGameSelectionFlow({
});
});
}}
readOnly={isAgentDraftResultEditingFrozen}
readOnly={false}
compactAgentResultMode={isAgentDraftResultView}
backLabel={isAgentDraftResultView ? '返回创作' : undefined}
editActionLabel="去Agent调整设定"
editActionLabel="继续调整设定"
enterWorldActionLabel="进入世界"
autoSaveState={customWorldAutoSaveState}
/>