Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# AGENTS.md

## Commands
```bash
bun dev # Dev server (Turbopack)
bun build # Production build
bun lint # ESLint
bun db:push # Push schema to database
bun db:studio # Drizzle Studio
```
No test framework configured.

## Code Style
- **Imports**: Use `@/*` path alias (e.g., `@/lib/utils`, `@/components/ui/button`)
- **Components**: `"use client"` directive for client components; use `cn()` from `@/lib/utils` for className merging
- **Types**: Strict TypeScript; infer DB types via `$inferSelect`/`$inferInsert`; use Zod for runtime validation
- **Naming**: camelCase for functions/variables, PascalCase for components/types, SCREAMING_SNAKE for constants
- **Error handling**: try/catch with `Response.json({ error }, { status })` in API routes
- **No comments** unless explicitly requested
- **Formatting**: 2-space indent, double quotes for JSX strings, template literals for interpolation
- **AI SDK**: Use `@ai-sdk/gateway` with model format `provider/model-name` (e.g., `openai/gpt-4o`)
- **UI**: shadcn/ui components from `@/components/ui/*`; Lucide icons
83 changes: 73 additions & 10 deletions app/api/gallery/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { eq } from "drizzle-orm";
import { asc, eq } from "drizzle-orm";
import { type NextRequest, NextResponse } from "next/server";
import { db } from "@/db";
import { drawings, gameSessions, guesses } from "@/db/schema";
import {
drawings,
gameSessions,
guesses,
playerScores,
roundResults,
} from "@/db/schema";

export async function GET(
_request: NextRequest,
Expand All @@ -19,11 +25,72 @@ export async function GET(
return NextResponse.json({ error: "Session not found" }, { status: 404 });
}

const [sessionDrawings, sessionGuesses] = await Promise.all([
const [sessionRounds, sessionDrawings, sessionGuesses] = await Promise.all([
db
.select()
.from(roundResults)
.where(eq(roundResults.sessionId, id))
.orderBy(asc(roundResults.roundNumber)),
db.select().from(drawings).where(eq(drawings.sessionId, id)),
db.select().from(guesses).where(eq(guesses.sessionId, id)),
]);

let playerName: string | null = null;
if (session.clerkUserId) {
const [player] = await db
.select()
.from(playerScores)
.where(eq(playerScores.clerkUserId, session.clerkUserId))
.limit(1);
playerName = player?.username || null;
} else if (session.anonId) {
const [player] = await db
.select()
.from(playerScores)
.where(eq(playerScores.anonId, session.anonId))
.limit(1);
playerName = player?.username || null;
}

const rounds = sessionRounds.map((round) => {
const roundGuesses = sessionGuesses.filter((g) => g.roundId === round.id);

const llmDrawing = sessionDrawings.find(
(d) => round.drawerType === "llm" && d.modelId === round.drawerId,
);

return {
id: round.id,
roundNumber: round.roundNumber,
prompt: round.prompt,
drawerType: round.drawerType,
drawerId: round.drawerId,
svg: llmDrawing?.svg || round.svg,
chunks: llmDrawing?.chunks ? JSON.parse(llmDrawing.chunks) : null,
guesses: roundGuesses.map((g) => ({
id: g.id,
modelId: g.modelId,
guess: g.guess,
isCorrect: g.isCorrect,
isHuman: g.isHuman,
semanticScore: g.semanticScore,
finalScore: g.finalScore,
generationTimeMs: g.generationTimeMs,
})),
};
});

const legacyGuesses =
sessionRounds.length === 0
? sessionGuesses.map((g) => ({
id: g.id,
modelId: g.modelId,
guess: g.guess,
isCorrect: g.isCorrect,
generationTimeMs: g.generationTimeMs,
}))
: [];

return NextResponse.json({
id: session.id,
mode: session.mode,
Expand All @@ -32,6 +99,8 @@ export async function GET(
totalTokens: session.totalTokens || 0,
totalTimeMs: session.totalTimeMs,
createdAt: session.createdAt.toISOString(),
playerName,
rounds,
drawings: sessionDrawings.map((d) => ({
id: d.id,
modelId: d.modelId,
Expand All @@ -41,13 +110,7 @@ export async function GET(
isWinner: d.isWinner,
chunks: d.chunks ? JSON.parse(d.chunks) : null,
})),
guesses: sessionGuesses.map((g) => ({
id: g.id,
modelId: g.modelId,
guess: g.guess,
isCorrect: g.isCorrect,
generationTimeMs: g.generationTimeMs,
})),
guesses: legacyGuesses,
});
} catch (error) {
console.error("Error fetching session:", error);
Expand Down
Loading