@thanh01.pmt/interactive-quiz-kit 1.0.31 → 1.0.33

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.
package/dist/ai.cjs CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  var genai = require('@google/genai');
4
4
  var zod = require('zod');
5
- var genkit = require('genkit');
6
- var googleai = require('@genkit-ai/googleai');
7
5
 
8
6
  // src/ai/flows/question-gen/generate-true-false-question.ts
9
7
 
@@ -2825,10 +2823,7 @@ var AIQuizReviewOutputSchema = zod.z.object({
2825
2823
  // src/ai/flows/generate-quiz-review.ts
2826
2824
  async function generateQuizReview(clientInput, apiKey) {
2827
2825
  try {
2828
- const ai = genkit.genkit({
2829
- plugins: [googleai.googleAI({ apiKey })],
2830
- model: googleai.gemini20Flash
2831
- });
2826
+ const genAI = new genai.GoogleGenAI({ apiKey });
2832
2827
  const resultsString = JSON.stringify(clientInput.questionResults, null, 2);
2833
2828
  const promptText = `
2834
2829
  You are an expert educational tutor. Your task is to analyze a student's quiz results and provide a detailed, helpful review in ${clientInput.language}.
@@ -2865,8 +2860,17 @@ Return a single, valid JSON object with this EXACT format.
2865
2860
  \`\`\`
2866
2861
 
2867
2862
  Return only the valid JSON response.`;
2868
- const response = await ai.generate(promptText);
2869
- const rawText = response.text;
2863
+ const modelName = "gemini-1.5-flash";
2864
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
2865
+ const result = await genAI.models.generateContent({
2866
+ model: modelName,
2867
+ contents
2868
+ });
2869
+ const response = result;
2870
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
2871
+ if (!rawText) {
2872
+ throw new Error("AI returned an empty response.");
2873
+ }
2870
2874
  const jsonText = extractJsonFromMarkdown(rawText);
2871
2875
  const aiGeneratedContent = JSON.parse(jsonText);
2872
2876
  const validatedOutput = AIQuizReviewOutputSchema.parse(aiGeneratedContent);
@@ -2913,10 +2917,7 @@ var PracticeSuggestionOutputSchema = zod.z.object({
2913
2917
  });
2914
2918
  async function generatePracticeSuggestion(clientInput, apiKey) {
2915
2919
  try {
2916
- const ai = genkit.genkit({
2917
- plugins: [googleai.googleAI({ apiKey })],
2918
- model: googleai.gemini20Flash
2919
- });
2920
+ const genAI = new genai.GoogleGenAI({ apiKey });
2920
2921
  const { language, userName, performanceByTopic, recentHistory, allAvailableTopics } = clientInput;
2921
2922
  const promptText = `
2922
2923
  You are a friendly and insightful AI Learning Coach. Your goal is to provide a personalized practice suggestion for a student named ${userName || "there"}.
@@ -2955,8 +2956,17 @@ Return a single, valid JSON object in this exact format. All text must be in ${l
2955
2956
  }
2956
2957
 
2957
2958
  Return only the JSON response.`;
2958
- const response = await ai.generate(promptText);
2959
- const rawText = response.text;
2959
+ const modelName = "gemini-1.5-flash";
2960
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
2961
+ const result = await genAI.models.generateContent({
2962
+ model: modelName,
2963
+ contents
2964
+ });
2965
+ const response = result;
2966
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
2967
+ if (!rawText) {
2968
+ throw new Error("AI returned an empty response.");
2969
+ }
2960
2970
  const jsonText = extractJsonFromMarkdown(rawText);
2961
2971
  const aiGeneratedContent = JSON.parse(jsonText);
2962
2972
  const validatedOutput = PracticeSuggestionOutputSchema.parse(aiGeneratedContent);
@@ -3021,10 +3031,7 @@ var LearningAnalysisOutputSchema = zod.z.object({
3021
3031
  // src/ai/flows/generate-learning-analysis.ts
3022
3032
  async function generateLearningAnalysis(clientInput, apiKey) {
3023
3033
  try {
3024
- const ai = genkit.genkit({
3025
- plugins: [googleai.googleAI({ apiKey })],
3026
- model: googleai.gemini20Flash
3027
- });
3034
+ const genAI = new genai.GoogleGenAI({ apiKey });
3028
3035
  const {
3029
3036
  language,
3030
3037
  userName = "learner",
@@ -3112,8 +3119,17 @@ The 'suggestedDifficulty' field MUST ALWAYS be one of these exact English string
3112
3119
  }
3113
3120
  \`\`\`
3114
3121
  `;
3115
- const response = await ai.generate(promptText);
3116
- const rawText = response.text;
3122
+ const modelName = "gemini-1.5-flash";
3123
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3124
+ const result = await genAI.models.generateContent({
3125
+ model: modelName,
3126
+ contents
3127
+ });
3128
+ const response = result;
3129
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3130
+ if (!rawText) {
3131
+ throw new Error("AI returned an empty response.");
3132
+ }
3117
3133
  const jsonText = extractJsonFromMarkdown(rawText);
3118
3134
  const aiGeneratedContent = JSON.parse(jsonText);
3119
3135
  const validatedOutput = LearningAnalysisOutputSchema.parse(aiGeneratedContent);
@@ -3144,10 +3160,7 @@ var GenerateMotivationalQuoteOutputSchema = zod.z.object({
3144
3160
  // src/ai/flows/generate-motivational-quote.ts
3145
3161
  async function generateMotivationalQuote(clientInput, apiKey) {
3146
3162
  try {
3147
- const ai = genkit.genkit({
3148
- plugins: [googleai.googleAI({ apiKey })],
3149
- model: googleai.gemini20Flash
3150
- });
3163
+ const genAI = new genai.GoogleGenAI({ apiKey });
3151
3164
  const { language, userName, currentStreak, weakestTopic } = clientInput;
3152
3165
  let contextPrompt = "";
3153
3166
  if (userName) {
@@ -3180,8 +3193,17 @@ Return the response as a single, valid JSON object with this EXACT format:
3180
3193
 
3181
3194
  Return only the JSON response.`;
3182
3195
  try {
3183
- const response = await ai.generate(promptText);
3184
- const rawText = response.text;
3196
+ const modelName = "gemini-1.5-flash";
3197
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3198
+ const result = await genAI.models.generateContent({
3199
+ model: modelName,
3200
+ contents
3201
+ });
3202
+ const response = result;
3203
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3204
+ if (!rawText) {
3205
+ throw new Error("AI returned an empty response.");
3206
+ }
3185
3207
  const jsonText = extractJsonFromMarkdown(rawText);
3186
3208
  const aiGeneratedContent = JSON.parse(jsonText);
3187
3209
  const validatedOutput = GenerateMotivationalQuoteOutputSchema.parse(aiGeneratedContent);
@@ -3207,10 +3229,7 @@ var PlanKnowledgeCardsOutputSchema = zod.z.object({
3207
3229
  // src/ai/flows/plan-knowledge-cards.ts
3208
3230
  async function planKnowledgeCards(clientInput, apiKey) {
3209
3231
  try {
3210
- const ai = genkit.genkit({
3211
- plugins: [googleai.googleAI({ apiKey })],
3212
- model: googleai.gemini20Flash
3213
- });
3232
+ const genAI = new genai.GoogleGenAI({ apiKey });
3214
3233
  const { language, learningObjectivesContent, overallSubject } = clientInput;
3215
3234
  const promptText = `
3216
3235
  You are an expert curriculum designer specializing in the subject of "${overallSubject}".
@@ -3230,18 +3249,28 @@ ${learningObjectivesContent}
3230
3249
 
3231
3250
  **JSON OUTPUT FORMAT:**
3232
3251
  Return a single, valid JSON object with this EXACT format:
3252
+ \`\`\`json
3233
3253
  {
3234
3254
  "concepts": [
3235
3255
  "First Concept",
3236
3256
  "Second Concept",
3237
- "Third Concept",
3238
- ...
3257
+ "Third Concept"
3239
3258
  ]
3240
3259
  }
3260
+ \`\`\`
3241
3261
 
3242
3262
  Return only the JSON response.`;
3243
- const response = await ai.generate(promptText);
3244
- const rawText = response.text;
3263
+ const modelName = "gemini-1.5-flash";
3264
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3265
+ const result = await genAI.models.generateContent({
3266
+ model: modelName,
3267
+ contents
3268
+ });
3269
+ const response = result;
3270
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3271
+ if (!rawText) {
3272
+ throw new Error("AI returned an empty response.");
3273
+ }
3245
3274
  const jsonText = extractJsonFromMarkdown(rawText);
3246
3275
  const aiGeneratedContent = JSON.parse(jsonText);
3247
3276
  const validatedOutput = PlanKnowledgeCardsOutputSchema.parse(aiGeneratedContent);
@@ -3268,30 +3297,48 @@ var GenerateSingleKnowledgeCardOutputSchema = zod.z.object({
3268
3297
 
3269
3298
  // src/ai/flows/generate-single-knowledge-card.ts
3270
3299
  async function generateSingleKnowledgeCard(clientInput, apiKey) {
3271
- const ai = genkit.genkit({
3272
- plugins: [googleai.googleAI({ apiKey })],
3273
- model: googleai.gemini20Flash
3274
- });
3275
3300
  try {
3276
- const { language, concept, overallSubject, fullContext } = clientInput;
3301
+ const genAI = new genai.GoogleGenAI({ apiKey });
3302
+ const { language, concept, overallSubject } = clientInput;
3277
3303
  const promptText = `
3278
- You are an expert educator for "${overallSubject}". Create content for a single knowledge card.
3279
- Target Concept: ${concept}
3280
- Instructions:
3281
- 1. Write a concise "definition" (under 40 words).
3282
- 2. Provide a practical "example" (code or real-world scenario) relevant to "${overallSubject}".
3283
- 3. All content must be in ${language}.
3284
- 4. The 'concept' field in your output must exactly match the Target Concept.`;
3285
- const response = await ai.generate({
3286
- prompt: promptText,
3287
- output: {
3288
- schema: GenerateSingleKnowledgeCardOutputSchema
3289
- }
3304
+ You are an expert educator for "${overallSubject}". Your task is to create content for a single knowledge card based on the provided concept.
3305
+
3306
+ **Target Concept:**
3307
+ ${concept}
3308
+
3309
+ **Instructions:**
3310
+ 1. **Definition:** Write a concise definition for the concept (under 40 words).
3311
+ 2. **Example:** Provide a practical example (code or real-world scenario) relevant to "${overallSubject}".
3312
+ 3. **Language:** All content must be in ${language}.
3313
+ 4. **Format:** You MUST return ONLY a single, valid JSON object that strictly follows the provided schema. Do not include any extra text, comments, or markdown formatting.
3314
+
3315
+ **Required JSON Output Format:**
3316
+ Your response must be ONLY the JSON object, matching this exact structure. The 'concept' field must exactly match the Target Concept provided above.
3317
+
3318
+ {
3319
+ "concept": "${concept}",
3320
+ "definition": "A concise explanation of the concept goes here, in ${language}.",
3321
+ "example": "A practical code snippet or real-world example goes here, in ${language}."
3322
+ }
3323
+
3324
+ Now, generate the JSON for the requested knowledge card.`;
3325
+ const modelName = "gemini-1.5-flash";
3326
+ const config = {
3327
+ responseMimeType: "application/json"
3328
+ };
3329
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3330
+ const result = await genAI.models.generateContent({
3331
+ model: modelName,
3332
+ contents,
3333
+ config
3290
3334
  });
3291
- const validatedOutput = response.output;
3292
- if (!validatedOutput) {
3335
+ const response = result;
3336
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3337
+ if (!rawText) {
3293
3338
  throw new Error("AI did not return a valid structured output.");
3294
3339
  }
3340
+ const aiGeneratedContent = JSON.parse(rawText);
3341
+ const validatedOutput = GenerateSingleKnowledgeCardOutputSchema.parse(aiGeneratedContent);
3295
3342
  return validatedOutput;
3296
3343
  } catch (error) {
3297
3344
  console.error(`Error generating knowledge card for concept "${clientInput.concept}":`, error);
@@ -3327,10 +3374,7 @@ var AssessAndMapDocumentOutputSchema = zod.z.object({
3327
3374
  // src/ai/flows/assess-and-map-document.ts
3328
3375
  async function assessAndMapDocument(clientInput, apiKey) {
3329
3376
  try {
3330
- const ai = genkit.genkit({
3331
- plugins: [googleai.googleAI({ apiKey })],
3332
- model: googleai.gemini20Flash
3333
- });
3377
+ const genAI = new genai.GoogleGenAI({ apiKey });
3334
3378
  const { language, documentContent, learningObjectives } = clientInput;
3335
3379
  const relevanceThreshold = 40;
3336
3380
  const promptText = `
@@ -3378,8 +3422,17 @@ Return a single, valid JSON object in this EXACT format. Do not include any othe
3378
3422
 
3379
3423
  If the document is not relevant at all, the "mappedLOs" array should be empty, and the "relevanceScore" should be low.
3380
3424
  `;
3381
- const response = await ai.generate(promptText);
3382
- const rawText = response.text;
3425
+ const modelName = "gemini-1.5-flash";
3426
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3427
+ const result = await genAI.models.generateContent({
3428
+ model: modelName,
3429
+ contents
3430
+ });
3431
+ const response = result;
3432
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3433
+ if (!rawText) {
3434
+ throw new Error("AI returned an empty response.");
3435
+ }
3383
3436
  const jsonText = extractJsonFromMarkdown(rawText);
3384
3437
  const aiGeneratedContent = JSON.parse(jsonText);
3385
3438
  const validatedOutput = AssessAndMapDocumentOutputSchema.parse(aiGeneratedContent);
@@ -3411,10 +3464,7 @@ var GenerateQuizFromTextOutputSchema = zod.z.object({
3411
3464
  var AnyGeneratedQuestionSchema2 = GenerateQuizFromTextOutputSchema.shape.generatedQuestions.element;
3412
3465
  async function generateQuizFromText(clientInput, apiKey) {
3413
3466
  try {
3414
- const ai = genkit.genkit({
3415
- plugins: [googleai.googleAI({ apiKey })],
3416
- model: googleai.gemini20Flash
3417
- });
3467
+ const genAI = new genai.GoogleGenAI({ apiKey });
3418
3468
  const { language, documentContent, numQuestions, questionTypes } = clientInput;
3419
3469
  const allowedTypes = questionTypes || ["multiple_choice", "true_false"];
3420
3470
  const promptText = `
@@ -3468,8 +3518,17 @@ Return the response as a single JSON object with a key "generatedQuestions" cont
3468
3518
  \`\`\`
3469
3519
 
3470
3520
  Now, generate the JSON response.`;
3471
- const response = await ai.generate(promptText);
3472
- const rawText = response.text;
3521
+ const modelName = "gemini-1.5-flash";
3522
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3523
+ const result = await genAI.models.generateContent({
3524
+ model: modelName,
3525
+ contents
3526
+ });
3527
+ const response = result;
3528
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3529
+ if (!rawText) {
3530
+ throw new Error("AI returned an empty response.");
3531
+ }
3473
3532
  const jsonText = extractJsonFromMarkdown(rawText);
3474
3533
  const aiGeneratedContent = JSON.parse(jsonText);
3475
3534
  if (!aiGeneratedContent.generatedQuestions || !Array.isArray(aiGeneratedContent.generatedQuestions)) {
package/dist/ai.mjs CHANGED
@@ -1,7 +1,5 @@
1
1
  import { GoogleGenAI } from '@google/genai';
2
2
  import { z } from 'zod';
3
- import { genkit } from 'genkit';
4
- import { gemini20Flash, googleAI } from '@genkit-ai/googleai';
5
3
 
6
4
  // src/ai/flows/question-gen/generate-true-false-question.ts
7
5
 
@@ -2823,10 +2821,7 @@ var AIQuizReviewOutputSchema = z.object({
2823
2821
  // src/ai/flows/generate-quiz-review.ts
2824
2822
  async function generateQuizReview(clientInput, apiKey) {
2825
2823
  try {
2826
- const ai = genkit({
2827
- plugins: [googleAI({ apiKey })],
2828
- model: gemini20Flash
2829
- });
2824
+ const genAI = new GoogleGenAI({ apiKey });
2830
2825
  const resultsString = JSON.stringify(clientInput.questionResults, null, 2);
2831
2826
  const promptText = `
2832
2827
  You are an expert educational tutor. Your task is to analyze a student's quiz results and provide a detailed, helpful review in ${clientInput.language}.
@@ -2863,8 +2858,17 @@ Return a single, valid JSON object with this EXACT format.
2863
2858
  \`\`\`
2864
2859
 
2865
2860
  Return only the valid JSON response.`;
2866
- const response = await ai.generate(promptText);
2867
- const rawText = response.text;
2861
+ const modelName = "gemini-1.5-flash";
2862
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
2863
+ const result = await genAI.models.generateContent({
2864
+ model: modelName,
2865
+ contents
2866
+ });
2867
+ const response = result;
2868
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
2869
+ if (!rawText) {
2870
+ throw new Error("AI returned an empty response.");
2871
+ }
2868
2872
  const jsonText = extractJsonFromMarkdown(rawText);
2869
2873
  const aiGeneratedContent = JSON.parse(jsonText);
2870
2874
  const validatedOutput = AIQuizReviewOutputSchema.parse(aiGeneratedContent);
@@ -2911,10 +2915,7 @@ var PracticeSuggestionOutputSchema = z.object({
2911
2915
  });
2912
2916
  async function generatePracticeSuggestion(clientInput, apiKey) {
2913
2917
  try {
2914
- const ai = genkit({
2915
- plugins: [googleAI({ apiKey })],
2916
- model: gemini20Flash
2917
- });
2918
+ const genAI = new GoogleGenAI({ apiKey });
2918
2919
  const { language, userName, performanceByTopic, recentHistory, allAvailableTopics } = clientInput;
2919
2920
  const promptText = `
2920
2921
  You are a friendly and insightful AI Learning Coach. Your goal is to provide a personalized practice suggestion for a student named ${userName || "there"}.
@@ -2953,8 +2954,17 @@ Return a single, valid JSON object in this exact format. All text must be in ${l
2953
2954
  }
2954
2955
 
2955
2956
  Return only the JSON response.`;
2956
- const response = await ai.generate(promptText);
2957
- const rawText = response.text;
2957
+ const modelName = "gemini-1.5-flash";
2958
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
2959
+ const result = await genAI.models.generateContent({
2960
+ model: modelName,
2961
+ contents
2962
+ });
2963
+ const response = result;
2964
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
2965
+ if (!rawText) {
2966
+ throw new Error("AI returned an empty response.");
2967
+ }
2958
2968
  const jsonText = extractJsonFromMarkdown(rawText);
2959
2969
  const aiGeneratedContent = JSON.parse(jsonText);
2960
2970
  const validatedOutput = PracticeSuggestionOutputSchema.parse(aiGeneratedContent);
@@ -3019,10 +3029,7 @@ var LearningAnalysisOutputSchema = z.object({
3019
3029
  // src/ai/flows/generate-learning-analysis.ts
3020
3030
  async function generateLearningAnalysis(clientInput, apiKey) {
3021
3031
  try {
3022
- const ai = genkit({
3023
- plugins: [googleAI({ apiKey })],
3024
- model: gemini20Flash
3025
- });
3032
+ const genAI = new GoogleGenAI({ apiKey });
3026
3033
  const {
3027
3034
  language,
3028
3035
  userName = "learner",
@@ -3110,8 +3117,17 @@ The 'suggestedDifficulty' field MUST ALWAYS be one of these exact English string
3110
3117
  }
3111
3118
  \`\`\`
3112
3119
  `;
3113
- const response = await ai.generate(promptText);
3114
- const rawText = response.text;
3120
+ const modelName = "gemini-1.5-flash";
3121
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3122
+ const result = await genAI.models.generateContent({
3123
+ model: modelName,
3124
+ contents
3125
+ });
3126
+ const response = result;
3127
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3128
+ if (!rawText) {
3129
+ throw new Error("AI returned an empty response.");
3130
+ }
3115
3131
  const jsonText = extractJsonFromMarkdown(rawText);
3116
3132
  const aiGeneratedContent = JSON.parse(jsonText);
3117
3133
  const validatedOutput = LearningAnalysisOutputSchema.parse(aiGeneratedContent);
@@ -3142,10 +3158,7 @@ var GenerateMotivationalQuoteOutputSchema = z.object({
3142
3158
  // src/ai/flows/generate-motivational-quote.ts
3143
3159
  async function generateMotivationalQuote(clientInput, apiKey) {
3144
3160
  try {
3145
- const ai = genkit({
3146
- plugins: [googleAI({ apiKey })],
3147
- model: gemini20Flash
3148
- });
3161
+ const genAI = new GoogleGenAI({ apiKey });
3149
3162
  const { language, userName, currentStreak, weakestTopic } = clientInput;
3150
3163
  let contextPrompt = "";
3151
3164
  if (userName) {
@@ -3178,8 +3191,17 @@ Return the response as a single, valid JSON object with this EXACT format:
3178
3191
 
3179
3192
  Return only the JSON response.`;
3180
3193
  try {
3181
- const response = await ai.generate(promptText);
3182
- const rawText = response.text;
3194
+ const modelName = "gemini-1.5-flash";
3195
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3196
+ const result = await genAI.models.generateContent({
3197
+ model: modelName,
3198
+ contents
3199
+ });
3200
+ const response = result;
3201
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3202
+ if (!rawText) {
3203
+ throw new Error("AI returned an empty response.");
3204
+ }
3183
3205
  const jsonText = extractJsonFromMarkdown(rawText);
3184
3206
  const aiGeneratedContent = JSON.parse(jsonText);
3185
3207
  const validatedOutput = GenerateMotivationalQuoteOutputSchema.parse(aiGeneratedContent);
@@ -3205,10 +3227,7 @@ var PlanKnowledgeCardsOutputSchema = z.object({
3205
3227
  // src/ai/flows/plan-knowledge-cards.ts
3206
3228
  async function planKnowledgeCards(clientInput, apiKey) {
3207
3229
  try {
3208
- const ai = genkit({
3209
- plugins: [googleAI({ apiKey })],
3210
- model: gemini20Flash
3211
- });
3230
+ const genAI = new GoogleGenAI({ apiKey });
3212
3231
  const { language, learningObjectivesContent, overallSubject } = clientInput;
3213
3232
  const promptText = `
3214
3233
  You are an expert curriculum designer specializing in the subject of "${overallSubject}".
@@ -3228,18 +3247,28 @@ ${learningObjectivesContent}
3228
3247
 
3229
3248
  **JSON OUTPUT FORMAT:**
3230
3249
  Return a single, valid JSON object with this EXACT format:
3250
+ \`\`\`json
3231
3251
  {
3232
3252
  "concepts": [
3233
3253
  "First Concept",
3234
3254
  "Second Concept",
3235
- "Third Concept",
3236
- ...
3255
+ "Third Concept"
3237
3256
  ]
3238
3257
  }
3258
+ \`\`\`
3239
3259
 
3240
3260
  Return only the JSON response.`;
3241
- const response = await ai.generate(promptText);
3242
- const rawText = response.text;
3261
+ const modelName = "gemini-1.5-flash";
3262
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3263
+ const result = await genAI.models.generateContent({
3264
+ model: modelName,
3265
+ contents
3266
+ });
3267
+ const response = result;
3268
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3269
+ if (!rawText) {
3270
+ throw new Error("AI returned an empty response.");
3271
+ }
3243
3272
  const jsonText = extractJsonFromMarkdown(rawText);
3244
3273
  const aiGeneratedContent = JSON.parse(jsonText);
3245
3274
  const validatedOutput = PlanKnowledgeCardsOutputSchema.parse(aiGeneratedContent);
@@ -3266,30 +3295,48 @@ var GenerateSingleKnowledgeCardOutputSchema = z.object({
3266
3295
 
3267
3296
  // src/ai/flows/generate-single-knowledge-card.ts
3268
3297
  async function generateSingleKnowledgeCard(clientInput, apiKey) {
3269
- const ai = genkit({
3270
- plugins: [googleAI({ apiKey })],
3271
- model: gemini20Flash
3272
- });
3273
3298
  try {
3274
- const { language, concept, overallSubject, fullContext } = clientInput;
3299
+ const genAI = new GoogleGenAI({ apiKey });
3300
+ const { language, concept, overallSubject } = clientInput;
3275
3301
  const promptText = `
3276
- You are an expert educator for "${overallSubject}". Create content for a single knowledge card.
3277
- Target Concept: ${concept}
3278
- Instructions:
3279
- 1. Write a concise "definition" (under 40 words).
3280
- 2. Provide a practical "example" (code or real-world scenario) relevant to "${overallSubject}".
3281
- 3. All content must be in ${language}.
3282
- 4. The 'concept' field in your output must exactly match the Target Concept.`;
3283
- const response = await ai.generate({
3284
- prompt: promptText,
3285
- output: {
3286
- schema: GenerateSingleKnowledgeCardOutputSchema
3287
- }
3302
+ You are an expert educator for "${overallSubject}". Your task is to create content for a single knowledge card based on the provided concept.
3303
+
3304
+ **Target Concept:**
3305
+ ${concept}
3306
+
3307
+ **Instructions:**
3308
+ 1. **Definition:** Write a concise definition for the concept (under 40 words).
3309
+ 2. **Example:** Provide a practical example (code or real-world scenario) relevant to "${overallSubject}".
3310
+ 3. **Language:** All content must be in ${language}.
3311
+ 4. **Format:** You MUST return ONLY a single, valid JSON object that strictly follows the provided schema. Do not include any extra text, comments, or markdown formatting.
3312
+
3313
+ **Required JSON Output Format:**
3314
+ Your response must be ONLY the JSON object, matching this exact structure. The 'concept' field must exactly match the Target Concept provided above.
3315
+
3316
+ {
3317
+ "concept": "${concept}",
3318
+ "definition": "A concise explanation of the concept goes here, in ${language}.",
3319
+ "example": "A practical code snippet or real-world example goes here, in ${language}."
3320
+ }
3321
+
3322
+ Now, generate the JSON for the requested knowledge card.`;
3323
+ const modelName = "gemini-1.5-flash";
3324
+ const config = {
3325
+ responseMimeType: "application/json"
3326
+ };
3327
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3328
+ const result = await genAI.models.generateContent({
3329
+ model: modelName,
3330
+ contents,
3331
+ config
3288
3332
  });
3289
- const validatedOutput = response.output;
3290
- if (!validatedOutput) {
3333
+ const response = result;
3334
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3335
+ if (!rawText) {
3291
3336
  throw new Error("AI did not return a valid structured output.");
3292
3337
  }
3338
+ const aiGeneratedContent = JSON.parse(rawText);
3339
+ const validatedOutput = GenerateSingleKnowledgeCardOutputSchema.parse(aiGeneratedContent);
3293
3340
  return validatedOutput;
3294
3341
  } catch (error) {
3295
3342
  console.error(`Error generating knowledge card for concept "${clientInput.concept}":`, error);
@@ -3325,10 +3372,7 @@ var AssessAndMapDocumentOutputSchema = z.object({
3325
3372
  // src/ai/flows/assess-and-map-document.ts
3326
3373
  async function assessAndMapDocument(clientInput, apiKey) {
3327
3374
  try {
3328
- const ai = genkit({
3329
- plugins: [googleAI({ apiKey })],
3330
- model: gemini20Flash
3331
- });
3375
+ const genAI = new GoogleGenAI({ apiKey });
3332
3376
  const { language, documentContent, learningObjectives } = clientInput;
3333
3377
  const relevanceThreshold = 40;
3334
3378
  const promptText = `
@@ -3376,8 +3420,17 @@ Return a single, valid JSON object in this EXACT format. Do not include any othe
3376
3420
 
3377
3421
  If the document is not relevant at all, the "mappedLOs" array should be empty, and the "relevanceScore" should be low.
3378
3422
  `;
3379
- const response = await ai.generate(promptText);
3380
- const rawText = response.text;
3423
+ const modelName = "gemini-1.5-flash";
3424
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3425
+ const result = await genAI.models.generateContent({
3426
+ model: modelName,
3427
+ contents
3428
+ });
3429
+ const response = result;
3430
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3431
+ if (!rawText) {
3432
+ throw new Error("AI returned an empty response.");
3433
+ }
3381
3434
  const jsonText = extractJsonFromMarkdown(rawText);
3382
3435
  const aiGeneratedContent = JSON.parse(jsonText);
3383
3436
  const validatedOutput = AssessAndMapDocumentOutputSchema.parse(aiGeneratedContent);
@@ -3409,10 +3462,7 @@ var GenerateQuizFromTextOutputSchema = z.object({
3409
3462
  var AnyGeneratedQuestionSchema2 = GenerateQuizFromTextOutputSchema.shape.generatedQuestions.element;
3410
3463
  async function generateQuizFromText(clientInput, apiKey) {
3411
3464
  try {
3412
- const ai = genkit({
3413
- plugins: [googleAI({ apiKey })],
3414
- model: gemini20Flash
3415
- });
3465
+ const genAI = new GoogleGenAI({ apiKey });
3416
3466
  const { language, documentContent, numQuestions, questionTypes } = clientInput;
3417
3467
  const allowedTypes = questionTypes || ["multiple_choice", "true_false"];
3418
3468
  const promptText = `
@@ -3466,8 +3516,17 @@ Return the response as a single JSON object with a key "generatedQuestions" cont
3466
3516
  \`\`\`
3467
3517
 
3468
3518
  Now, generate the JSON response.`;
3469
- const response = await ai.generate(promptText);
3470
- const rawText = response.text;
3519
+ const modelName = "gemini-1.5-flash";
3520
+ const contents = [{ role: "user", parts: [{ text: promptText }] }];
3521
+ const result = await genAI.models.generateContent({
3522
+ model: modelName,
3523
+ contents
3524
+ });
3525
+ const response = result;
3526
+ const rawText = response.candidates?.[0]?.content?.parts?.[0]?.text || "";
3527
+ if (!rawText) {
3528
+ throw new Error("AI returned an empty response.");
3529
+ }
3471
3530
  const jsonText = extractJsonFromMarkdown(rawText);
3472
3531
  const aiGeneratedContent = JSON.parse(jsonText);
3473
3532
  if (!aiGeneratedContent.generatedQuestions || !Array.isArray(aiGeneratedContent.generatedQuestions)) {