Skip to content

Commit fadbba6

Browse files
authored
Merge pull request #8 from Z4phxr/feat/LLM_intergation_for_course_creation
feat(ai-agent): implement AI agent functionality
2 parents a2b305a + 2ad16a9 commit fadbba6

14 files changed

Lines changed: 1736 additions & 2 deletions

File tree

LearningPlatform/.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ VERBOSE_LOGGING="false"
102102
# ANTHROPIC_MODEL="claude-haiku-4-5"
103103
# ANTHROPIC_SONNET_MODEL="claude-sonnet-4-5"
104104

105+
# -----------------------------------------------------------------------------
106+
# OpenAI (Admin AI Agent optional provider)
107+
# -----------------------------------------------------------------------------
108+
# OPENAI_API_KEY=""
109+
# OPENAI_MODEL="gpt-4.1"
110+
105111
# -----------------------------------------------------------------------------
106112
# Testing
107113
# -----------------------------------------------------------------------------
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { AIAgentWorkspace } from '@/components/admin/ai-agent-workspace'
2+
3+
export const dynamic = 'force-dynamic'
4+
5+
export default function AdminAIAgentPage() {
6+
return <AIAgentWorkspace />
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NextResponse } from 'next/server'
2+
import { requireAdmin } from '@/lib/auth-helpers'
3+
import { createRun } from '@/lib/ai-agent/progress-store'
4+
import { runAcceptPipeline } from '@/lib/ai-agent/generation'
5+
6+
export async function POST(req: Request) {
7+
try {
8+
const admin = await requireAdmin()
9+
const body = await req.json()
10+
const run = createRun()
11+
12+
void runAcceptPipeline(run.runId, body, {
13+
id: admin.id,
14+
email: admin.email,
15+
})
16+
17+
return NextResponse.json({ runId: run.runId }, { status: 202 })
18+
} catch (error) {
19+
if (error instanceof Error && (error.message === 'Unauthorized' || error.message === 'Forbidden')) {
20+
return NextResponse.json({ error: error.message }, { status: error.message === 'Unauthorized' ? 401 : 403 })
21+
}
22+
console.error('[POST /api/admin/ai-agent/accept]', error)
23+
return NextResponse.json(
24+
{ error: error instanceof Error ? error.message : 'Internal server error' },
25+
{ status: 500 },
26+
)
27+
}
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { NextResponse } from 'next/server'
2+
import { requireAdmin } from '@/lib/auth-helpers'
3+
import { generateDraft } from '@/lib/ai-agent/generation'
4+
5+
export async function POST(req: Request) {
6+
try {
7+
await requireAdmin()
8+
const body = await req.json()
9+
const draft = await generateDraft(body)
10+
return NextResponse.json({ draft })
11+
} catch (error) {
12+
if (error instanceof Error && (error.message === 'Unauthorized' || error.message === 'Forbidden')) {
13+
return NextResponse.json({ error: error.message }, { status: error.message === 'Unauthorized' ? 401 : 403 })
14+
}
15+
console.error('[POST /api/admin/ai-agent/draft]', error)
16+
return NextResponse.json(
17+
{ error: error instanceof Error ? error.message : 'Internal server error' },
18+
{ status: 500 },
19+
)
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { NextResponse } from 'next/server'
2+
import { requireAdmin } from '@/lib/auth-helpers'
3+
import { getRun } from '@/lib/ai-agent/progress-store'
4+
5+
export async function GET(
6+
_req: Request,
7+
ctx: { params: Promise<{ runId: string }> },
8+
) {
9+
try {
10+
await requireAdmin()
11+
const { runId } = await ctx.params
12+
const run = getRun(runId)
13+
if (!run) {
14+
return NextResponse.json({ error: 'Run not found' }, { status: 404 })
15+
}
16+
return NextResponse.json({ run })
17+
} catch (error) {
18+
if (error instanceof Error && (error.message === 'Unauthorized' || error.message === 'Forbidden')) {
19+
return NextResponse.json({ error: error.message }, { status: error.message === 'Unauthorized' ? 401 : 403 })
20+
}
21+
console.error('[GET /api/admin/ai-agent/progress/[runId]]', error)
22+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
23+
}
24+
}

0 commit comments

Comments
 (0)