Repository navigation
(feature): adds ai production assistance - #24
Merged
Bishopukpai merged 1 commit intoSep 1, 2026
Merged
Conversation
✅ Deploy Preview for scenepilot ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Implemented
getProjectContext(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:
Expected result: 0 errors, 0 warnings.
📋 Pre-Merge Checklist
🔐 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.