diff --git a/src/modules/beam/BeamView.tsx b/src/modules/beam/BeamView.tsx index 23db9c522..2cef13c55 100644 --- a/src/modules/beam/BeamView.tsx +++ b/src/modules/beam/BeamView.tsx @@ -14,6 +14,7 @@ import { BeamRayGrid } from './scatter/BeamRayGrid'; import { BeamScatterInput } from './scatter/BeamScatterInput'; import { BeamScatterPane } from './scatter/BeamScatterPane'; import { BeamStoreApi, useBeamStore } from './store-beam.hooks'; +import { useModuleBeamStore } from './store-module-beam'; export function BeamView(props: { @@ -24,6 +25,7 @@ export function BeamView(props: { }) { // state + const [hasAutoMerged, setHasAutoMerged] = React.useState(false); const [warnIsScattering, setWarnIsScattering] = React.useState(false); // external state @@ -36,7 +38,9 @@ export function BeamView(props: { /* root */ inputHistory, inputIssues, inputReady, /* scatter */ isScattering, raysReady, /* gather (composite) */ canGather, + /* IDs */ rayIds, fusionIds, } = useBeamStore(props.beamStore, useShallow(state => ({ + // input inputHistory: state.inputHistory, inputIssues: state.inputIssues, inputReady: state.inputReady, @@ -45,9 +49,13 @@ export function BeamView(props: { raysReady: state.raysReady, // gather (composite) canGather: state.raysReady >= 2 && state.currentFactoryId !== null && state.currentGatherLlmId !== null, + // IDs + rayIds: state.rays.map(ray => ray.rayId), + fusionIds: state.fusions.map(fusion => fusion.fusionId), + }))); + const { gatherAutoStartAfterScatter } = useModuleBeamStore(useShallow(state => ({ + gatherAutoStartAfterScatter: state.gatherAutoStartAfterScatter, }))); - const rayIds = useBeamStore(props.beamStore, useShallow(state => state.rays.map(ray => ray.rayId))); - const fusionIds = useBeamStore(props.beamStore, useShallow(state => state.fusions.map(fusion => fusion.fusionId))); // derived state const raysCount = rayIds.length; @@ -59,6 +67,11 @@ export function BeamView(props: { const handleRayIncreaseCount = React.useCallback(() => setRayCount(raysCount + 1), [setRayCount, raysCount]); + const handleScatterStart = React.useCallback(() => { + setHasAutoMerged(false); + startScatteringAll(); + }, [startScatteringAll]); + const handleCreateFusion = React.useCallback(() => { // if scatter is busy, ask for confirmation @@ -70,20 +83,31 @@ export function BeamView(props: { }, [isScattering, props.beamStore]); - const handleStopScatterConfirmation = React.useCallback(() => { + const handleStartMergeConfirmation = React.useCallback(() => { setWarnIsScattering(false); stopScatteringAll(); handleCreateFusion(); }, [handleCreateFusion, stopScatteringAll]); - const handleStopScatterDenial = React.useCallback(() => setWarnIsScattering(false), []); + const handleStartMergeDenial = React.useCallback(() => setWarnIsScattering(false), []); + + // auto-merge + const shallAutoMerge = gatherAutoStartAfterScatter && canGather && !isScattering && !hasAutoMerged; + React.useEffect(() => { + if (shallAutoMerge) { + setHasAutoMerged(true); + handleStartMergeConfirmation(); + } + }, [handleStartMergeConfirmation, shallAutoMerge]); - // (this is great ux) scatter freed up while we were asking the question, proceed + // (great ux) scatter finished while the "start merge" (warning) dialog is up: dismiss dialog and proceed + // here we assume that 'warnIsScattering' shows the intention of the user to proceed with a merge asap + const shallResumeMerge = warnIsScattering && !isScattering && !gatherAutoStartAfterScatter; React.useEffect(() => { - if (warnIsScattering && !isScattering) - handleStopScatterConfirmation(); - }, [handleStopScatterConfirmation, isScattering, warnIsScattering]); + if (shallResumeMerge) + handleStartMergeConfirmation(); + }, [handleStartMergeConfirmation, shallResumeMerge]); // runnning @@ -138,7 +162,7 @@ export function BeamView(props: { setRayCount={handleRaySetCount} startEnabled={inputReady} startBusy={isScattering} - onStart={startScatteringAll} + onStart={handleScatterStart} onStop={stopScatteringAll} onExplainerShow={explainerShow} /> @@ -163,7 +187,7 @@ export function BeamView(props: { beamStore={props.beamStore} canGather={canGather} isMobile={props.isMobile} - onAddFusion={handleCreateFusion} + // onAddFusion={handleCreateFusion} raysReady={raysReady} /> @@ -184,8 +208,8 @@ export function BeamView(props: { {warnIsScattering && ( : ( {/*You need two or more replies for a {currentFactory?.shortLabel?.toLocaleLowerCase() ?? ''} merge.*/} - Waiting for multiple Beams. + Waiting for multiple responses. )} diff --git a/src/modules/beam/gather/BeamGatherPane.tsx b/src/modules/beam/gather/BeamGatherPane.tsx index 93dfed9bd..ff591b196 100644 --- a/src/modules/beam/gather/BeamGatherPane.tsx +++ b/src/modules/beam/gather/BeamGatherPane.tsx @@ -57,7 +57,7 @@ export function BeamGatherPane(props: { beamStore: BeamStoreApi, canGather: boolean, isMobile: boolean, - onAddFusion: () => void, + // onAddFusion: () => void, raysReady: number, }) { diff --git a/src/modules/beam/gather/beam.gather.ts b/src/modules/beam/gather/beam.gather.ts index 9759b0b88..50e2ff8e8 100644 --- a/src/modules/beam/gather/beam.gather.ts +++ b/src/modules/beam/gather/beam.gather.ts @@ -104,6 +104,7 @@ interface GatherStateSlice { // derived state (just acts as a cache to avoid re-calculating) isGatheringAny: boolean; + // fusionsReady: number; } @@ -118,6 +119,7 @@ export const reInitGatherStateSlice = (prevFusions: BFusion[], gatherLlmId: DLLM fusions: [], isGatheringAny: false, + // fusionsReady: 0, }; }; @@ -170,10 +172,12 @@ export const createGatherSlice: StateCreator - handleClearLastConfig()}> + handleClearLastConfig() : undefined}> Advanced + + {gatherAutoStartAfterScatter && } + Auto-Merge + + {gatherShowAllPrompts && } Detailed Custom Merge diff --git a/src/modules/beam/store-module-beam.tsx b/src/modules/beam/store-module-beam.tsx index f4b58bb76..ff1bdc470 100644 --- a/src/modules/beam/store-module-beam.tsx +++ b/src/modules/beam/store-module-beam.tsx @@ -23,6 +23,7 @@ interface ModuleBeamState { cardScrolling: boolean; scatterShowLettering: boolean; scatterShowPrevMessages: boolean; + gatherAutoStartAfterScatter: boolean; gatherShowAllPrompts: boolean; } @@ -37,6 +38,7 @@ interface ModuleBeamStore extends ModuleBeamState { toggleCardScrolling: () => void; toggleScatterShowLettering: () => void; toggleScatterShowPrevMessages: () => void; + toggleGatherAutoStartAfterScatter: () => void; toggleGatherShowAllPrompts: () => void; } @@ -50,6 +52,7 @@ export const useModuleBeamStore = create()(persist( scatterShowLettering: false, scatterShowPrevMessages: false, gatherShowAllPrompts: false, + gatherAutoStartAfterScatter: false, addPreset: (name, rayLlmIds, gatherLlmId, gatherFactoryId) => _set(state => ({ @@ -86,6 +89,8 @@ export const useModuleBeamStore = create()(persist( toggleScatterShowPrevMessages: () => _set(state => ({ scatterShowPrevMessages: !state.scatterShowPrevMessages })), + toggleGatherAutoStartAfterScatter: () => _set(state => ({ gatherAutoStartAfterScatter: !state.gatherAutoStartAfterScatter })), + toggleGatherShowAllPrompts: () => _set(state => ({ gatherShowAllPrompts: !state.gatherShowAllPrompts })), }), {