Syntax changes in front and back end dirs. These do not affect functionality and are purely intended to better capture and describe the app's functionality and purpose
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
import { Router, type Request, type Response, type NextFunction } from 'express';
|
||||
import logger from '../logger.js';
|
||||
import * as notebookStore from '../stores/notebookStore.js';
|
||||
import type { TextChunk, Source, SourceGroup } from '../stores/notebookStore.js';
|
||||
import * as sourceCorpusStore from '../stores/sourceCorpusStore.js';
|
||||
import type { TextChunk, Source, SourceGroup } from '../stores/sourceCorpusStore.js';
|
||||
import * as documentCacheStore from '../stores/documentCacheStore.js';
|
||||
import type { CacheEntry } from '../stores/documentCacheStore.js';
|
||||
import {
|
||||
@@ -27,16 +27,16 @@ const GENERATORS: Record<DocumentType, GeneratorFn> = {
|
||||
const router = Router();
|
||||
|
||||
interface GenerateBody {
|
||||
notebookId?: string;
|
||||
sourceCorpusId?: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
router.post('/generate', async (req: Request<unknown, unknown, GenerateBody>, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const { notebookId, type } = req.body;
|
||||
const { sourceCorpusId, type } = req.body;
|
||||
|
||||
if (!notebookId || !type) {
|
||||
res.status(400).json({ error: 'notebookId and type are required' });
|
||||
if (!sourceCorpusId || !type) {
|
||||
res.status(400).json({ error: 'sourceCorpusId and type are required' });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,31 +48,31 @@ router.post('/generate', async (req: Request<unknown, unknown, GenerateBody>, re
|
||||
return;
|
||||
}
|
||||
|
||||
const chunks: TextChunk[] = notebookStore.getChunksForNotebook(notebookId);
|
||||
const chunks: TextChunk[] = sourceCorpusStore.getChunksForSourceCorpus(sourceCorpusId);
|
||||
if (chunks.length === 0) {
|
||||
res.status(422).json({ error: 'No source material available in this notebook' });
|
||||
res.status(422).json({ error: 'No source material available in this source corpus' });
|
||||
return;
|
||||
}
|
||||
|
||||
const sources: Source[] = notebookStore.getSources(notebookId);
|
||||
const cached: CacheEntry | null = documentCacheStore.getCachedDocument(notebookId, type);
|
||||
if (cached && documentCacheStore.isFresh(notebookId, type, sources)) {
|
||||
logger.info({ notebookId, type }, 'serving cached document');
|
||||
const sources: Source[] = sourceCorpusStore.getSources(sourceCorpusId);
|
||||
const cached: CacheEntry | null = documentCacheStore.getCachedDocument(sourceCorpusId, type);
|
||||
if (cached && documentCacheStore.isFresh(sourceCorpusId, type, sources)) {
|
||||
logger.info({ sourceCorpusId, type }, 'serving cached document');
|
||||
res.json({ type, document: cached.document });
|
||||
return;
|
||||
}
|
||||
|
||||
const sourceGroups: SourceGroup[] = notebookStore.buildSourceGroups(notebookId, chunks);
|
||||
const sourceGroups: SourceGroup[] = sourceCorpusStore.buildSourceGroups(sourceCorpusId, chunks);
|
||||
|
||||
logger.info(
|
||||
{ notebookId, type, sourceCount: sourceGroups.length, chunkCount: chunks.length },
|
||||
{ sourceCorpusId, type, sourceCount: sourceGroups.length, chunkCount: chunks.length },
|
||||
'document generation started'
|
||||
);
|
||||
|
||||
const document: StudyGuide | Faq | ExecutiveBrief = await generator(sourceGroups);
|
||||
|
||||
documentCacheStore.setCachedDocument(notebookId, type, document, sources);
|
||||
logger.info({ notebookId, type }, 'document generation complete');
|
||||
documentCacheStore.setCachedDocument(sourceCorpusId, type, document, sources);
|
||||
logger.info({ sourceCorpusId, type }, 'document generation complete');
|
||||
|
||||
res.json({ type, document });
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user