last commit before trying out opencode on repo

This commit is contained in:
2026-01-11 10:17:30 -05:00
parent 843b264c61
commit 91682bd887
85 changed files with 1589 additions and 1196 deletions

View File

@@ -1,8 +1,9 @@
import { v } from "convex/values";
import { query, mutation, action } from "./_generated/server";
import { getAuthUserId } from "@convex-dev/auth/server";
import { api } from "./_generated/api";
import OpenAI from "openai";
import { getAuthUserId } from '@convex-dev/auth/server';
import { v } from 'convex/values';
import OpenAI from 'openai';
import { api } from './_generated/api';
import { action, mutation, query } from './_generated/server';
const openai = new OpenAI({
baseURL: process.env.OPENAI_BASE_URL,
@@ -13,8 +14,8 @@ export const getAllQuestions = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Not authenticated");
return await ctx.db.query("questions").collect();
if (!userId) throw new Error('Not authenticated');
return await ctx.db.query('questions').collect();
},
});
@@ -22,10 +23,10 @@ export const getQuestionsByTopic = query({
args: { topic: v.string() },
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Not authenticated");
if (!userId) throw new Error('Not authenticated');
return await ctx.db
.query("questions")
.withIndex("by_topic", (q) => q.eq("topic", args.topic))
.query('questions')
.withIndex('by_topic', (q) => q.eq('topic', args.topic))
.collect();
},
});
@@ -41,8 +42,8 @@ export const addQuestion = mutation({
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Not authenticated");
return await ctx.db.insert("questions", {
if (!userId) throw new Error('Not authenticated');
return await ctx.db.insert('questions', {
question: args.question,
options: args.options,
correctAnswer: args.correctAnswer,
@@ -60,7 +61,7 @@ export const generateQuestions = action({
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Not authenticated");
if (!userId) throw new Error('Not authenticated');
const prompt = `Generate ${args.count} multiple choice questions for the CompTIA Network+ exam on the topic: "${args.topic}".
Return ONLY a valid JSON array with this exact structure:
@@ -83,19 +84,19 @@ Rules:
- Return ONLY the JSON array, no other text`;
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: prompt }],
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: prompt }],
temperature: 0.8,
});
const content = response.choices[0].message.content;
if (!content) throw new Error("No response from AI");
if (!content) throw new Error('No response from AI');
let questions;
try {
questions = JSON.parse(content);
} catch (e) {
throw new Error("Failed to parse AI response as JSON");
throw new Error('Failed to parse AI response as JSON');
}
const questionIds = [];