Skip to content

(feature): adds ai production assistance - #24

Merged
Bishopukpai merged 1 commit into
mainfrom
feature/ai-production-intelligence-assistance-backend
Sep 1, 2026
Merged

Bishopukpai merged 1 commit into
mainfrom
feature/ai-production-intelligence-assistance-backend

Conversation

@Bishopukpai

@Bishopukpai Bishopukpai commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

AI Production Intelligence Backend Integration

🚀 Summary

Implements the server-side architecture for AI Production planning, introducing context aware AI project analysis, automated task generation, risk assessment, and status reporting using the Google Gen AI SDK (@google/genai) with structured JSON output enforcement.

This PR establishes an automated relational context aggregation engine that pulls multi-collection production data from MongoDB (projects, tasks, production plans, and team rosters) and feeds it into Gemini 2.5 Flash. By combining deep context injection with structured Zod/Type schemas, ScenePilot now safely delivers validated, structured AI insights and task recommendations ready for human review.

The implementation establishes a backend engine for:

Relational Context Hydration: Single-query aggregation of project metadata, active tasks, production breakdown objects (scenes, shoot days, locations), and team assignments.

Structured Schema Enforcement: Guaranteed JSON outputs leveraging Gemini's responseSchema to eliminate parsing errors and raw string hallucination.

Contextual Intelligence Workflows: Natural language processing for project risk detection, pre-production task generation, production plan generation, and project health reporting.

📦 Changes Made

🧠 Context Aggregation Engine

lib/ai/context.ts:

ImplementedgetProjectContext(projectId)to query MongoDB across projects, tasks, production_plans, and project_members collections.

Formatted raw MongoDB documents into clean, compact JSON payloads optimized for LLM system prompt context windows.

📐 Schema Definitions & Type Safety

lib/ai/schemas.ts:

Defined Zod validation schemas (AIAssistantResponseSchema, GeneratedTasksSchema) enforcing strict response shapes for intents, project health ratings (Healthy, Moderate Risk, High Risk, Critical), risk items, recommendations, and structured generated task objects.

🌐 AI API Endpoint

app/api/projects/[projectId]/ai/route.ts:

Initialized GoogleGenAI client using @google/genai.

Configured POST route handler to retrieve session credentials via getServerSession(authOptions).

Integrated gemini-3.6-flash with system instructions containing hydrated project context.

Passed responseMimeType: "application/json" and explicit responseSchema parameters to ensure deterministic JSON structure from the Gemini API.

##🧪 How to Test

Terminal & Build Validation

Run the following commands in your terminal:


npx tsc --noEmit
npm run lint

Expected result: 0 errors, 0 warnings.

📋 Pre-Merge Checklist

  • Context aggregator implemented querying MongoDB collections (projects, tasks, production_plans, project_members)
  • @google/genai SDK integrated with GoogleGenAI instance
  • AI API route implemented with NextAuth session authentication
  • gemini-3.6-flash configured with structured responseSchema
  • Zod validation schemas defined for structured AI responses
  • Error handling added for unauthenticated requests and empty AI responses
  • npx tsc --noEmit passes with 0 errors
  • npm run lint passes with 0 errors and 0 warnings
  • Environment variable GEMINI_API_KEY secured and excluded from commit

🔐 Security & Safety Notes

GEMINI_API_KEY is accessed exclusively on the server side within Next.js API route handlers and is never exposed to the client bundle.

Endpoint requests require active session authorization via getServerSession(authOptions).

Input prompts are bound with project context inside system instructions to prevent contextual prompt drift.

🔄 Next Steps

Frontend Assistant Interface

Wire up client-side ScenePilotAI chat interface.

Implement quick-prompt buttons ("What are the biggest risks?", "Create pre-production tasks").

Add human approval interface for committing generatedTasks to MongoDB tasks collection.

@netlify

netlify Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for scenepilot ready!

Name Link
🔨 Latest commit 651a3e3
🔍 Latest deploy log https://app.netlify.com/projects/scenepilot/deploys/6a96f07f160f9b0007874a6f
😎 Deploy Preview https://deploy-preview-24--scenepilot.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Bishopukpai
Bishopukpai merged commit 8d78d0c into main Sep 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant