feat: design system overhaul — sidebar, AI chats, settings, brainstorm, color cleanup
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 12s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 12s
- Sidebar: dynamic brand-accent colors, brainstorm section restyled - AI chat general: popup panel with expand/collapse, hides when contextual AI open - AI chat contextual: tabs reordered (Actions first), X close button, height fix - Settings: all tabs restyled, 6 new color presets (sage, terracotta, iron, etc.) - Global color cleanup: emerald/orange hardcoded → brand-accent dynamic - Brainstorm page: orange → brand-accent throughout - PageEntry animation component added to key pages - Floating AI button: bg-brand-accent instead of hardcoded black - i18n: all 15 locales updated with new AI/billing keys - Billing: freemium quota tracking, BYOK, stripe subscription scaffolding - Admin: integrated into new design - AGENTS.md + CLAUDE.md project rules added
This commit is contained in:
@@ -2,10 +2,15 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { auth } from '@/auth'
|
||||
import { z } from 'zod'
|
||||
import { getTagsProvider } from '@/lib/ai/factory'
|
||||
import { runLaneWithBillingUser, willUseByokForLane } from '@/lib/ai/provider-for-user'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
import { embeddingService } from '@/lib/ai/services/embedding.service'
|
||||
import {
|
||||
checkSessionEntitlementOrThrow,
|
||||
QuotaExceededError,
|
||||
} from '@/lib/entitlements'
|
||||
import {
|
||||
billingOwnerFromSession,
|
||||
verifyParticipant,
|
||||
resolveAiContextUserId,
|
||||
sanitizeNotesForGuest,
|
||||
@@ -182,7 +187,23 @@ export async function POST(
|
||||
return NextResponse.json({ error: 'Session not found' }, { status: 404 })
|
||||
}
|
||||
|
||||
const parentIdea = brainstormSession.ideas.find(i => i.id === ideaId)
|
||||
const { billingOwnerId, isGuestActor } = billingOwnerFromSession(
|
||||
brainstormSession.userId,
|
||||
session.user.id,
|
||||
)
|
||||
// Story 3.5: per-provider BYOK bypass
|
||||
const earlyConfig = await getSystemConfig()
|
||||
const { usedByok: willUseByok } = await willUseByokForLane('tags', earlyConfig, billingOwnerId)
|
||||
if (!willUseByok) {
|
||||
await checkSessionEntitlementOrThrow(
|
||||
billingOwnerId,
|
||||
session.user.id,
|
||||
isGuestActor,
|
||||
'brainstorm_expand',
|
||||
)
|
||||
}
|
||||
|
||||
const parentIdea = (brainstormSession.ideas || []).find(i => i.id === ideaId)
|
||||
if (!parentIdea) {
|
||||
return NextResponse.json({ error: 'Idea not found' }, { status: 404 })
|
||||
}
|
||||
@@ -205,7 +226,6 @@ export async function POST(
|
||||
}
|
||||
|
||||
const config = await getSystemConfig()
|
||||
const provider = getTagsProvider(config)
|
||||
|
||||
const prompt = buildExpandPromptV2(
|
||||
parentIdea.title,
|
||||
@@ -216,7 +236,12 @@ export async function POST(
|
||||
locale
|
||||
)
|
||||
|
||||
const llmResponse = await provider.generateText(prompt)
|
||||
const { result: llmResponse } = await runLaneWithBillingUser(
|
||||
'tags',
|
||||
config,
|
||||
billingOwnerId,
|
||||
(provider) => provider.generateText(prompt),
|
||||
)
|
||||
|
||||
let newIdeas: any[]
|
||||
try {
|
||||
@@ -311,6 +336,9 @@ export async function POST(
|
||||
|
||||
return NextResponse.json({ success: true, data: updatedSession })
|
||||
} catch (error: any) {
|
||||
if (error instanceof QuotaExceededError) {
|
||||
return NextResponse.json(error.toJSON(), { status: 402 })
|
||||
}
|
||||
if (error instanceof z.ZodError) {
|
||||
return NextResponse.json({ error: error.issues }, { status: 400 })
|
||||
}
|
||||
|
||||
@@ -2,10 +2,20 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { auth } from '@/auth'
|
||||
import { z } from 'zod'
|
||||
import { verifyParticipant, logActivity, resolveAiContextUserId, captureSnapshot } from '@/lib/brainstorm-collab'
|
||||
import {
|
||||
billingOwnerFromSession,
|
||||
verifyParticipant,
|
||||
logActivity,
|
||||
resolveAiContextUserId,
|
||||
captureSnapshot,
|
||||
} from '@/lib/brainstorm-collab'
|
||||
import { embeddingService } from '@/lib/ai/services/embedding.service'
|
||||
import { getTagsProvider } from '@/lib/ai/factory'
|
||||
import { runLaneWithBillingUser, willUseByokForLane } from '@/lib/ai/provider-for-user'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
import {
|
||||
reserveUsageOrThrow,
|
||||
QuotaExceededError,
|
||||
} from '@/lib/entitlements'
|
||||
import { emitToSession } from '@/lib/socket-emit'
|
||||
|
||||
const manualSchema = z.object({
|
||||
@@ -43,6 +53,11 @@ export async function POST(
|
||||
return NextResponse.json({ error: 'Session not found' }, { status: 404 })
|
||||
}
|
||||
|
||||
const { billingOwnerId, isGuestActor } = billingOwnerFromSession(
|
||||
brainstormSession.userId,
|
||||
session.user.id,
|
||||
)
|
||||
|
||||
let wave = 1
|
||||
let parentIdea: any = null
|
||||
if (parentIdeaId) {
|
||||
@@ -78,8 +93,25 @@ export async function POST(
|
||||
},
|
||||
})
|
||||
|
||||
// [UPDATE - SÉCURITÉ] Recherche vectorielle guest-safe
|
||||
// Story 3.5: per-provider BYOK bypass for enrich
|
||||
let enrichBlocked = false
|
||||
try {
|
||||
const config = await getSystemConfig()
|
||||
const { usedByok: willUseByok } = await willUseByokForLane('tags', config, billingOwnerId)
|
||||
if (!willUseByok) {
|
||||
await reserveUsageOrThrow(billingOwnerId, 'brainstorm_enrich')
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
enrichBlocked = true
|
||||
} else {
|
||||
console.error('[manual-idea] reserveUsage error:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// [UPDATE - SÉCURITÉ] Recherche vectorielle guest-safe (skipped when host quota exhausted)
|
||||
let relatedNoteIds: string[] = []
|
||||
if (!enrichBlocked) {
|
||||
try {
|
||||
const { isGuest, publicNoteIds, aiUserId } = await resolveAiContextUserId(sessionId, session.user.id)
|
||||
|
||||
@@ -117,7 +149,10 @@ export async function POST(
|
||||
}
|
||||
relatedNoteIds = results.map((r: any) => r.id)
|
||||
}
|
||||
} catch {}
|
||||
} catch (vectorErr) {
|
||||
console.error('[manual-idea] vector context search failed:', vectorErr)
|
||||
}
|
||||
}
|
||||
|
||||
if (relatedNoteIds.length > 0) {
|
||||
const notes = await prisma.note.findMany({
|
||||
@@ -155,6 +190,16 @@ export async function POST(
|
||||
const requestingUserId = session.user!.id
|
||||
|
||||
const enrichAsync = async () => {
|
||||
if (enrichBlocked) {
|
||||
await emitToSession(sessionId, 'idea:ai_failed', {
|
||||
ideaId: idea.id,
|
||||
reason: 'quota_exceeded',
|
||||
isGuestActor,
|
||||
billingOwnerId,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// Notifier le room que l'IA traite ce nœud (bordure pulsante violet)
|
||||
await emitToSession(sessionId, 'idea:ai_processing', {
|
||||
@@ -163,7 +208,6 @@ export async function POST(
|
||||
})
|
||||
|
||||
const config = await getSystemConfig()
|
||||
const provider = getTagsProvider(config)
|
||||
const lang = locale === 'fr' ? 'French' : locale === 'es' ? 'Spanish' : locale === 'de' ? 'German' : locale === 'it' ? 'Italian' : locale === 'pt' ? 'Portuguese' : locale === 'ja' ? 'Japanese' : locale === 'ko' ? 'Korean' : locale === 'zh' ? 'Chinese' : locale === 'ar' ? 'Arabic' : "the user's language"
|
||||
|
||||
const enrichPrompt = `You are an idea enrichment assistant. Given a user's raw brainstorm idea and context, produce a JSON object with:
|
||||
@@ -181,7 +225,12 @@ User's raw description: "${description || 'none provided'}"
|
||||
|
||||
Respond ONLY with the JSON object, no markdown.`
|
||||
|
||||
const raw = await provider.generateText(enrichPrompt)
|
||||
const { result: raw } = await runLaneWithBillingUser(
|
||||
'tags',
|
||||
config,
|
||||
billingOwnerId,
|
||||
(provider) => provider.generateText(enrichPrompt),
|
||||
)
|
||||
const cleaned = raw.replace(/```json\n?/g, '').replace(/```\n?/g, '').trim()
|
||||
const enriched = JSON.parse(cleaned)
|
||||
|
||||
@@ -195,7 +244,6 @@ Respond ONLY with the JSON object, no markdown.`
|
||||
data: { title: enrichedTitle, description: enrichedDescription, connectionToSeed, noveltyScore },
|
||||
})
|
||||
|
||||
// [UPDATE - TEMPS RÉEL] Notifier la complétion avec les données enrichies
|
||||
await emitToSession(sessionId, 'idea:ai_completed', {
|
||||
ideaId: idea.id,
|
||||
title: enrichedTitle,
|
||||
|
||||
@@ -2,9 +2,14 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { auth } from '@/auth'
|
||||
import { z } from 'zod'
|
||||
import { getTagsProvider } from '@/lib/ai/factory'
|
||||
import { runLaneWithBillingUser, willUseByokForLane } from '@/lib/ai/provider-for-user'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
import { embeddingService } from '@/lib/ai/services/embedding.service'
|
||||
import {
|
||||
checkEntitlementOrThrow,
|
||||
QuotaExceededError,
|
||||
incrementUsageAsync,
|
||||
} from '@/lib/entitlements'
|
||||
import { logActivity, captureSnapshot } from '@/lib/brainstorm-collab'
|
||||
|
||||
const waveSchema = z.object({
|
||||
@@ -64,11 +69,7 @@ async function autoContextSearch(
|
||||
snippet: (n.content || '').slice(0, 300),
|
||||
}))
|
||||
|
||||
try {
|
||||
const config = await getSystemConfig()
|
||||
const provider = getTagsProvider(config)
|
||||
|
||||
const classifyPrompt = `Given the seed idea: "${seedIdea}"
|
||||
const classifyPrompt = `Given the seed idea: "${seedIdea}"
|
||||
|
||||
Classify each note as SUPPORT (confirms/reinforces the seed), TENSION (contradicts/questions the seed), or EXTENSION (extends the seed into an adjacent domain).
|
||||
|
||||
@@ -78,7 +79,14 @@ ${notesForLLM.map(n => `[${n.id}] "${n.title}": ${n.snippet}`).join('\n')}
|
||||
Respond ONLY with a valid JSON array of objects:
|
||||
{ "noteId": string, "category": "SUPPORT" | "TENSION" | "EXTENSION" }`
|
||||
|
||||
const raw = await provider.generateText(classifyPrompt)
|
||||
try {
|
||||
const config = await getSystemConfig()
|
||||
const { result: raw } = await runLaneWithBillingUser(
|
||||
'tags',
|
||||
config,
|
||||
userId,
|
||||
(provider) => provider.generateText(classifyPrompt),
|
||||
)
|
||||
const cleaned = raw.replace(/```json\n?/g, '').replace(/```\n?/g, '').trim()
|
||||
const classifications: { noteId: string; category: 'SUPPORT' | 'TENSION' | 'EXTENSION' }[] = JSON.parse(cleaned)
|
||||
|
||||
@@ -199,13 +207,23 @@ export async function POST(request: NextRequest) {
|
||||
const body = await request.json()
|
||||
const { seedIdea, sourceNoteId, contextNoteIds, locale } = waveSchema.parse(body)
|
||||
|
||||
// Story 3.5: per-provider BYOK bypass
|
||||
const config = await getSystemConfig()
|
||||
const { usedByok: willUseByok } = await willUseByokForLane('tags', config, userId)
|
||||
if (!willUseByok) {
|
||||
await checkEntitlementOrThrow(userId, 'brainstorm_create')
|
||||
}
|
||||
|
||||
const classifiedNotes = await autoContextSearch(userId, seedIdea, contextNoteIds)
|
||||
|
||||
const config = await getSystemConfig()
|
||||
const provider = getTagsProvider(config)
|
||||
|
||||
const prompt = buildPromptV2(seedIdea, classifiedNotes, locale)
|
||||
const llmResponse = await provider.generateText(prompt)
|
||||
const { result: llmResponse, usedByok } = await runLaneWithBillingUser(
|
||||
'tags',
|
||||
config,
|
||||
userId,
|
||||
(provider) => provider.generateText(prompt),
|
||||
)
|
||||
if (!usedByok) incrementUsageAsync(userId, 'brainstorm_create')
|
||||
|
||||
let ideas: any[]
|
||||
try {
|
||||
@@ -312,6 +330,9 @@ export async function POST(request: NextRequest) {
|
||||
},
|
||||
}, { status: 201 })
|
||||
} catch (error: any) {
|
||||
if (error instanceof QuotaExceededError) {
|
||||
return NextResponse.json(error.toJSON(), { status: 402 })
|
||||
}
|
||||
if (error instanceof z.ZodError) {
|
||||
return NextResponse.json({ error: error.issues }, { status: 400 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user