Instruction file imported from Jegama/calvinist-parrot (
.github/instructions/journal-api.instructions.md). Copyright stays with the author.
Journal API Guidance
Authentication
- Use
lib/auth.ts(requireAuthenticatedUser) and verify ownership byauthorProfileId.
Streaming
- Stream NDJSON in
app/api/journal/entries/route.tswith these event types:entry_created: Initial entry saved to DBprogress: Stage updates ("call1a", "parallel")call1a_complete,call1b_complete,call1c_complete: Parallel Call 1 resultscall2_complete: Call 2 (tags/suggestions) resultcall1b_error,call1c_error,call2_error: A parallel stage faileddone: Final merged output, withpartialandfailedStageswhen a stage failederror: Error occurred
AI Pipeline
- Use
utils/journal/llm.tsfor AI calls; Call 1 runs in parallel (a/b/c) for better latency. - Persist outputs via
storeJournalAIOutputwith retry/backoff and tag merging. - Persist partial-generation status and failed stage names in
modelInfo; reprocessing is allowed only for failed or partial entries.
Data Management
- Maintain profile counters: increment on create, decrement on delete.
- Keep pagination sane: limit ≤ 50; return
total,page,limit,totalPageswith entries.