Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 45x 45x 45x 45x 45x 45x 45x 45x 45x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | import { createId } from '@paralleldrive/cuid2'
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
import type { PracticeTypeId } from '@/constants/practiceTypes'
import type { GameResultsReport } from '@/lib/arcade/game-sdk/types'
import type { TermCountExplanation } from '@/lib/curriculum/config/term-count-scaling'
import type { SkillSet } from '@/types/tutorial'
import { players } from './players'
// ============================================================================
// Types for JSON fields
// ============================================================================
/**
* Session part types - defined centrally in @/constants/practiceTypes
* @see PRACTICE_TYPES for the full list with labels and icons
*/
export type SessionPartType = PracticeTypeId
/**
* A session part containing multiple problem slots
*/
export interface SessionPart {
/** Part number (1, 2, or 3) */
partNumber: 1 | 2 | 3
/** Type of practice for this part */
type: SessionPartType
/** Display format for problems */
format: 'vertical' | 'linear'
/** Whether the physical abacus should be used */
useAbacus: boolean
/** Problem slots in this part */
slots: ProblemSlot[]
/** Estimated duration in minutes for this part */
estimatedMinutes: number
}
/**
* A single problem slot in the session plan
*/
export interface ProblemSlot {
/** Globally unique ID for this slot (for tracing answers back to the problem) */
slotId: string
/** Position within the part */
index: number
/** Purpose of this problem */
purpose: 'focus' | 'reinforce' | 'review' | 'challenge'
/** Constraints for problem generation */
constraints: ProblemConstraints
/** Generated problem (filled when slot is reached) */
problem?: GeneratedProblem
/** Complexity bounds that were applied during generation */
complexityBounds?: {
min?: number
max?: number
}
/** Explanation of how term count range was determined (for tooltip display) */
termCountExplanation?: TermCountExplanation
}
export interface ProblemConstraints {
allowedSkills?: Partial<SkillSet>
targetSkills?: Partial<SkillSet>
forbiddenSkills?: Partial<SkillSet>
digitRange?: { min: number; max: number }
termCount?: { min: number; max: number }
operator?: 'addition' | 'subtraction' | 'mixed'
/**
* Maximum complexity budget per term.
*
* Each term's skills are costed using the SkillCostCalculator,
* which factors in both base skill complexity and student mastery.
*
* If set, terms with total cost > budget are rejected during generation.
*/
maxComplexityBudgetPerTerm?: number
/**
* Minimum complexity budget per term.
*
* If set, terms with total cost < budget are rejected during generation.
* This ensures every term exercises real skills (no trivial direct additions).
*
* Example: min=1 requires at least one five-complement per term.
*/
minComplexityBudgetPerTerm?: number
}
/**
* A single step in the generation trace
*/
export interface GenerationTraceStep {
stepNumber: number
operation: string // e.g., "0 + 3 = 3" or "3 + 4 = 7"
accumulatedBefore: number
termAdded: number
accumulatedAfter: number
skillsUsed: string[]
explanation: string
/** Complexity cost for this term (if budget system was used) */
complexityCost?: number
}
/**
* Skill practice context for a single skill - captured at generation time.
*
* Note: BKT handles fine-grained mastery estimation. This just tracks the
* skill's practice level in the student's rotation.
* Fine-grained mastery info (pKnown) should come from BKT data separately.
*/
export interface SkillMasteryDisplay {
/** Whether skill is in the student's active practice rotation */
isPracticing: boolean
/** Practice level: 'none' | 'abacus' | 'visual' */
practiceLevel: import('./player-skill-mastery').PracticeLevel
/** Base complexity cost (intrinsic to skill, 0-3) */
baseCost: number
/** Effective cost for this student (baseCost × rotationMultiplier) */
effectiveCost: number
}
/**
* Full generation trace for a problem
*/
export interface GenerationTrace {
terms: number[]
answer: number
steps: GenerationTraceStep[]
allSkills: string[]
/** Max budget constraint used during generation (if any) */
budgetConstraint?: number
/** Min budget constraint used during generation (if any) */
minBudgetConstraint?: number
/** Total complexity cost across all terms */
totalComplexityCost?: number
/** Per-skill mastery context at generation time (for UI display) */
skillMasteryContext?: Record<string, SkillMasteryDisplay>
}
export interface GeneratedProblem {
/** Problem terms (positive for add, negative for subtract) */
terms: number[]
/** Correct answer */
answer: number
/** Skills this problem exercises */
skillsRequired: string[]
/** Generation trace with per-step skills and costs */
generationTrace?: GenerationTrace
}
/**
* Summary for a single session part
*/
export interface PartSummary {
/** Part number */
partNumber: 1 | 2 | 3
/** Part type */
type: SessionPartType
/** Description (e.g., "Use Abacus", "Mental Math (Visualization)", "Mental Math (Linear)") */
description: string
/** Number of problems in this part */
problemCount: number
/** Estimated duration in minutes */
estimatedMinutes: number
}
/**
* Human-readable summary for display
*/
export interface SessionSummary {
/** Description of the focus skill */
focusDescription: string
/** Total number of problems across all parts */
totalProblemCount: number
/** Estimated total session duration */
estimatedMinutes: number
/** Summary for each part */
parts: PartSummary[]
}
/**
* Real-time session health metrics
*/
export interface SessionHealth {
/** Overall health status */
overall: 'good' | 'warning' | 'struggling'
/** Current accuracy (0-1) */
accuracy: number
/** Pace relative to expected (100 = on track) */
pacePercent: number
/** Current streak (positive = correct, negative = wrong) */
currentStreak: number
/** Average response time in milliseconds */
avgResponseTimeMs: number
}
/**
* Record of a teacher adjustment during session
*/
export interface SessionAdjustment {
timestamp: Date
type:
| 'difficulty_reduced'
| 'scaffolding_enabled'
| 'focus_narrowed'
| 'paused'
| 'resumed'
| 'extended'
| 'ended_early'
reason?: string
previousHealth: SessionHealth
}
/**
* Source of a slot result record.
*
* - 'practice': Normal practice session result (default when undefined)
* - 'recency-refresh': Teacher marked skill as recently practiced offline.
* These records update lastPracticedAt but are ZERO-WEIGHT for BKT mastery.
* They don't affect pKnown calculation - they only reset staleness.
* - 'teacher-corrected': Teacher/parent marked an incorrect result as correct.
* This is used for typo fixes or verbal confirmation. Affects BKT calculation.
* - 'teacher-excluded': Teacher/parent excluded this result from tracking.
* BKT should skip these entirely (zero-weight, no effect on pKnown).
*/
export type SlotResultSource =
| 'practice'
| 'recency-refresh'
| 'teacher-corrected'
| 'teacher-excluded'
/**
* Result of a single problem slot
*/
export interface SlotResult {
/** ID of the problem slot this result answers */
slotId: string
/** Which part this result belongs to (1, 2, or 3) */
partNumber: 1 | 2 | 3
/** Index within the part */
slotIndex: number
problem: GeneratedProblem
studentAnswer: number
isCorrect: boolean
responseTimeMs: number
skillsExercised: string[]
usedOnScreenAbacus: boolean
timestamp: Date
// ---- Help Tracking (for feedback loop) ----
/** Whether the student used help during this problem */
hadHelp: boolean
/** Number of incorrect attempts before getting the right answer */
incorrectAttempts: number
/** How help was triggered */
helpTrigger?: 'none' | 'manual' | 'auto-time' | 'auto-errors' | 'teacher-approved'
// ---- Record Source (for sentinel records) ----
/**
* Source of this record. Defaults to 'practice' when undefined.
*
* 'recency-refresh' records are sentinels inserted when a teacher clicks
* "Mark Current" to indicate offline practice. BKT uses these for
* lastPracticedAt but skips them for pKnown calculation (zero-weight).
*/
source?: SlotResultSource
// ---- Retry Tracking ----
/** Whether this was a retry attempt (not the original) */
isRetry?: boolean
/**
* Which retry epoch this result belongs to.
* 0 = original attempt, 1 = first retry, 2 = second retry
*/
epochNumber?: number
/**
* Weight applied to mastery/BKT calculation.
* Formula: 1.0 / (2 ^ epochNumber) if correct, 0 if wrong
* - Epoch 0 correct: 1.0 (100%)
* - Epoch 1 correct: 0.5 (50%)
* - Epoch 2 correct: 0.25 (25%)
* - Any wrong: 0
*/
masteryWeight?: number
/** Original slot index (for retries, tracks which slot is being retried) */
originalSlotIndex?: number
// ---- Manual Redo Tracking ----
/**
* Whether this result was from a manual redo (student tapped a completed problem).
* Manual redos don't advance the session position but can affect the retry queue.
*/
isManualRedo?: boolean
}
export type SessionStatus =
| 'draft'
| 'approved'
| 'in_progress'
| 'completed'
| 'abandoned'
| 'recency-refresh'
export type SessionFlowState =
| 'practicing'
| 'part_transition'
| 'break_pending'
| 'break_active'
| 'break_results'
| 'completed'
| 'abandoned'
// ============================================================================
// Game Break Settings
// ============================================================================
/**
* Mode for how the game is selected during a break.
* - 'auto-start': Pre-selected game starts immediately (kid can skip)
* - 'kid-chooses': Show game selection screen with optional default highlighted
*/
export type GameBreakSelectionMode = 'auto-start' | 'kid-chooses'
/**
* Type-safe partial configs for practice break games.
* Uses string index to avoid importing all game config types here.
* Runtime validation ensures type safety.
*/
export type PracticeBreakGameConfig = Record<string, Record<string, unknown>>
/**
* Settings for game breaks between practice session parts.
*
* When enabled, students get rewarded game time between parts
* (e.g., after finishing abacus section, before starting visualization).
*/
export interface GameBreakSettings {
/** Whether game breaks are enabled */
enabled: boolean
/** Maximum duration in minutes (default: 5) */
maxDurationMinutes: number
/** How the game is selected: auto-start bypasses selection, kid-chooses shows grid */
selectionMode: GameBreakSelectionMode
/**
* Selected game name, 'random', or null.
* - For auto-start: This game starts immediately (or random picks one)
* - For kid-chooses: This game is highlighted as default (or null for no highlight)
*/
selectedGame: string | 'random' | null
/**
* Pre-configured game settings, nested by game name.
* Allows teachers or the adaptive system to customize game difficulty.
* Example: { 'memory-quiz': { selectedCount: 5, displayTime: 2.0 } }
*/
gameConfig?: PracticeBreakGameConfig
/**
* Per-player allowlist of enabled game names.
* Only games in this list (that also pass manifest + system whitelist checks)
* will be available during game breaks.
*/
enabledGames?: string[]
/**
* Skip the setup phase and go directly to playing.
* When true, games use getInitialStateForPracticeBreak() to create
* a playing-ready state instead of showing the setup screen.
* Default: true for practice breaks (faster start).
*/
skipSetupPhase?: boolean
/**
* Use adaptive game selection based on student performance.
* When true, the practice system may override selectedGame and gameConfig
* based on the student's current mood and performance metrics.
*/
useAdaptiveSelection?: boolean
}
export type GameBreakEndReason = 'timeout' | 'skipped' | 'gameFinished'
// ============================================================================
// Retry System Types
// ============================================================================
/**
* A single problem queued for retry
*/
export interface RetryItem {
/** Slot ID from the original problem slot */
slotId: string
/** Original slot index within the part */
originalSlotIndex: number
/** The exact same problem to retry (never regenerated) */
problem: GeneratedProblem
/** Which epoch this retry is for (1 = first retry, 2 = second retry) */
epochNumber: number
/** Purpose from the original slot (for display) */
originalPurpose: 'focus' | 'reinforce' | 'review' | 'challenge'
}
/**
* Retry state for a single session part
*/
export interface PartRetryState {
/**
* Current epoch number within this part.
* 0 = still working original slots
* 1 = first retry epoch
* 2 = second retry epoch (final)
*/
currentEpoch: number
/**
* Problems queued for the next epoch (accumulated during current epoch).
* When a problem is wrong, it gets added here for the next retry round.
*/
pendingRetries: RetryItem[]
/**
* Problems being worked through in the current retry epoch.
* Set when starting a new epoch by moving pendingRetries here.
*/
currentEpochItems: RetryItem[]
/**
* Index into currentEpochItems (which retry we're on within this epoch).
*/
currentRetryIndex: number
/**
* Slot indices that were redeemed via manual redo (correct answer on originally wrong problem).
* When processing retry epochs, these slots are skipped since the student already got them right.
*/
redeemedSlots?: number[]
}
/**
* Retry state across all parts of a session
*/
export type SessionRetryState = {
[partIndex: number]: PartRetryState
}
// ============================================================================
// Database Table
// ============================================================================
/**
* Session plans table - planned and active practice sessions
*/
export const sessionPlans = sqliteTable(
'session_plans',
{
/** Primary key */
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
/** Foreign key to players table */
playerId: text('player_id')
.notNull()
.references(() => players.id, { onDelete: 'cascade' }),
// ---- Setup Parameters ----
/** Target session duration in minutes */
targetDurationMinutes: integer('target_duration_minutes').notNull(),
/** Estimated number of problems */
estimatedProblemCount: integer('estimated_problem_count').notNull(),
/** Average time per problem in seconds (based on student history) */
avgTimePerProblemSeconds: integer('avg_time_per_problem_seconds').notNull(),
/** Game break settings for rewards between parts */
gameBreakSettings: text('game_break_settings', {
mode: 'json',
}).$type<GameBreakSettings>(),
// ---- Plan Content (JSON) ----
/** Session parts (3 parts: abacus, visualization, linear) */
parts: text('parts', { mode: 'json' }).notNull().$type<SessionPart[]>(),
/** Human-readable summary */
summary: text('summary', { mode: 'json' }).notNull().$type<SessionSummary>(),
/** Skill IDs that were mastered when this session was generated (for mismatch detection) */
masteredSkillIds: text('mastered_skill_ids', { mode: 'json' })
.notNull()
.default('[]')
.$type<string[]>(),
// ---- Session State ----
/** Current status */
status: text('status').$type<SessionStatus>().notNull().default('draft'),
/** Authoritative UI flow state for practice lifecycle */
flowState: text('flow_state').$type<SessionFlowState>().notNull().default('practicing'),
/** Last time flow state was updated */
flowUpdatedAt: integer('flow_updated_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => new Date()),
/** Monotonic version for optimistic concurrency on flow events */
flowVersion: integer('flow_version').notNull().default(0),
/** Current part index (0-based: 0=abacus, 1=visualization, 2=linear) */
currentPartIndex: integer('current_part_index').notNull().default(0),
/** Current problem slot index within the current part (0-based) */
currentSlotIndex: integer('current_slot_index').notNull().default(0),
/** When the current game break started */
breakStartedAt: integer('break_started_at', { mode: 'timestamp' }),
/** How the last/active break ended (timeout, skipped, or game finished) */
breakReason: text('break_reason').$type<GameBreakEndReason>(),
/** Selected game for the active/last break (if any) */
breakSelectedGame: text('break_selected_game'),
/** Optional lightweight persisted game-break results payload */
breakResults: text('break_results', { mode: 'json' }).$type<GameResultsReport>(),
/** Real-time health metrics */
sessionHealth: text('session_health', {
mode: 'json',
}).$type<SessionHealth>(),
/** Teacher adjustments made during session */
adjustments: text('adjustments', { mode: 'json' })
.notNull()
.default('[]')
.$type<SessionAdjustment[]>(),
/** Results for each completed slot */
results: text('results', { mode: 'json' }).notNull().default('[]').$type<SlotResult[]>(),
// ---- Retry State ----
/** Retry state per part - tracks problems that need retrying */
retryState: text('retry_state', {
mode: 'json',
}).$type<SessionRetryState>(),
// ---- Vision/Camera State ----
/** Remote camera session ID for phone camera streaming */
remoteCameraSessionId: text('remote_camera_session_id'),
// ---- Pause State (for teacher observation control) ----
/** Whether the session is currently paused by a teacher */
isPaused: integer('is_paused', { mode: 'boolean' }).notNull().default(false),
/** When the session was paused */
pausedAt: integer('paused_at', { mode: 'timestamp' }),
/** Observer ID (teacher user ID) who paused the session */
pausedBy: text('paused_by'),
/** Optional reason for pausing (e.g., "Let's review this concept together") */
pauseReason: text('paused_reason'),
// ---- Timestamps ----
/** When the plan was created */
createdAt: integer('created_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => new Date()),
/** When the teacher approved the plan */
approvedAt: integer('approved_at', { mode: 'timestamp' }),
/** When the session actually started */
startedAt: integer('started_at', { mode: 'timestamp' }),
/** When the session was completed */
completedAt: integer('completed_at', { mode: 'timestamp' }),
},
(table) => ({
/** Index for fast lookups by playerId */
playerIdIdx: index('session_plans_player_id_idx').on(table.playerId),
/** Index for filtering by status */
statusIdx: index('session_plans_status_idx').on(table.status),
/** Index for recent plans */
createdAtIdx: index('session_plans_created_at_idx').on(table.createdAt),
})
)
export type SessionPlan = typeof sessionPlans.$inferSelect
export type NewSessionPlan = typeof sessionPlans.$inferInsert
// ============================================================================
// Helper Functions & Constants
//
// Canonical definitions live in session-plan-helpers.ts (drizzle-free).
// Re-exported here for backward compatibility with server-side code.
// Client components should import directly from session-plan-helpers.ts
// to avoid pulling drizzle-orm into the browser bundle.
// ============================================================================
export {
DEFAULT_GAME_BREAK_SETTINGS,
DEFAULT_PLAN_CONFIG,
MAX_RETRY_EPOCHS,
getSessionPlanAccuracy,
getCurrentPart,
getNextSlot,
getTotalProblemCount,
getCompletedProblemCount,
isPartComplete,
isSessionComplete,
calculateSessionHealth,
calculateMasteryWeight,
isInRetryEpoch,
getCurrentProblemInfo,
initRetryState,
getSlotRetryStatus,
calculateTotalProblemsWithRetries,
needsRetryTransition,
} from './session-plan-helpers'
export type { PlanGenerationConfig } from './session-plan-helpers'
|