@vue-skuilder/db 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/{contentSource-2zVmcjKA.d.ts → contentSource-CSI0pJ2D.d.ts} +10 -0
  2. package/dist/core/index.cjs +62 -14
  3. package/dist/core/index.cjs.map +1 -1
  4. package/dist/core/index.d.ts +3 -3
  5. package/dist/core/interfaces/contentSource.mjs.map +1 -1
  6. package/dist/core/navigators/Pipeline.mjs +7 -1
  7. package/dist/core/navigators/Pipeline.mjs.map +1 -1
  8. package/dist/core/navigators/filters/eloDistance.mjs +17 -2
  9. package/dist/core/navigators/filters/eloDistance.mjs.map +1 -1
  10. package/dist/core/navigators/generators/prescribed.mjs +20 -10
  11. package/dist/core/navigators/generators/prescribed.mjs.map +1 -1
  12. package/dist/core/navigators/index.mjs +2 -0
  13. package/dist/core/navigators/index.mjs.map +1 -1
  14. package/dist/core/versionStamps.mjs +1 -1
  15. package/dist/{dataLayerProvider-rGyLQ93v.d.ts → dataLayerProvider-D5n1gGc_.d.ts} +1 -1
  16. package/dist/diagnostics/derive.mjs.map +1 -1
  17. package/dist/diagnostics/index.cjs +16 -3
  18. package/dist/diagnostics/index.cjs.map +1 -1
  19. package/dist/diagnostics/index.d.ts +29 -6
  20. package/dist/diagnostics/tagElo.mjs +20 -4
  21. package/dist/diagnostics/tagElo.mjs.map +1 -1
  22. package/dist/impl/couch/courseDB.mjs +5 -0
  23. package/dist/impl/couch/courseDB.mjs.map +1 -1
  24. package/dist/impl/couch/index.cjs +37 -2
  25. package/dist/impl/couch/index.cjs.map +1 -1
  26. package/dist/impl/couch/index.d.ts +4 -2
  27. package/dist/impl/static/courseDB.mjs +5 -0
  28. package/dist/impl/static/courseDB.mjs.map +1 -1
  29. package/dist/impl/static/index.cjs +37 -2
  30. package/dist/impl/static/index.cjs.map +1 -1
  31. package/dist/impl/static/index.d.ts +4 -2
  32. package/dist/index.cjs +80 -16
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.ts +3 -3
  35. package/dist/study/SessionController.mjs +1 -0
  36. package/dist/study/SessionController.mjs.map +1 -1
  37. package/dist/study/services/tagRecent.mjs +2 -1
  38. package/dist/study/services/tagRecent.mjs.map +1 -1
  39. package/package.json +3 -3
  40. package/src/core/interfaces/contentSource.ts +7 -0
  41. package/src/core/navigators/Pipeline.ts +7 -0
  42. package/src/core/navigators/filters/eloDistance.ts +31 -2
  43. package/src/core/navigators/generators/prescribed.ts +55 -11
  44. package/src/core/navigators/generators/types.ts +3 -0
  45. package/src/core/navigators/index.ts +5 -0
  46. package/src/diagnostics/derive.ts +6 -1
  47. package/src/diagnostics/tagElo.ts +43 -3
  48. package/src/impl/couch/courseDB.ts +13 -0
  49. package/src/impl/static/courseDB.ts +13 -0
  50. package/src/study/SessionController.ts +3 -0
  51. package/src/study/services/tagRecent.test.ts +57 -3
  52. package/src/study/services/tagRecent.ts +8 -1
  53. package/tests/core/navigators/eloDistanceFilter.test.ts +15 -0
@@ -1,8 +1,8 @@
1
1
  import { T as TagStub, a as Tag, S as SkuilderCourseData, Q as QualifiedCardID } from '../../types-legacy-DdVjg81H.js';
2
2
  import { Moment } from 'moment';
3
3
  export { h as hexEncode } from '../../userDBKeys-ne1g4Xuq.js';
4
- import { o as StudyContentSource, U as UserDBInterface, G as GeneratorResult, a as CoursesDBInterface, C as CourseDBInterface, b as CourseInfo, D as DataLayerResult, c as ContentNavigationStrategyData, d as ContentNavigator, R as ReplanHints, S as StudySessionItem, f as ScheduledCard } from '../../contentSource-2zVmcjKA.js';
5
- export { v as ContentSourceID, p as StudySessionFailedItem, q as StudySessionFailedNewItem, r as StudySessionFailedReviewItem, s as StudySessionNewItem, t as StudySessionReviewItem, w as getStudySource, u as isReview } from '../../contentSource-2zVmcjKA.js';
4
+ import { o as StudyContentSource, U as UserDBInterface, G as GeneratorResult, a as CoursesDBInterface, C as CourseDBInterface, b as CourseInfo, D as DataLayerResult, c as ContentNavigationStrategyData, d as ContentNavigator, R as ReplanHints, S as StudySessionItem, f as ScheduledCard } from '../../contentSource-CSI0pJ2D.js';
5
+ export { v as ContentSourceID, p as StudySessionFailedItem, q as StudySessionFailedNewItem, r as StudySessionFailedReviewItem, s as StudySessionNewItem, t as StudySessionReviewItem, w as getStudySource, u as isReview } from '../../contentSource-CSI0pJ2D.js';
6
6
  import { A as AdminDBInterface, a as AssignedContent, S as StudentClassroomDBInterface, T as TeacherClassroomDBInterface } from '../../classroomDB-DLTtLZct.js';
7
7
  import * as _vue_skuilder_common from '@vue-skuilder/common';
8
8
  import { ClassroomConfig, DataShape, CourseElo, CourseConfig as CourseConfig$1 } from '@vue-skuilder/common';
@@ -326,6 +326,8 @@ declare class CourseDB implements CourseDBInterface {
326
326
  private _cachedNavigator;
327
327
  private readonly _navigatorTtlMs;
328
328
  setEphemeralHints(hints: ReplanHints): void;
329
+ private _sessionId;
330
+ setSessionId(sessionId: string): void;
329
331
  /**
330
332
  * Forward a presentation to the navigator (a new card restarts its intake
331
333
  * clock). Builds the navigator if the cached one has expired.
@@ -320,6 +320,10 @@ var StaticCourseDB = class {
320
320
  setEphemeralHints(hints) {
321
321
  this._pendingHints = hints;
322
322
  }
323
+ _sessionId = null;
324
+ setSessionId(sessionId) {
325
+ this._sessionId = sessionId;
326
+ }
323
327
  /** Forward a presentation to the navigator (a new card restarts its intake clock). */
324
328
  notePresented(card) {
325
329
  if (card.status !== "new") return;
@@ -332,6 +336,7 @@ var StaticCourseDB = class {
332
336
  navigator.setEphemeralHints(this._pendingHints);
333
337
  this._pendingHints = null;
334
338
  }
339
+ if (this._sessionId) navigator.setSessionId(this._sessionId);
335
340
  return navigator.getWeightedCards(limit);
336
341
  } catch (e) {
337
342
  logger.error(`[static/courseDB] Error getting weighted cards: ${e}`);
@@ -1 +1 @@
1
- {"version":3,"file":"courseDB.mjs","names":[],"sources":["../../../src/impl/static/courseDB.ts"],"sourcesContent":["// packages/db/src/impl/static/courseDB.ts\n\nimport {\n CourseDBInterface,\n UserDBInterface,\n CourseInfo,\n StudySessionItem,\n type StudyContentSource,\n} from '../../core/interfaces';\nimport type { GeneratorResult, ReplanHints } from '../../core/navigators/generators/types';\nimport { StaticDataUnpacker } from './StaticDataUnpacker';\nimport { StaticCourseManifest } from '../../util/packer/types';\nimport { CourseConfig, CourseElo, DataShape, Status } from '@vue-skuilder/common';\nimport {\n Tag,\n TagStub,\n DocType,\n SkuilderCourseData,\n QualifiedCardID,\n DocTypePrefixes,\n} from '../../core/types/types-legacy';\nimport { DataLayerResult } from '../../core/types/db';\nimport { ContentNavigationStrategyData } from '../../core/types/contentNavigationStrategy';\n\nimport { ContentNavigator } from '../../core/navigators';\nimport { logger } from '../../util/logger';\nimport { createDefaultPipeline } from '@db/core/navigators/defaults';\nimport { PipelineAssembler } from '@db/core/navigators/PipelineAssembler';\n\nexport class StaticCourseDB implements CourseDBInterface {\n constructor(\n private courseId: string,\n private unpacker: StaticDataUnpacker,\n private userDB: UserDBInterface,\n private manifest: StaticCourseManifest\n ) {}\n\n getCourseID(): string {\n return this.courseId;\n }\n\n async getCourseConfig(): Promise<CourseConfig> {\n if (this.manifest.courseConfig != null) {\n return this.manifest.courseConfig;\n } else {\n throw new Error(`Course config not found for course ${this.courseId}`);\n }\n }\n\n async updateCourseConfig(_cfg: CourseConfig): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot update course config in static mode');\n }\n\n async getCourseInfo(): Promise<CourseInfo> {\n // Count only cards, not all documents\n // Use chunks metadata to count card documents specifically\n const cardCount = this.manifest.chunks\n .filter((chunk) => chunk.docType === DocType.CARD)\n .reduce((total, chunk) => total + chunk.documentCount, 0);\n\n return {\n cardCount,\n registeredUsers: 0, // Always 0 in static mode\n };\n }\n\n async getCourseDoc<T extends SkuilderCourseData>(\n id: string,\n _options?: PouchDB.Core.GetOptions\n ): Promise<T> {\n return this.unpacker.getDocument(id);\n }\n\n async getCourseDocs<T extends SkuilderCourseData>(\n ids: string[],\n _options?: PouchDB.Core.AllDocsOptions\n ): Promise<PouchDB.Core.AllDocsWithKeysResponse<{} & T>> {\n const rows = await Promise.all(\n ids.map(async (id) => {\n try {\n const doc = await this.unpacker.getDocument(id);\n return {\n id,\n key: id,\n value: { rev: '1-static' },\n doc,\n };\n } catch {\n return {\n key: id,\n error: 'not_found' as const,\n };\n }\n })\n );\n\n return {\n total_rows: ids.length,\n offset: 0,\n rows,\n };\n }\n\n async getCardsByELO(\n elo: number,\n limit?: number\n ): Promise<\n {\n courseID: string;\n cardID: string;\n elo?: number;\n }[]\n > {\n return (await this.unpacker.queryByElo(elo, limit || 25)).map((card) => {\n const [courseID, cardID, elo] = card.split('-');\n return { courseID, cardID, elo: elo ? parseInt(elo) : undefined };\n });\n }\n\n async getCardEloData(cardIds: string[]): Promise<CourseElo[]> {\n const results = await Promise.all(\n cardIds.map(async (id) => {\n try {\n const card = await this.unpacker.getDocument(id);\n return card.elo || { global: { score: 1000, count: 0 }, tags: {}, misc: {} };\n } catch {\n return { global: { score: 1000, count: 0 }, tags: {}, misc: {} };\n }\n })\n );\n return results;\n }\n\n async updateCardElo(cardId: string, _elo: CourseElo): Promise<PouchDB.Core.Response> {\n // No updates to card data in static mode - this is a noop\n return { ok: true, id: cardId, rev: '1-static' };\n }\n\n async getCardsCenteredAtELO(\n options: { limit: number; elo: 'user' | 'random' | number },\n filter?: (id: QualifiedCardID) => boolean\n ): Promise<StudySessionItem[]> {\n let targetElo = typeof options.elo === 'number' ? options.elo : 1000;\n\n if (options.elo === 'user') {\n // Get user's ELO for this course\n try {\n const regDoc = await this.userDB.getCourseRegistrationsDoc();\n const courseReg = regDoc.courses.find((c) => c.courseID === this.courseId);\n if (courseReg && typeof courseReg.elo === 'object') {\n targetElo = courseReg.elo.global.score;\n }\n } catch {\n targetElo = 1000;\n }\n } else if (options.elo === 'random') {\n targetElo = 800 + Math.random() * 400; // Random between 800-1200\n }\n\n let cardIds = (await this.unpacker.queryByElo(targetElo, options.limit * 2)).map((c) => {\n return {\n cardID: c,\n courseID: this.courseId,\n };\n });\n\n if (filter) {\n cardIds = cardIds.filter(filter);\n }\n\n return cardIds.slice(0, options.limit).map((card) => ({\n status: 'new' as const,\n // qualifiedID: `${this.courseId}-${cardId}`,\n cardID: card.cardID,\n contentSourceType: 'course' as const,\n contentSourceID: this.courseId,\n courseID: this.courseId,\n }));\n }\n\n async getAppliedTags(cardId: string): Promise<PouchDB.Query.Response<TagStub>> {\n try {\n const tagsIndex = await this.unpacker.getTagsIndex();\n const cardTags = tagsIndex.byCard[cardId] || [];\n\n const rows = await Promise.all(\n cardTags.map(async (tagName) => {\n const tagId = `${DocType.TAG}-${tagName}`;\n\n try {\n // Try to get the full tag document\n const tagDoc = await this.unpacker.getDocument(tagId);\n return {\n id: tagId,\n key: cardId,\n value: {\n name: tagDoc.name,\n snippet: tagDoc.snippet,\n count: tagDoc.taggedCards?.length || 0,\n },\n };\n } catch (error) {\n if (error && (error as PouchDB.Core.Error).status === 404) {\n logger.warn(`Tag document not found for ${tagName}, creating stub`);\n } else {\n logger.error(`Error getting tag document for ${tagName}:`, error);\n throw error;\n }\n // If tag document not found, create a minimal stub\n return {\n id: tagId,\n key: cardId,\n value: {\n name: tagName,\n snippet: `Tag: ${tagName}`,\n count: tagsIndex.byTag[tagName]?.length || 0,\n },\n };\n }\n })\n );\n\n return {\n total_rows: rows.length,\n offset: 0,\n rows,\n };\n } catch (error) {\n logger.error(`Error getting applied tags for card ${cardId}:`, error);\n return {\n total_rows: 0,\n offset: 0,\n rows: [],\n };\n }\n }\n\n async getAppliedTagsBatch(cardIds: string[]): Promise<Map<string, string[]>> {\n const tagsIndex = await this.unpacker.getTagsIndex();\n const tagsByCard = new Map<string, string[]>();\n\n for (const cardId of cardIds) {\n tagsByCard.set(cardId, tagsIndex.byCard[cardId] || []);\n }\n\n return tagsByCard;\n }\n\n async getAllCardIds(): Promise<string[]> {\n const tagsIndex = await this.unpacker.getTagsIndex();\n return Object.keys(tagsIndex.byCard);\n }\n\n async addTagToCard(_cardId: string, _tagId: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot modify tags in static mode');\n }\n\n async removeTagFromCard(_cardId: string, _tagId: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot modify tags in static mode');\n }\n\n async createTag(_tagName: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot create tags in static mode');\n }\n\n async getTag(tagName: string): Promise<Tag> {\n return this.unpacker.getDocument(`${DocType.TAG}-${tagName}`);\n }\n\n async updateTag(_tag: Tag): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot update tags in static mode');\n }\n\n async getCourseTagStubs(): Promise<PouchDB.Core.AllDocsResponse<Tag>> {\n try {\n const tagsIndex = await this.unpacker.getTagsIndex();\n\n if (!tagsIndex || !tagsIndex.byTag) {\n logger.warn('Tags index not found or empty');\n return {\n total_rows: 0,\n offset: 0,\n rows: [],\n };\n }\n\n // Create tag stubs from the index\n const tagNames = Object.keys(tagsIndex.byTag);\n const rows = await Promise.all(\n tagNames.map(async (tagName) => {\n const cardIds = tagsIndex.byTag[tagName] || [];\n const tagId = `${DocType.TAG}-${tagName}`;\n\n try {\n // Try to get the full tag document\n const tagDoc = await this.unpacker.getDocument(tagId);\n return {\n id: tagId,\n key: tagId,\n value: { rev: '1-static' },\n doc: tagDoc,\n };\n } catch (error) {\n // If tag document not found, create a minimal stub\n if (error && (error as PouchDB.Core.Error).status === 404) {\n logger.warn(`Tag document not found for ${tagName}, creating stub`);\n const stubDoc = {\n _id: tagId,\n _rev: '1-static',\n course: this.courseId,\n docType: DocType.TAG,\n name: tagName,\n snippet: `Tag: ${tagName}`,\n wiki: '',\n taggedCards: cardIds,\n author: 'system',\n };\n return {\n id: tagId,\n key: tagId,\n value: { rev: '1-static' },\n doc: stubDoc,\n };\n } else {\n logger.error(`Error getting tag document for ${tagName}:`, error);\n throw error;\n }\n }\n })\n );\n\n return {\n total_rows: rows.length,\n offset: 0,\n rows,\n };\n } catch (error) {\n logger.error('Failed to get course tag stubs:', error);\n return {\n total_rows: 0,\n offset: 0,\n rows: [],\n };\n }\n }\n\n async addNote(\n _codeCourse: string,\n _shape: DataShape,\n _data: unknown,\n _author: string,\n _tags: string[],\n _uploads?: { [key: string]: PouchDB.Core.FullAttachment },\n _elo?: CourseElo\n ): Promise<DataLayerResult> {\n return {\n status: Status.error,\n message: 'Cannot add notes in static mode',\n };\n }\n\n async removeCard(_cardId: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot remove cards in static mode');\n }\n\n async getInexperiencedCards(): Promise<any[]> {\n // Would need to be pre-computed in indices\n return [];\n }\n\n // Navigation Strategy Manager implementation\n async getNavigationStrategy(id: string): Promise<ContentNavigationStrategyData> {\n try {\n return await this.unpacker.getDocument(id);\n } catch (error) {\n logger.error(`[static/courseDB] Strategy ${id} not found: ${error}`);\n throw error;\n }\n }\n\n async getAllNavigationStrategies(): Promise<ContentNavigationStrategyData[]> {\n const prefix = DocTypePrefixes[DocType.NAVIGATION_STRATEGY];\n try {\n const docs = await this.unpacker.getAllDocumentsByPrefix(prefix);\n return docs as ContentNavigationStrategyData[];\n } catch (error) {\n logger.warn(`[static/courseDB] Error loading navigation strategies: ${error}`);\n return []; // Fall back to default pipeline\n }\n }\n\n async addNavigationStrategy(_data: ContentNavigationStrategyData): Promise<void> {\n throw new Error('Cannot add navigation strategies in static mode');\n }\n\n async updateNavigationStrategy(_id: string, _data: ContentNavigationStrategyData): Promise<void> {\n throw new Error('Cannot update navigation strategies in static mode');\n }\n\n /**\n * Create a ContentNavigator for this course.\n *\n * Loads navigation strategy documents from static data and uses PipelineAssembler\n * to build a Pipeline. Falls back to default pipeline if no strategies found.\n */\n async createNavigator(user: UserDBInterface): Promise<ContentNavigator> {\n try {\n const allStrategies = await this.getAllNavigationStrategies();\n\n if (allStrategies.length === 0) {\n logger.debug(\n '[static/courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])'\n );\n return createDefaultPipeline(user, this);\n }\n\n // Use PipelineAssembler to build Pipeline from strategy documents\n const assembler = new PipelineAssembler();\n const { pipeline, generatorStrategies, filterStrategies, warnings } =\n await assembler.assemble({\n strategies: allStrategies,\n user,\n course: this,\n });\n\n // Log warnings\n for (const warning of warnings) {\n logger.warn(`[PipelineAssembler] ${warning}`);\n }\n\n if (!pipeline) {\n logger.debug('[static/courseDB] Pipeline assembly failed, using default pipeline');\n return createDefaultPipeline(user, this);\n }\n\n logger.debug(\n `[static/courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`\n );\n return pipeline;\n } catch (e) {\n logger.error(`[static/courseDB] Error creating navigator: ${e}`);\n throw e;\n }\n }\n\n // Study Content Source implementation\n\n private _pendingHints: ReplanHints | null = null;\n\n setEphemeralHints(hints: ReplanHints): void {\n this._pendingHints = hints;\n }\n\n /** Forward a presentation to the navigator (a new card restarts its intake clock). */\n notePresented(card: { cardId: string; courseId: string; status: string }): void {\n if (card.status !== 'new') return;\n void this.createNavigator(this.userDB)\n .then((navigator) => (navigator as StudyContentSource).notePresented?.(card))\n .catch((e) => logger.warn(`[static/courseDB] Could not note a presentation: ${e}`));\n }\n\n async getWeightedCards(limit: number): Promise<GeneratorResult> {\n try {\n const navigator = await this.createNavigator(this.userDB);\n // Forward any pending hints to the Pipeline\n if (this._pendingHints) {\n navigator.setEphemeralHints(this._pendingHints);\n this._pendingHints = null;\n }\n return navigator.getWeightedCards(limit);\n } catch (e) {\n logger.error(`[static/courseDB] Error getting weighted cards: ${e}`);\n throw e;\n }\n }\n\n // Attachment helper methods (internal use, not part of interface)\n\n /**\n * Get attachment URL for a document and attachment name\n * Internal helper method for static attachment serving\n */\n getAttachmentUrl(docId: string, attachmentName: string): string {\n return this.unpacker.getAttachmentUrl(docId, attachmentName);\n }\n\n /**\n * Load attachment as blob/buffer\n * Internal helper method for static attachment serving\n */\n async getAttachmentBlob(docId: string, attachmentName: string): Promise<Blob | Buffer | null> {\n return this.unpacker.getAttachmentBlob(docId, attachmentName);\n }\n\n // Admin search methods\n async searchCards(_query: string): Promise<any[]> {\n // In static mode, return empty results for now\n // Could be implemented with local search if needed\n return [];\n }\n\n async find(_request: PouchDB.Find.FindRequest<any>): Promise<PouchDB.Find.FindResponse<any>> {\n // In static mode, return empty results for now\n // Could be implemented with local search if needed\n return {\n docs: [],\n warning: 'Find operations not supported in static mode',\n } as any;\n }\n}\n"],"mappings":";;;;;;;AA6BA,IAAa,iBAAb,MAAyD;CACvD,YACE,UACA,UACA,QACA,UACA;AAJQ,OAAA,WAAA;AACA,OAAA,WAAA;AACA,OAAA,SAAA;AACA,OAAA,WAAA;;CAGV,cAAsB;AACpB,SAAO,KAAK;;CAGd,MAAM,kBAAyC;AAC7C,MAAI,KAAK,SAAS,gBAAgB,KAChC,QAAO,KAAK,SAAS;MAErB,OAAM,IAAI,MAAM,sCAAsC,KAAK,WAAW;;CAI1E,MAAM,mBAAmB,MAAoD;AAC3E,QAAM,IAAI,MAAM,6CAA6C;;CAG/D,MAAM,gBAAqC;AAOzC,SAAO;GACL,WALgB,KAAK,SAAS,OAC7B,QAAQ,UAAU,MAAM,YAAY,QAAQ,KAAK,CACjD,QAAQ,OAAO,UAAU,QAAQ,MAAM,eAAe,EAAE;GAIzD,iBAAiB;GAClB;;CAGH,MAAM,aACJ,IACA,UACY;AACZ,SAAO,KAAK,SAAS,YAAY,GAAG;;CAGtC,MAAM,cACJ,KACA,UACuD;EACvD,MAAM,OAAO,MAAM,QAAQ,IACzB,IAAI,IAAI,OAAO,OAAO;AACpB,OAAI;AAEF,WAAO;KACL;KACA,KAAK;KACL,OAAO,EAAE,KAAK,YAAY;KAC1B,KALU,MAAM,KAAK,SAAS,YAAY,GAAG;KAM9C;WACK;AACN,WAAO;KACL,KAAK;KACL,OAAO;KACR;;IAEH,CACH;AAED,SAAO;GACL,YAAY,IAAI;GAChB,QAAQ;GACR;GACD;;CAGH,MAAM,cACJ,KACA,OAOA;AACA,UAAQ,MAAM,KAAK,SAAS,WAAW,KA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AU;AACb,WAAO,MAAM,qEAAqE;AAClF,WAAO,sBAAsB,MAAM,KAAK;;AAG1C,UAAO,MACL,mDAAmD,oBAAoB,OAAO,oBAAoB,iBAAiB,OAAO,YAC3H;AACD,UAAO;WACA,GAAG;AACV,UAAO,MAAM,+CAA+C,IAAI;AAChE,SAAM;;;CAMV,gBAA4C;CAE5C,kBAAkB,OAA0B;AAC1C,OAAK,gBAAgB;;;CAIvB,cAAc,MAAkE;AAC9E,MAAI,KAAK,WAAW,MAAO;AACtB,OAAK,gBAAgB,KAAK,OAAO,CACnC,MAAM,cAAe,UAAiC,gBAAgB,KAAK,CAAC,CAC5E,OAAO,MAAM,OAAO,KAAK,oDAAoD,IAAI,CAAC;;CAGvF,MAAM,iBAAiB,OAAyC;AAC9D,MAAI;GACF,MAAM,YAAY,MAAM,KAAK,gBAAgB,KAAK,OAAO;AAEzD,OAAI,KAAK,eAAe;AACtB,cAAU,kBAAkB,KAAK,cAAc;AAC/C,SAAK,gBAAgB;;AAEvB,UAAO,UAAU,iBAAiB,MAAM;WACjC,GAAG;AACV,UAAO,MAAM,mDAAmD,IAAI;AACpE,SAAM;;;;;;;CAUV,iBAAiB,OAAe,gBAAgC;AAC9D,SAAO,KAAK,SAAS,iBAAiB,OAAO,eAAe;;;;;;CAO9D,MAAM,kBAAkB,OAAe,gBAAuD;AAC5F,SAAO,KAAK,SAAS,kBAAkB,OAAO,eAAe;;CAI/D,MAAM,YAAY,QAAgC;AAGhD,SAAO,EAAE;;CAGX,MAAM,KAAK,UAAkF;AAG3F,SAAO;GACL,MAAM,EAAE;GACR,SAAS;GACV"}
1
+ {"version":3,"file":"courseDB.mjs","names":[],"sources":["../../../src/impl/static/courseDB.ts"],"sourcesContent":["// packages/db/src/impl/static/courseDB.ts\n\nimport {\n CourseDBInterface,\n UserDBInterface,\n CourseInfo,\n StudySessionItem,\n type StudyContentSource,\n} from '../../core/interfaces';\nimport type { GeneratorResult, ReplanHints } from '../../core/navigators/generators/types';\nimport { StaticDataUnpacker } from './StaticDataUnpacker';\nimport { StaticCourseManifest } from '../../util/packer/types';\nimport { CourseConfig, CourseElo, DataShape, Status } from '@vue-skuilder/common';\nimport {\n Tag,\n TagStub,\n DocType,\n SkuilderCourseData,\n QualifiedCardID,\n DocTypePrefixes,\n} from '../../core/types/types-legacy';\nimport { DataLayerResult } from '../../core/types/db';\nimport { ContentNavigationStrategyData } from '../../core/types/contentNavigationStrategy';\n\nimport { ContentNavigator } from '../../core/navigators';\nimport { logger } from '../../util/logger';\nimport { createDefaultPipeline } from '@db/core/navigators/defaults';\nimport { PipelineAssembler } from '@db/core/navigators/PipelineAssembler';\n\nexport class StaticCourseDB implements CourseDBInterface {\n constructor(\n private courseId: string,\n private unpacker: StaticDataUnpacker,\n private userDB: UserDBInterface,\n private manifest: StaticCourseManifest\n ) {}\n\n getCourseID(): string {\n return this.courseId;\n }\n\n async getCourseConfig(): Promise<CourseConfig> {\n if (this.manifest.courseConfig != null) {\n return this.manifest.courseConfig;\n } else {\n throw new Error(`Course config not found for course ${this.courseId}`);\n }\n }\n\n async updateCourseConfig(_cfg: CourseConfig): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot update course config in static mode');\n }\n\n async getCourseInfo(): Promise<CourseInfo> {\n // Count only cards, not all documents\n // Use chunks metadata to count card documents specifically\n const cardCount = this.manifest.chunks\n .filter((chunk) => chunk.docType === DocType.CARD)\n .reduce((total, chunk) => total + chunk.documentCount, 0);\n\n return {\n cardCount,\n registeredUsers: 0, // Always 0 in static mode\n };\n }\n\n async getCourseDoc<T extends SkuilderCourseData>(\n id: string,\n _options?: PouchDB.Core.GetOptions\n ): Promise<T> {\n return this.unpacker.getDocument(id);\n }\n\n async getCourseDocs<T extends SkuilderCourseData>(\n ids: string[],\n _options?: PouchDB.Core.AllDocsOptions\n ): Promise<PouchDB.Core.AllDocsWithKeysResponse<{} & T>> {\n const rows = await Promise.all(\n ids.map(async (id) => {\n try {\n const doc = await this.unpacker.getDocument(id);\n return {\n id,\n key: id,\n value: { rev: '1-static' },\n doc,\n };\n } catch {\n return {\n key: id,\n error: 'not_found' as const,\n };\n }\n })\n );\n\n return {\n total_rows: ids.length,\n offset: 0,\n rows,\n };\n }\n\n async getCardsByELO(\n elo: number,\n limit?: number\n ): Promise<\n {\n courseID: string;\n cardID: string;\n elo?: number;\n }[]\n > {\n return (await this.unpacker.queryByElo(elo, limit || 25)).map((card) => {\n const [courseID, cardID, elo] = card.split('-');\n return { courseID, cardID, elo: elo ? parseInt(elo) : undefined };\n });\n }\n\n async getCardEloData(cardIds: string[]): Promise<CourseElo[]> {\n const results = await Promise.all(\n cardIds.map(async (id) => {\n try {\n const card = await this.unpacker.getDocument(id);\n return card.elo || { global: { score: 1000, count: 0 }, tags: {}, misc: {} };\n } catch {\n return { global: { score: 1000, count: 0 }, tags: {}, misc: {} };\n }\n })\n );\n return results;\n }\n\n async updateCardElo(cardId: string, _elo: CourseElo): Promise<PouchDB.Core.Response> {\n // No updates to card data in static mode - this is a noop\n return { ok: true, id: cardId, rev: '1-static' };\n }\n\n async getCardsCenteredAtELO(\n options: { limit: number; elo: 'user' | 'random' | number },\n filter?: (id: QualifiedCardID) => boolean\n ): Promise<StudySessionItem[]> {\n let targetElo = typeof options.elo === 'number' ? options.elo : 1000;\n\n if (options.elo === 'user') {\n // Get user's ELO for this course\n try {\n const regDoc = await this.userDB.getCourseRegistrationsDoc();\n const courseReg = regDoc.courses.find((c) => c.courseID === this.courseId);\n if (courseReg && typeof courseReg.elo === 'object') {\n targetElo = courseReg.elo.global.score;\n }\n } catch {\n targetElo = 1000;\n }\n } else if (options.elo === 'random') {\n targetElo = 800 + Math.random() * 400; // Random between 800-1200\n }\n\n let cardIds = (await this.unpacker.queryByElo(targetElo, options.limit * 2)).map((c) => {\n return {\n cardID: c,\n courseID: this.courseId,\n };\n });\n\n if (filter) {\n cardIds = cardIds.filter(filter);\n }\n\n return cardIds.slice(0, options.limit).map((card) => ({\n status: 'new' as const,\n // qualifiedID: `${this.courseId}-${cardId}`,\n cardID: card.cardID,\n contentSourceType: 'course' as const,\n contentSourceID: this.courseId,\n courseID: this.courseId,\n }));\n }\n\n async getAppliedTags(cardId: string): Promise<PouchDB.Query.Response<TagStub>> {\n try {\n const tagsIndex = await this.unpacker.getTagsIndex();\n const cardTags = tagsIndex.byCard[cardId] || [];\n\n const rows = await Promise.all(\n cardTags.map(async (tagName) => {\n const tagId = `${DocType.TAG}-${tagName}`;\n\n try {\n // Try to get the full tag document\n const tagDoc = await this.unpacker.getDocument(tagId);\n return {\n id: tagId,\n key: cardId,\n value: {\n name: tagDoc.name,\n snippet: tagDoc.snippet,\n count: tagDoc.taggedCards?.length || 0,\n },\n };\n } catch (error) {\n if (error && (error as PouchDB.Core.Error).status === 404) {\n logger.warn(`Tag document not found for ${tagName}, creating stub`);\n } else {\n logger.error(`Error getting tag document for ${tagName}:`, error);\n throw error;\n }\n // If tag document not found, create a minimal stub\n return {\n id: tagId,\n key: cardId,\n value: {\n name: tagName,\n snippet: `Tag: ${tagName}`,\n count: tagsIndex.byTag[tagName]?.length || 0,\n },\n };\n }\n })\n );\n\n return {\n total_rows: rows.length,\n offset: 0,\n rows,\n };\n } catch (error) {\n logger.error(`Error getting applied tags for card ${cardId}:`, error);\n return {\n total_rows: 0,\n offset: 0,\n rows: [],\n };\n }\n }\n\n async getAppliedTagsBatch(cardIds: string[]): Promise<Map<string, string[]>> {\n const tagsIndex = await this.unpacker.getTagsIndex();\n const tagsByCard = new Map<string, string[]>();\n\n for (const cardId of cardIds) {\n tagsByCard.set(cardId, tagsIndex.byCard[cardId] || []);\n }\n\n return tagsByCard;\n }\n\n async getAllCardIds(): Promise<string[]> {\n const tagsIndex = await this.unpacker.getTagsIndex();\n return Object.keys(tagsIndex.byCard);\n }\n\n async addTagToCard(_cardId: string, _tagId: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot modify tags in static mode');\n }\n\n async removeTagFromCard(_cardId: string, _tagId: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot modify tags in static mode');\n }\n\n async createTag(_tagName: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot create tags in static mode');\n }\n\n async getTag(tagName: string): Promise<Tag> {\n return this.unpacker.getDocument(`${DocType.TAG}-${tagName}`);\n }\n\n async updateTag(_tag: Tag): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot update tags in static mode');\n }\n\n async getCourseTagStubs(): Promise<PouchDB.Core.AllDocsResponse<Tag>> {\n try {\n const tagsIndex = await this.unpacker.getTagsIndex();\n\n if (!tagsIndex || !tagsIndex.byTag) {\n logger.warn('Tags index not found or empty');\n return {\n total_rows: 0,\n offset: 0,\n rows: [],\n };\n }\n\n // Create tag stubs from the index\n const tagNames = Object.keys(tagsIndex.byTag);\n const rows = await Promise.all(\n tagNames.map(async (tagName) => {\n const cardIds = tagsIndex.byTag[tagName] || [];\n const tagId = `${DocType.TAG}-${tagName}`;\n\n try {\n // Try to get the full tag document\n const tagDoc = await this.unpacker.getDocument(tagId);\n return {\n id: tagId,\n key: tagId,\n value: { rev: '1-static' },\n doc: tagDoc,\n };\n } catch (error) {\n // If tag document not found, create a minimal stub\n if (error && (error as PouchDB.Core.Error).status === 404) {\n logger.warn(`Tag document not found for ${tagName}, creating stub`);\n const stubDoc = {\n _id: tagId,\n _rev: '1-static',\n course: this.courseId,\n docType: DocType.TAG,\n name: tagName,\n snippet: `Tag: ${tagName}`,\n wiki: '',\n taggedCards: cardIds,\n author: 'system',\n };\n return {\n id: tagId,\n key: tagId,\n value: { rev: '1-static' },\n doc: stubDoc,\n };\n } else {\n logger.error(`Error getting tag document for ${tagName}:`, error);\n throw error;\n }\n }\n })\n );\n\n return {\n total_rows: rows.length,\n offset: 0,\n rows,\n };\n } catch (error) {\n logger.error('Failed to get course tag stubs:', error);\n return {\n total_rows: 0,\n offset: 0,\n rows: [],\n };\n }\n }\n\n async addNote(\n _codeCourse: string,\n _shape: DataShape,\n _data: unknown,\n _author: string,\n _tags: string[],\n _uploads?: { [key: string]: PouchDB.Core.FullAttachment },\n _elo?: CourseElo\n ): Promise<DataLayerResult> {\n return {\n status: Status.error,\n message: 'Cannot add notes in static mode',\n };\n }\n\n async removeCard(_cardId: string): Promise<PouchDB.Core.Response> {\n throw new Error('Cannot remove cards in static mode');\n }\n\n async getInexperiencedCards(): Promise<any[]> {\n // Would need to be pre-computed in indices\n return [];\n }\n\n // Navigation Strategy Manager implementation\n async getNavigationStrategy(id: string): Promise<ContentNavigationStrategyData> {\n try {\n return await this.unpacker.getDocument(id);\n } catch (error) {\n logger.error(`[static/courseDB] Strategy ${id} not found: ${error}`);\n throw error;\n }\n }\n\n async getAllNavigationStrategies(): Promise<ContentNavigationStrategyData[]> {\n const prefix = DocTypePrefixes[DocType.NAVIGATION_STRATEGY];\n try {\n const docs = await this.unpacker.getAllDocumentsByPrefix(prefix);\n return docs as ContentNavigationStrategyData[];\n } catch (error) {\n logger.warn(`[static/courseDB] Error loading navigation strategies: ${error}`);\n return []; // Fall back to default pipeline\n }\n }\n\n async addNavigationStrategy(_data: ContentNavigationStrategyData): Promise<void> {\n throw new Error('Cannot add navigation strategies in static mode');\n }\n\n async updateNavigationStrategy(_id: string, _data: ContentNavigationStrategyData): Promise<void> {\n throw new Error('Cannot update navigation strategies in static mode');\n }\n\n /**\n * Create a ContentNavigator for this course.\n *\n * Loads navigation strategy documents from static data and uses PipelineAssembler\n * to build a Pipeline. Falls back to default pipeline if no strategies found.\n */\n async createNavigator(user: UserDBInterface): Promise<ContentNavigator> {\n try {\n const allStrategies = await this.getAllNavigationStrategies();\n\n if (allStrategies.length === 0) {\n logger.debug(\n '[static/courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])'\n );\n return createDefaultPipeline(user, this);\n }\n\n // Use PipelineAssembler to build Pipeline from strategy documents\n const assembler = new PipelineAssembler();\n const { pipeline, generatorStrategies, filterStrategies, warnings } =\n await assembler.assemble({\n strategies: allStrategies,\n user,\n course: this,\n });\n\n // Log warnings\n for (const warning of warnings) {\n logger.warn(`[PipelineAssembler] ${warning}`);\n }\n\n if (!pipeline) {\n logger.debug('[static/courseDB] Pipeline assembly failed, using default pipeline');\n return createDefaultPipeline(user, this);\n }\n\n logger.debug(\n `[static/courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`\n );\n return pipeline;\n } catch (e) {\n logger.error(`[static/courseDB] Error creating navigator: ${e}`);\n throw e;\n }\n }\n\n // Study Content Source implementation\n\n private _pendingHints: ReplanHints | null = null;\n\n setEphemeralHints(hints: ReplanHints): void {\n this._pendingHints = hints;\n }\n\n\n private _sessionId: string | null = null;\n\n\n setSessionId(sessionId: string): void {\n\n this._sessionId = sessionId;\n\n }\n\n /** Forward a presentation to the navigator (a new card restarts its intake clock). */\n notePresented(card: { cardId: string; courseId: string; status: string }): void {\n if (card.status !== 'new') return;\n void this.createNavigator(this.userDB)\n .then((navigator) => (navigator as StudyContentSource).notePresented?.(card))\n .catch((e) => logger.warn(`[static/courseDB] Could not note a presentation: ${e}`));\n }\n\n async getWeightedCards(limit: number): Promise<GeneratorResult> {\n try {\n const navigator = await this.createNavigator(this.userDB);\n // Forward any pending hints to the Pipeline\n if (this._pendingHints) {\n navigator.setEphemeralHints(this._pendingHints);\n this._pendingHints = null;\n }\n if (this._sessionId) {\n navigator.setSessionId(this._sessionId);\n }\n return navigator.getWeightedCards(limit);\n } catch (e) {\n logger.error(`[static/courseDB] Error getting weighted cards: ${e}`);\n throw e;\n }\n }\n\n // Attachment helper methods (internal use, not part of interface)\n\n /**\n * Get attachment URL for a document and attachment name\n * Internal helper method for static attachment serving\n */\n getAttachmentUrl(docId: string, attachmentName: string): string {\n return this.unpacker.getAttachmentUrl(docId, attachmentName);\n }\n\n /**\n * Load attachment as blob/buffer\n * Internal helper method for static attachment serving\n */\n async getAttachmentBlob(docId: string, attachmentName: string): Promise<Blob | Buffer | null> {\n return this.unpacker.getAttachmentBlob(docId, attachmentName);\n }\n\n // Admin search methods\n async searchCards(_query: string): Promise<any[]> {\n // In static mode, return empty results for now\n // Could be implemented with local search if needed\n return [];\n }\n\n async find(_request: PouchDB.Find.FindRequest<any>): Promise<PouchDB.Find.FindResponse<any>> {\n // In static mode, return empty results for now\n // Could be implemented with local search if needed\n return {\n docs: [],\n warning: 'Find operations not supported in static mode',\n } as any;\n }\n}\n"],"mappings":";;;;;;;AA6BA,IAAa,iBAAb,MAAyD;CACvD,YACE,UACA,UACA,QACA,UACA;AAJQ,OAAA,WAAA;AACA,OAAA,WAAA;AACA,OAAA,SAAA;AACA,OAAA,WAAA;;CAGV,cAAsB;AACpB,SAAO,KAAK;;CAGd,MAAM,kBAAyC;AAC7C,MAAI,KAAK,SAAS,gBAAgB,KAChC,QAAO,KAAK,SAAS;MAErB,OAAM,IAAI,MAAM,sCAAsC,KAAK,WAAW;;CAI1E,MAAM,mBAAmB,MAAoD;AAC3E,QAAM,IAAI,MAAM,6CAA6C;;CAG/D,MAAM,gBAAqC;AAOzC,SAAO;GACL,WALgB,KAAK,SAAS,OAC7B,QAAQ,UAAU,MAAM,YAAY,QAAQ,KAAK,CACjD,QAAQ,OAAO,UAAU,QAAQ,MAAM,eAAe,EAAE;GAIzD,iBAAiB;GAClB;;CAGH,MAAM,aACJ,IACA,UACY;AACZ,SAAO,KAAK,SAAS,YAAY,GAAG;;CAGtC,MAAM,cACJ,KACA,UACuD;EACvD,MAAM,OAAO,MAAM,QAAQ,IACzB,IAAI,IAAI,OAAO,OAAO;AACpB,OAAI;AAEF,WAAO;KACL;KACA,KAAK;KACL,OAAO,EAAE,KAAK,YAAY;KAC1B,KALU,MAAM,KAAK,SAAS,YAAY,GAAG;KAM9C;WACK;AACN,WAAO;KACL,KAAK;KACL,OAAO;KACR;;IAEH,CACH;AAED,SAAO;GACL,YAAY,IAAI;GAChB,QAAQ;GACR;GACD;;CAGH,MAAM,cACJ,KACA,OAOA;AACA,UAAQ,MAAM,KAAK,SAAS,WAAW,KAAK,SAAS,GAAG,EAAE,KAAK,SA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AClF,WAAO,sBAAsB,MAAM,KAAK;;AAG1C,UAAO,MACL,mDAAmD,oBAAoB,OAAO,oBAAoB,iBAAiB,OAAO,YAC3H;AACD,UAAO;WACA,GAAG;AACV,UAAO,MAAM,+CAA+C,IAAI;AAChE,SAAM;;;CAMV,gBAA4C;CAE5C,kBAAkB,OAA0B;AAC1C,OAAK,gBAAgB;;CAIvB,aAAoC;CAGpC,aAAa,WAAyB;AAEpC,OAAK,aAAa;;;CAKpB,cAAc,MAAkE;AAC9E,MAAI,KAAK,WAAW,MAAO;AACtB,OAAK,gBAAgB,KAAK,OAAO,CACnC,MAAM,cAAe,UAAiC,gBAAgB,KAAK,CAAC,CAC5E,OAAO,MAAM,OAAO,KAAK,oDAAoD,IAAI,CAAC;;CAGvF,MAAM,iBAAiB,OAAyC;AAC9D,MAAI;GACF,MAAM,YAAY,MAAM,KAAK,gBAAgB,KAAK,OAAO;AAEzD,OAAI,KAAK,eAAe;AACtB,cAAU,kBAAkB,KAAK,cAAc;AAC/C,SAAK,gBAAgB;;AAEvB,OAAI,KAAK,WACP,WAAU,aAAa,KAAK,WAAW;AAEzC,UAAO,UAAU,iBAAiB,MAAM;WACjC,GAAG;AACV,UAAO,MAAM,mDAAmD,IAAI;AACpE,SAAM;;;;;;;CAUV,iBAAiB,OAAe,gBAAgC;AAC9D,SAAO,KAAK,SAAS,iBAAiB,OAAO,eAAe;;;;;;CAO9D,MAAM,kBAAkB,OAAe,gBAAuD;AAC5F,SAAO,KAAK,SAAS,kBAAkB,OAAO,eAAe;;CAI/D,MAAM,YAAY,QAAgC;AAGhD,SAAO,EAAE;;CAGX,MAAM,KAAK,UAAkF;AAG3F,SAAO;GACL,MAAM,EAAE;GACR,SAAS;GACV"}
@@ -1310,6 +1310,9 @@ var init_navigators = __esm({
1310
1310
  */
1311
1311
  setEphemeralHints(_hints) {
1312
1312
  }
1313
+ /** See StudyContentSource.setSessionId. No-op for non-Pipeline navigators. */
1314
+ setSessionId(_sessionId) {
1315
+ }
1313
1316
  };
1314
1317
  }
1315
1318
  });
@@ -2021,6 +2024,7 @@ var init_Pipeline = __esm({
2021
2024
  * getWeightedCards() call, then cleared.
2022
2025
  */
2023
2026
  _ephemeralHints = null;
2027
+ _sessionId;
2024
2028
  /**
2025
2029
  * The intake valve's clock (see regulators.ts), loaded from strategy state on
2026
2030
  * first use and kept in memory. Writes are chained so a presentation and a
@@ -2056,6 +2060,10 @@ var init_Pipeline = __esm({
2056
2060
  *
2057
2061
  * Overrides ContentNavigator.setEphemeralHints() no-op.
2058
2062
  */
2063
+ /** See StudyContentSource.setSessionId. Carried into every run's context. */
2064
+ setSessionId(sessionId) {
2065
+ this._sessionId = sessionId;
2066
+ }
2059
2067
  setEphemeralHints(hints) {
2060
2068
  this._ephemeralHints = hints;
2061
2069
  logger.info(`[Pipeline] Ephemeral hints set: ${JSON.stringify(hints)}`);
@@ -2503,7 +2511,8 @@ var init_Pipeline = __esm({
2503
2511
  course: this.course,
2504
2512
  userElo,
2505
2513
  ...userCourseElo ? { userCourseElo } : {},
2506
- orchestration
2514
+ orchestration,
2515
+ ...this._sessionId ? { sessionId: this._sessionId } : {}
2507
2516
  };
2508
2517
  }
2509
2518
  /**
@@ -3197,6 +3206,9 @@ var init_srs = __esm({
3197
3206
  });
3198
3207
 
3199
3208
  // src/core/navigators/filters/eloDistance.ts
3209
+ function isIntroCard(card) {
3210
+ return (card.tags ?? []).some((t) => (0, import_common3.tagRole)(t) === "intro");
3211
+ }
3200
3212
  function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
3201
3213
  const normalizedDistance = distance / halfLife;
3202
3214
  const decay = Math.exp(-(normalizedDistance * normalizedDistance));
@@ -3264,7 +3276,7 @@ async function applyEloDistance(cards, context, config, source) {
3264
3276
  const { course, userElo, userCourseElo } = context;
3265
3277
  const { halfLife, minMultiplier, maxMultiplier } = config;
3266
3278
  const tagAware = (config.tagAware || multiDimElo) && userCourseElo !== void 0;
3267
- const missing = cards.filter((c) => tagAware || c.cardElo === void 0).map((c) => c.cardId);
3279
+ const missing = cards.filter((c) => !isIntroCard(c) && (tagAware || c.cardElo === void 0)).map((c) => c.cardId);
3268
3280
  const fetched = /* @__PURE__ */ new Map();
3269
3281
  if (missing.length > 0) {
3270
3282
  const elos = await course.getCardEloData(missing);
@@ -3273,6 +3285,22 @@ async function applyEloDistance(cards, context, config, source) {
3273
3285
  });
3274
3286
  }
3275
3287
  return cards.map((card) => {
3288
+ if (isIntroCard(card)) {
3289
+ return {
3290
+ ...card,
3291
+ provenance: [
3292
+ ...card.provenance,
3293
+ {
3294
+ strategy: "eloDistance",
3295
+ strategyName: source.name,
3296
+ strategyId: source.strategyId,
3297
+ action: "passed",
3298
+ score: card.score,
3299
+ reason: "intro card: ELO is a placeholder, distance not applied \u2192 1.00x"
3300
+ }
3301
+ ]
3302
+ };
3303
+ }
3276
3304
  const full = fetched.get(card.cardId);
3277
3305
  const cardElo = full?.global?.score ?? card.cardElo ?? DEFAULT_CARD_ELO;
3278
3306
  let distance = Math.abs(cardElo - userElo);
@@ -7035,6 +7063,10 @@ var init_courseDB3 = __esm({
7035
7063
  setEphemeralHints(hints) {
7036
7064
  this._pendingHints = hints;
7037
7065
  }
7066
+ _sessionId = null;
7067
+ setSessionId(sessionId) {
7068
+ this._sessionId = sessionId;
7069
+ }
7038
7070
  /** Forward a presentation to the navigator (a new card restarts its intake clock). */
7039
7071
  notePresented(card) {
7040
7072
  if (card.status !== "new") return;
@@ -7047,6 +7079,9 @@ var init_courseDB3 = __esm({
7047
7079
  navigator2.setEphemeralHints(this._pendingHints);
7048
7080
  this._pendingHints = null;
7049
7081
  }
7082
+ if (this._sessionId) {
7083
+ navigator2.setSessionId(this._sessionId);
7084
+ }
7050
7085
  return navigator2.getWeightedCards(limit);
7051
7086
  } catch (e) {
7052
7087
  logger.error(`[static/courseDB] Error getting weighted cards: ${e}`);