1
This commit is contained in:
@@ -47,6 +47,14 @@ type UseRpgCreationSessionControllerParams = {
|
||||
setSelectionStage: (stage: SelectionStage) => void;
|
||||
enterCreateTab?: (() => void) | undefined;
|
||||
onSessionOpened?: (() => void) | undefined;
|
||||
onDraftGenerationStarted?: ((sessionId: string) => void) | undefined;
|
||||
onDraftGenerationCompleted?:
|
||||
| ((params: {
|
||||
sessionId: string;
|
||||
profileId: string | null;
|
||||
viewedImmediately: boolean;
|
||||
}) => void)
|
||||
| undefined;
|
||||
};
|
||||
|
||||
type PendingAgentUserMessage = {
|
||||
@@ -67,6 +75,8 @@ export function useRpgCreationSessionController(
|
||||
setSelectionStage,
|
||||
enterCreateTab,
|
||||
onSessionOpened,
|
||||
onDraftGenerationStarted,
|
||||
onDraftGenerationCompleted,
|
||||
} = params;
|
||||
const initialAgentUiStateRef = useRef(readCustomWorldAgentUiState());
|
||||
const shouldRestoreInitialAgentUiStateRef = useRef(
|
||||
@@ -471,7 +481,7 @@ export function useRpgCreationSessionController(
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
selectionStage !== 'custom-world-generating' ||
|
||||
!activeAgentSessionId ||
|
||||
customWorldGenerationViewSource !== 'agent-draft-foundation' ||
|
||||
!isDraftFoundationOperation(agentOperation) ||
|
||||
agentOperation.status !== 'completed'
|
||||
@@ -480,6 +490,7 @@ export function useRpgCreationSessionController(
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
const generationSessionId = activeAgentSessionId;
|
||||
void (async () => {
|
||||
for (
|
||||
let attempt = 1;
|
||||
@@ -494,11 +505,9 @@ export function useRpgCreationSessionController(
|
||||
return;
|
||||
}
|
||||
|
||||
const latestResultView = activeAgentSessionId
|
||||
? await syncAgentCreationResultView(activeAgentSessionId).catch(
|
||||
() => null,
|
||||
)
|
||||
: null;
|
||||
const latestResultView = await syncAgentCreationResultView(
|
||||
generationSessionId,
|
||||
).catch(() => null);
|
||||
|
||||
if (cancelled) {
|
||||
return;
|
||||
@@ -512,11 +521,19 @@ export function useRpgCreationSessionController(
|
||||
continue;
|
||||
}
|
||||
|
||||
setGeneratedCustomWorldProfile(draftResultProfile);
|
||||
setAgentDraftGenerationStartedAt(null);
|
||||
setCustomWorldGenerationViewSource(null);
|
||||
setCustomWorldResultViewSource('agent-draft');
|
||||
setSelectionStage('custom-world-result');
|
||||
const shouldOpenResult = selectionStage === 'custom-world-generating';
|
||||
onDraftGenerationCompleted?.({
|
||||
sessionId: generationSessionId,
|
||||
profileId: draftResultProfile.id ?? null,
|
||||
viewedImmediately: shouldOpenResult,
|
||||
});
|
||||
if (shouldOpenResult) {
|
||||
setGeneratedCustomWorldProfile(draftResultProfile);
|
||||
setCustomWorldResultViewSource('agent-draft');
|
||||
setSelectionStage('custom-world-result');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -533,6 +550,7 @@ export function useRpgCreationSessionController(
|
||||
agentOperation,
|
||||
agentSession,
|
||||
customWorldGenerationViewSource,
|
||||
onDraftGenerationCompleted,
|
||||
selectionStage,
|
||||
setSelectionStage,
|
||||
syncAgentCreationResultView,
|
||||
@@ -619,6 +637,11 @@ export function useRpgCreationSessionController(
|
||||
setCustomWorldResultViewSource(
|
||||
resultView.resultViewSource ?? 'agent-draft',
|
||||
);
|
||||
onDraftGenerationCompleted?.({
|
||||
sessionId: activeAgentSessionId,
|
||||
profileId: resultProfile.id ?? null,
|
||||
viewedImmediately: selectionStage === 'custom-world-result',
|
||||
});
|
||||
isAgentDraftResultAutoOpenSuppressedRef.current = false;
|
||||
if (selectionStage === 'agent-workspace') {
|
||||
setSelectionStage('custom-world-result');
|
||||
@@ -633,6 +656,7 @@ export function useRpgCreationSessionController(
|
||||
activeAgentSessionId,
|
||||
agentSession,
|
||||
generatedCustomWorldProfile,
|
||||
onDraftGenerationCompleted,
|
||||
selectionStage,
|
||||
setSelectionStage,
|
||||
syncAgentCreationResultView,
|
||||
@@ -815,6 +839,7 @@ export function useRpgCreationSessionController(
|
||||
setCustomWorldGenerationViewSource('agent-draft-foundation');
|
||||
setCustomWorldResultViewSource(null);
|
||||
setAgentDraftGenerationStartedAt(Date.now());
|
||||
onDraftGenerationStarted?.(activeAgentSessionId);
|
||||
setSelectionStage('custom-world-generating');
|
||||
}
|
||||
|
||||
@@ -851,7 +876,12 @@ export function useRpgCreationSessionController(
|
||||
);
|
||||
}
|
||||
},
|
||||
[activeAgentSessionId, persistAgentUiState, setSelectionStage],
|
||||
[
|
||||
activeAgentSessionId,
|
||||
onDraftGenerationStarted,
|
||||
persistAgentUiState,
|
||||
setSelectionStage,
|
||||
],
|
||||
);
|
||||
|
||||
const setNormalizedGeneratedCustomWorldProfile = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user