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 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 41x 41x 41x 41x 41x 41x 41x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 40x 40x 40x 40x 40x 40x 40x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 39x 39x 39x 39x 39x 2x 2x 2x 2x | import { createId } from '@paralleldrive/cuid2'
import { blob, index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
import { users } from './users'
/**
* Teacher Flowcharts table - User-created math flowcharts
*
* Teachers (or guests) can create their own flowcharts through the workshop.
* These can be published and shared with other users.
*/
export const teacherFlowcharts = sqliteTable(
'teacher_flowcharts',
{
/** Primary key */
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
/** User who created this flowchart */
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
// Identity
/** Display title for the flowchart */
title: text('title').notNull(),
/** Short description of what this flowchart teaches */
description: text('description'),
/** Emoji icon for the flowchart */
emoji: text('emoji').default('📊'),
/** Difficulty level */
difficulty: text('difficulty', {
enum: ['Beginner', 'Intermediate', 'Advanced'],
}),
// Content
/** FlowchartDefinition as JSON string */
definitionJson: text('definition_json').notNull(),
/** Mermaid content for visualization */
mermaidContent: text('mermaid_content').notNull(),
// Versioning
/** Version number, increments on each edit of a published flowchart */
version: integer('version').notNull().default(1),
/** If this is a new version, reference to the previous version */
parentVersionId: text('parent_version_id'),
// State
/** Current status: draft, published, or archived */
status: text('status', { enum: ['draft', 'published', 'archived'] })
.notNull()
.default('draft'),
/** When this flowchart was published (null if draft) */
publishedAt: integer('published_at', { mode: 'timestamp' }),
// Search
/** Space-separated keywords for search */
searchKeywords: text('search_keywords'),
// Embeddings
/** Semantic embedding vector for full content (title + description + topic) */
embedding: blob('embedding', { mode: 'buffer' }),
/** Semantic embedding vector for just the original prompt/topic description */
promptEmbedding: blob('prompt_embedding', { mode: 'buffer' }),
/** Version of the embedding model used (for recomputation when model changes) */
embeddingVersion: text('embedding_version'),
// Timestamps
/** When this flowchart was created */
createdAt: integer('created_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => new Date()),
/** When this flowchart was last updated */
updatedAt: integer('updated_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => new Date()),
},
(table) => ({
/** Index for finding flowcharts by user */
userIdx: index('teacher_flowcharts_user_idx').on(table.userId),
/** Index for browsing published flowcharts */
statusIdx: index('teacher_flowcharts_status_idx').on(table.status),
/** Index for finding versions of a flowchart */
parentVersionIdx: index('teacher_flowcharts_parent_version_idx').on(table.parentVersionId),
})
)
export type TeacherFlowchart = typeof teacherFlowcharts.$inferSelect
export type NewTeacherFlowchart = typeof teacherFlowcharts.$inferInsert
/**
* Workshop Sessions table - Tracks flowchart creation/editing sessions
*
* A workshop session represents an ongoing flowchart creation or editing process.
* It stores intermediate state like topic description, refinement history, and draft content.
*/
export const workshopSessions = sqliteTable(
'workshop_sessions',
{
/** Primary key */
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
/** User who owns this session */
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
// What we're working on
/** If editing an existing flowchart, reference to it */
flowchartId: text('flowchart_id').references(() => teacherFlowcharts.id, {
onDelete: 'set null',
}),
/** If remixing from an existing flowchart (can be hardcoded ID or teacher flowchart ID) */
remixFromId: text('remix_from_id'),
/** If editing a published flowchart, the ID to update on publish (instead of creating new) */
linkedPublishedId: text('linked_published_id').references(() => teacherFlowcharts.id, {
onDelete: 'set null',
}),
// Workshop state
/** Current state of the workshop */
state: text('state', {
enum: ['initial', 'generating', 'refining', 'testing', 'completed'],
})
.notNull()
.default('initial'),
// Context accumulated from conversation
/** Teacher's description of what they want to teach */
topicDescription: text('topic_description'),
/** JSON array of refinement requests made during the session */
refinementHistory: text('refinement_history'),
// Current draft (before saving to teacherFlowcharts)
/** Draft FlowchartDefinition as JSON string */
draftDefinitionJson: text('draft_definition_json'),
/** Draft Mermaid content */
draftMermaidContent: text('draft_mermaid_content'),
/** Draft title */
draftTitle: text('draft_title'),
/** Draft description */
draftDescription: text('draft_description'),
/** Draft difficulty level */
draftDifficulty: text('draft_difficulty', {
enum: ['Beginner', 'Intermediate', 'Advanced'],
}),
/** Draft emoji */
draftEmoji: text('draft_emoji'),
/** Notes/warnings from the LLM about the current draft */
draftNotes: text('draft_notes'),
/** Current reasoning text being streamed from the LLM (for reconnection) */
currentReasoningText: text('current_reasoning_text'),
/** Current version number for version history tracking */
currentVersionNumber: integer('current_version_number').default(0),
/** Active background task ID (for reconnection on page reload) */
currentTaskId: text('current_task_id'),
// Timestamps
/** When this session was created */
createdAt: integer('created_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => new Date()),
/** When this session was last updated */
updatedAt: integer('updated_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => new Date()),
/** When this session expires (7 days by default) */
expiresAt: integer('expires_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => {
const expires = new Date()
expires.setDate(expires.getDate() + 7)
return expires
}),
},
(table) => ({
/** Index for finding sessions by user */
userIdx: index('workshop_sessions_user_idx').on(table.userId),
/** Index for finding active sessions */
stateIdx: index('workshop_sessions_state_idx').on(table.state),
/** Index for cleanup of expired sessions */
expiresIdx: index('workshop_sessions_expires_idx').on(table.expiresAt),
})
)
export type WorkshopSession = typeof workshopSessions.$inferSelect
export type NewWorkshopSession = typeof workshopSessions.$inferInsert
/**
* Flowchart Version History table - Tracks version snapshots during workshop sessions
*
* Every time the LLM successfully generates or refines a flowchart, a snapshot
* is saved here. Users can view history and restore previous versions.
*/
export const flowchartVersionHistory = sqliteTable(
'flowchart_version_history',
{
/** Primary key */
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
/** The workshop session this version belongs to */
sessionId: text('session_id')
.notNull()
.references(() => workshopSessions.id, { onDelete: 'cascade' }),
/** Sequential version number within the session */
versionNumber: integer('version_number').notNull(),
// Full snapshot of draft state
/** FlowchartDefinition as JSON string */
definitionJson: text('definition_json').notNull(),
/** Mermaid content for visualization */
mermaidContent: text('mermaid_content').notNull(),
/** Title at this version */
title: text('title'),
/** Description at this version */
description: text('description'),
/** Emoji at this version */
emoji: text('emoji'),
/** Difficulty level at this version */
difficulty: text('difficulty'),
/** Notes/warnings from the LLM at this version */
notes: text('notes'),
// What created this version
/** How this version was created */
source: text('source', { enum: ['generate', 'refine'] }).notNull(),
/** The request that created this version (topic description or refinement text) */
sourceRequest: text('source_request'),
// Validation state at save time
/** Whether validation passed when this version was saved */
validationPassed: integer('validation_passed', { mode: 'boolean' }),
/** Coverage percent when this version was saved */
coveragePercent: integer('coverage_percent'),
// Timestamps
/** When this version was created */
createdAt: integer('created_at', { mode: 'timestamp' })
.notNull()
.$defaultFn(() => new Date()),
},
(table) => ({
/** Index for finding versions by session */
sessionIdx: index('fvh_session_idx').on(table.sessionId),
/** Index for finding specific version within session */
versionIdx: index('fvh_version_idx').on(table.sessionId, table.versionNumber),
})
)
export type FlowchartVersionHistory = typeof flowchartVersionHistory.$inferSelect
export type NewFlowchartVersionHistory = typeof flowchartVersionHistory.$inferInsert
|