|
| 1 | +# Codelab: Enhancing Obsidian Logistics with AI |
| 2 | + |
| 3 | +Welcome to the Obsidian Logistics AI Codelab! In this guide, you'll learn how to take a modern Angular logistics dashboard and supercharge it with AI capabilities using the Gemini CLI, specialized skills, and the Model Context Protocol (MCP). |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +Before you begin, ensure you have the following installed: |
| 10 | +- [Node.js](https://nodejs.org/) (v20 or higher) |
| 11 | +- [Angular CLI](https://angular.dev/tools/cli) (`npm install -g @angular/cli`) |
| 12 | +- [Gemini CLI](https://github.com/google-gemini/gemini-cli) |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Step 0: Environment Setup |
| 17 | + |
| 18 | +First, let's prepare your workspace and tools. |
| 19 | + |
| 20 | +### 1. Project Initialization |
| 21 | +Navigate to the project root and install the dependencies: |
| 22 | +```bash |
| 23 | +cd logistics-manager-app |
| 24 | +npm install |
| 25 | +``` |
| 26 | + |
| 27 | +### 2. Install Gemini CLI Skills |
| 28 | +Skills provide the agent with specialized knowledge. We'll add the `angular-developer` and `gemini-sdk` skills to help with code generation and API integration. |
| 29 | +```bash |
| 30 | +# Add Angular expertise |
| 31 | +gemini skills install https://github.com/google-gemini/angular-developer --scope project |
| 32 | + |
| 33 | +# Add Gemini SDK expertise |
| 34 | +gemini skills install https://github.com/google-gemini/gemini-sdk --scope project |
| 35 | +``` |
| 36 | + |
| 37 | +### 3. Configure MCP Servers |
| 38 | +The Model Context Protocol (MCP) allows your AI tools to interact with your running application and the browser. |
| 39 | + |
| 40 | +#### Angular MCP Server |
| 41 | +This server allows the AI to understand your Angular project structure, components, and services. |
| 42 | +```bash |
| 43 | +gemini mcp add angular npx -y @modelcontextprotocol/server-angular --scope project |
| 44 | +``` |
| 45 | + |
| 46 | +#### Chrome DevTools MCP Server |
| 47 | +This allows the AI to inspect the running application in your browser for debugging and UI analysis. |
| 48 | +```bash |
| 49 | +gemini mcp add chromedevtools npx -y @modelcontextprotocol/server-chromedevtools --scope project |
| 50 | +``` |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## Enhancement 1: AI-Powered Fleet Chat |
| 55 | + |
| 56 | +The `app-chat` component is currently a UI shell. Your task is to implement the backend and frontend logic to allow users to ask natural language questions about the fleet. |
| 57 | + |
| 58 | +### The Goal |
| 59 | +A user should be able to type: *"Which units are currently in critical status and have less than 10% battery?"* and receive a concise list. |
| 60 | + |
| 61 | +### Implementation Steps |
| 62 | +1. **Service Integration**: Update `FleetService` to include a `queryFleet(prompt: string)` method. |
| 63 | +2. **AI Logic**: Use the `gemini-sdk` skill to generate a prompt that sends the current `units()` state to Gemini and asks it to filter the data based on the user's input. |
| 64 | +3. **UI Binding**: Connect the chat input and message list in `chat.ts` to the `FleetService`. |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +## Enhancement 2: Intelligent Service Prioritization |
| 69 | + |
| 70 | +Currently, users manually select a priority when creating a service ticket. Let's automate this using AI analysis of the issue description. |
| 71 | + |
| 72 | +### The Goal |
| 73 | +When a user describes an issue like *"The vehicle is emitting smoke and the engine has stopped,"* the AI should automatically set the priority to `CRITICAL`. |
| 74 | + |
| 75 | +### Implementation Steps |
| 76 | +1. **Form Hook**: In `service-queue.ts`, add a listener to the `issue` field in the `serviceForm`. |
| 77 | +2. **AI Analysis**: Create a small utility that sends the issue text to Gemini with a system prompt: *"Analyze this logistics vehicle issue and return one of: LOW, MEDIUM, HIGH, CRITICAL."* |
| 78 | +3. **Auto-update**: Use the result to update the `priority` field in the form automatically as the user types or on blur. |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Enhancement 3: Predictive Battery Health Diagnostics |
| 83 | + |
| 84 | +Add a "Run Diagnostic" feature to the vehicle detail view that predicts potential failures before they happen. |
| 85 | + |
| 86 | +### The Goal |
| 87 | +In the `FleetDetailModal`, provide a "Run AI Diagnostic" button. When clicked, it analyzes the unit's `speed`, `battery`, and `status` history to provide a "Health Score" and a "Recommended Action." |
| 88 | + |
| 89 | +### Implementation Steps |
| 90 | +1. **Diagnostic Action**: Add a button to the `FleetDetailModal` template. |
| 91 | +2. **Telemetry Payload**: Gather the `FleetUnit` data and any historical trends (if available in `fleet-db.ts`). |
| 92 | +3. **AI Insight**: Send this telemetry to Gemini to generate a report. |
| 93 | + - Example prompt: *"Analyze this unit: Speed 102km/h, Battery 14% (Declining rapidly), Status: Transit. Predict potential failure points."* |
| 94 | +4. **Result Display**: Show the AI's response in a new "Diagnostics" section within the modal. |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## Running the App |
| 99 | + |
| 100 | +To see your changes in action, start the development server: |
| 101 | +```bash |
| 102 | +npm run start |
| 103 | +``` |
| 104 | +The app will be available at `http://localhost:4200`. |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Summary |
| 109 | +By completing these enhancements, you've transformed a static dashboard into an intelligent command center. You've leveraged: |
| 110 | +- **Angular Signals** for reactive state management. |
| 111 | +- **Gemini CLI Skills** for expert-level coding assistance. |
| 112 | +- **MCP Servers** for deep integration between your AI and your workspace. |
0 commit comments