Skip to content

NathanTarbert/incident-copilot

Repository files navigation

incident-copilot

image

AI-powered incident-response dashboard built with CopilotKit + OpenAI. Triage cybersecurity incidents conversationally, fill report forms via human-in-the-loop chat, drill into per-incident analysis and cross-incident timelines, and view charts over a decade of global cybersecurity threats (2015–2024).

Stack

  • Frontend: React + TypeScript + Vite, CopilotKit (@copilotkit/react-core, @copilotkit/react-ui), Recharts
  • Backend: Node + Express + @copilotkit/runtime with the OpenAI adapter
  • LLM: OpenAI via OpenAIAdapter
  • Data: Global Cybersecurity Threats (2015–2024) (see README_DATASET.md)
  • Tests: Vitest + Testing Library

Run it

Prerequisites

  • Node.js 20.19+ or 22.12+
  • pnpm β€” install
  • An OpenAI API key

Setup

git clone https://github.com/NathanTarbert/incident-copilot.git
cd incident-copilot
pnpm install
cp .env.example .env       # then paste your OPENAI_API_KEY

Start both servers

pnpm dev:all

Or run them separately

pnpm dev:server      # one terminal β€” Express + runtime
pnpm dev             # another β€” Vite

Tests

pnpm test            # one-shot
pnpm test:watch      # watch mode

What's in the app

  • Incidents list & detail β€” severities P0–P4, statuses Open / Investigating / Mitigated / Resolved, with sorting and filtering.
  • AI sidebar β€” CopilotSidebar chat that can read app state and trigger frontend tools.
  • Conversational incident reporting β€” the AI fills a structured ChatIncidentForm in-chat, the user reviews and submits (classic HITL pattern).
  • Tool calls visualized β€” runbook execution cards, analysis panels, and cross-incident timelines render inline from tool results.
  • Charts β€” Recharts-powered incident charts over the cybersecurity-threats dataset.

How CopilotKit is wired

The frontend wraps the app in <CopilotKit runtimeUrl="http://localhost:4000/copilotkit"> and a <CopilotSidebar>. Three integration points carry the work:

  • useCopilotReadable β€” shares the live incidents list and selection state with the agent.
  • useFrontendTool β€” registers ~9 tools the agent can call (report/resolve/clear incidents, fill the chat form, navigate to a detail view, run a runbook, etc.).
  • useRenderToolCall β€” renders custom React UI for specific tool calls (runbook cards, analysis panels) directly inside the chat thread.

The backend (server.js) mounts copilotRuntimeNodeHttpEndpoint on /copilotkit with the OpenAIAdapter so each request reaches OpenAI with the latest app context attached.

Project layout

incident-copilot/
β”œβ”€β”€ server.js                       # Express + CopilotKit runtime + OpenAI adapter
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ App.tsx                     # CopilotKit provider, sidebar, frontend tools
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ IncidentsList.tsx       # Sort + filter incidents
β”‚   β”‚   β”œβ”€β”€ IncidentDetail.tsx      # Per-incident detail view
β”‚   β”‚   β”œβ”€β”€ ChatIncidentForm.tsx    # HITL form rendered inside the sidebar
β”‚   β”‚   β”œβ”€β”€ CrossIncidentTimeline.tsx
β”‚   β”‚   β”œβ”€β”€ AnalysisPanel.tsx
β”‚   β”‚   β”œβ”€β”€ RunbookExecutionCard.tsx
β”‚   β”‚   └── charts/IncidentCharts.tsx
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ incidentDatabase.ts     # In-memory store
β”‚   β”‚   └── mockApi.ts              # Async wrapper
β”‚   β”œβ”€β”€ data/                       # Cybersecurity threats dataset
β”‚   └── types/incident.ts
β”œβ”€β”€ README_DATASET.md               # How the dataset is wired in
└── package.json

Configuration

Variable Description Required
OPENAI_API_KEY Used by the runtime's OpenAI adapter. Yes

The backend port (4000) and the frontend's runtimeUrl are matched in server.js and src/App.tsx β€” change both if you need a different port.

Deploy

Deploys as a single Node service. In production server.js binds to process.env.PORT, serves the Vite build from dist/, and mounts the runtime at /copilotkit on the same origin β€” no CORS, no second service.

  • Build: pnpm install --frozen-lockfile && pnpm build
  • Start: pnpm start
  • Env: NODE_ENV=production, OPENAI_API_KEY, VITE_COPILOTKIT_RUNTIME_URL=/copilotkit

Run the production bundle locally to sanity-check:

pnpm build
OPENAI_API_KEY=sk-... pnpm start    # http://localhost:4000

Troubleshooting

  • Agent 'default' not found β€” make sure pnpm dev:server is running and the runtimeUrl in App.tsx matches.
  • OPENAI_API_KEY is not set β€” populate .env and restart the server.
  • Port 4000 already in use β€” lsof -ti:4000 | xargs kill -9.

Learn more

About

πŸ” AI-powered incident-response dashboard built with CopilotKit + Custom Agent β€” natural-language triage, human-in-the-loop actions, and live charts over a decade of global cybersecurity threats.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors