@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
37 lines (28 loc) • 1.27 kB
text/typescript
import { GenerationBatch } from '@/types/generation';
import { ImageStoreState } from '../../initialState';
import { generationTopicSelectors } from '../generationTopic/selectors';
// ====== topic batch selectors ====== //
const getGenerationBatchesByTopicId = (topicId: string) => (s: ImageStoreState) => {
return s.generationBatchesMap[topicId] || [];
};
const currentGenerationBatches = (s: ImageStoreState): GenerationBatch[] => {
const activeTopicId = generationTopicSelectors.activeGenerationTopicId(s);
if (!activeTopicId) return [];
return getGenerationBatchesByTopicId(activeTopicId)(s);
};
const getGenerationBatchByBatchId = (batchId: string) => (s: ImageStoreState) => {
const batches = currentGenerationBatches(s);
return batches.find((batch) => batch.id === batchId);
};
const isCurrentGenerationTopicLoaded = (s: ImageStoreState): boolean => {
const activeTopicId = generationTopicSelectors.activeGenerationTopicId(s);
if (!activeTopicId) return false;
return Array.isArray(s.generationBatchesMap[activeTopicId]);
};
// ====== aggregate selectors ====== //
export const generationBatchSelectors = {
getGenerationBatchesByTopicId,
currentGenerationBatches,
getGenerationBatchByBatchId,
isCurrentGenerationTopicLoaded,
};