only_ever_generator 6.0.12 → 6.0.14

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.
@@ -1,6 +1,7 @@
1
+ import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
1
2
  import { database, ObjectId, setUp } from "../mongo_helper";
2
3
 
3
- export const buildCardSchema = async () => {
4
+ export const buildCardSchema = async (concepts: string[], facts: string[]) => {
4
5
  setUp();
5
6
  const objectId = new ObjectId("689c5cbd0d9d3bbda64b9584");
6
7
  const schemaObj = await database.collection("_prompts").findOne({
@@ -13,150 +14,164 @@ export const buildCardSchema = async () => {
13
14
  if (!schema) {
14
15
  throw new Error("Schema not found");
15
16
  }
17
+ const conceptsSanitized = sanitizeStringsForSchema(concepts);
18
+ const factsSanitized = sanitizeStringsForSchema(facts);
16
19
  // Deep clone to avoid mutating the original
17
20
  const populatedSchema = JSON.parse(schema);
21
+ populatedSchema.schema.properties.test_cards.items.properties.concepts.items.enum =
22
+ conceptsSanitized;
23
+ populatedSchema.schema.properties.test_cards.items.properties.facts.items.enum =
24
+ factsSanitized;
25
+ console.log(
26
+ "Populated Schema",
27
+ JSON.stringify(populatedSchema.schema.properties.test_cards.items, null, 2)
28
+ );
18
29
  return populatedSchema;
19
30
  };
20
31
 
21
- export const cardSchema = {
22
- type: "object",
23
- properties: {
24
- test_cards: {
25
- type: "array",
26
- items: {
27
- type: "object",
28
- properties: {
29
- type: {
30
- type: "string",
31
- enum: ["mcq", "cloze", "match", "flash"],
32
- },
33
- card_content: {
34
- anyOf: [
35
- // Flash Card
36
- {
37
- type: "object",
38
- properties: {
39
- front: { type: "string", maxLength: 320 },
40
- back: { type: "string", maxLength: 320 },
32
+ export const cardSchema = (concepts: string[], facts: string[]) => {
33
+ return {
34
+ type: "object",
35
+ properties: {
36
+ test_cards: {
37
+ type: "array",
38
+ items: {
39
+ type: "object",
40
+ properties: {
41
+ type: {
42
+ type: "string",
43
+ enum: ["mcq", "cloze", "match", "flash"],
44
+ },
45
+ card_content: {
46
+ anyOf: [
47
+ // Flash Card
48
+ {
49
+ type: "object",
50
+ properties: {
51
+ front: { type: "string", maxLength: 320 },
52
+ back: { type: "string", maxLength: 320 },
53
+ },
54
+ required: ["front", "back"],
55
+ additionalProperties: false,
41
56
  },
42
- required: ["front", "back"],
43
- additionalProperties: false,
44
- },
45
- // Match Card
46
- {
47
- type: "array",
48
- minItems: 1,
49
- maxItems: 9,
50
- items: {
51
- anyOf: [
52
- {
53
- type: "object",
54
- properties: {
55
- left_item: { type: "string", maxLength: 30 },
56
- right_item: { type: "string", maxLength: 30 },
57
+ // Match Card
58
+ {
59
+ type: "array",
60
+ minItems: 1,
61
+ maxItems: 9,
62
+ items: {
63
+ anyOf: [
64
+ {
65
+ type: "object",
66
+ properties: {
67
+ left_item: { type: "string", maxLength: 30 },
68
+ right_item: { type: "string", maxLength: 30 },
69
+ },
70
+ required: ["left_item", "right_item"],
71
+ additionalProperties: false,
57
72
  },
58
- required: ["left_item", "right_item"],
59
- additionalProperties: false,
60
- },
61
- // {
62
- // type: "object",
63
- // properties: {
64
- // explanation: { type: "string", maxLength: 320 },
65
- // },
66
- // required: ["explanation"],
67
- // additionalProperties: false,
68
- // },
69
- ],
70
- },
71
- },
72
- // Cloze Card
73
- {
74
- type: "object",
75
- properties: {
76
- prompt: {
77
- type: "string",
78
- maxLength: 320,
79
- pattern: ".*{{.+?}}.*",
73
+ // {
74
+ // type: "object",
75
+ // properties: {
76
+ // explanation: { type: "string", maxLength: 320 },
77
+ // },
78
+ // required: ["explanation"],
79
+ // additionalProperties: false,
80
+ // },
81
+ ],
80
82
  },
81
- correct_options: {
82
- type: "array",
83
- minItems: 1,
84
- maxItems: 4,
85
- items: { type: "string" },
86
- },
87
- incorrect_options: {
88
- type: "array",
89
- minItems: 1,
90
- maxItems: 7,
91
- items: { type: "string" },
83
+ },
84
+ // Cloze Card
85
+ {
86
+ type: "object",
87
+ properties: {
88
+ prompt: {
89
+ type: "string",
90
+ maxLength: 320,
91
+ pattern: ".*{{.+?}}.*",
92
+ },
93
+ correct_options: {
94
+ type: "array",
95
+ minItems: 1,
96
+ maxItems: 4,
97
+ items: { type: "string" },
98
+ },
99
+ incorrect_options: {
100
+ type: "array",
101
+ minItems: 1,
102
+ maxItems: 7,
103
+ items: { type: "string" },
104
+ },
92
105
  },
106
+ required: ["prompt", "correct_options", "incorrect_options"],
107
+ additionalProperties: false,
93
108
  },
94
- required: ["prompt", "correct_options", "incorrect_options"],
95
- additionalProperties: false,
96
- },
97
- // MCQ Card
98
- {
99
- type: "object",
100
- properties: {
101
- prompt: { type: "string", maxLength: 320 },
102
- choices: {
103
- type: "array",
104
- minItems: 2,
105
- maxItems: 8,
106
- items: {
107
- type: "object",
108
- properties: {
109
- choice: { type: "string", maxLength: 42 },
110
- is_correct: { type: "boolean" },
109
+ // MCQ Card
110
+ {
111
+ type: "object",
112
+ properties: {
113
+ prompt: { type: "string", maxLength: 320 },
114
+ choices: {
115
+ type: "array",
116
+ minItems: 2,
117
+ maxItems: 8,
118
+ items: {
119
+ type: "object",
120
+ properties: {
121
+ choice: { type: "string", maxLength: 42 },
122
+ is_correct: { type: "boolean" },
123
+ },
124
+ required: ["choice", "is_correct"],
125
+ additionalProperties: false,
111
126
  },
112
- required: ["choice", "is_correct"],
113
- additionalProperties: false,
114
127
  },
128
+ // explanation: { type: "string", maxLength: 320 },
115
129
  },
116
- // explanation: { type: "string", maxLength: 320 },
130
+ required: ["prompt", "choices"],
131
+ additionalProperties: false,
117
132
  },
118
- required: ["prompt", "choices"],
119
- additionalProperties: false,
120
- },
121
- ],
122
- },
123
- explanation: {
124
- type: "string",
125
- maxLength: 320,
126
- description:
127
- "Explanation for the card (≤320 characters). " +
128
- "If no useful explanation exists, return an empty string. " +
129
- "Include only if it helps the learner understand the concept(s) or fact(s) being tested. " +
130
- "Do not explain anything unrelated, repeat answers verbatim, or add meta-comments. " +
131
- "Keep it clear and concise; you may draw on personal knowledge where appropriate.",
132
- },
133
- concepts: {
134
- type: "array",
135
- items: { type: "string" },
136
- },
137
- facts: {
138
- type: "array",
139
- items: { type: "string" },
140
- },
141
- bloom_alignment: {
142
- type: "string",
143
- maxLength: 240,
144
- description:
145
- "Explain why this card fits the bloom level you were asked to create (max. 240 chars)",
133
+ ],
134
+ },
135
+ explanation: {
136
+ type: "string",
137
+ maxLength: 320,
138
+ description:
139
+ "Explanation for the card (≤320 characters). " +
140
+ "If no useful explanation exists, return an empty string. " +
141
+ "Include only if it helps the learner understand the concept(s) or fact(s) being tested. " +
142
+ "Do not explain anything unrelated, repeat answers verbatim, or add meta-comments. " +
143
+ "Keep it clear and concise; you may draw on personal knowledge where appropriate.",
144
+ },
145
+ concepts: {
146
+ type: "array",
147
+ minItems: 1,
148
+ items: { type: "string", enum: concepts },
149
+ },
150
+ facts: {
151
+ type: "array",
152
+ minItems: 1,
153
+ items: { type: "string", enum: facts },
154
+ },
155
+ bloom_alignment: {
156
+ type: "string",
157
+ maxLength: 240,
158
+ description:
159
+ "Explain why this card fits the bloom level you were asked to create (max. 240 chars)",
160
+ },
146
161
  },
162
+ required: [
163
+ "type",
164
+ "card_content",
165
+ "concepts",
166
+ "facts",
167
+ "bloom_alignment",
168
+ "explanation",
169
+ ],
170
+ additionalProperties: false,
147
171
  },
148
- required: [
149
- "type",
150
- "card_content",
151
- "concepts",
152
- "facts",
153
- "bloom_alignment",
154
- "explanation",
155
- ],
156
- additionalProperties: false,
157
172
  },
158
173
  },
159
- },
160
- required: ["test_cards"],
161
- additionalProperties: false,
174
+ required: ["test_cards"],
175
+ additionalProperties: false,
176
+ };
162
177
  };