Invect

Express

Mount Invect into an Express application.

Installation

npm install @invect/core @invect/express

Setup

The Express adapter provides a router factory. Mount it at any path in your app:

server.ts
import express from 'express';
import cors from 'cors';
import { createInvectRouter } from '@invect/express';

const app = express();
app.use(cors());

// Mount alongside your existing routes
app.use('/api/admin', adminRouter);
app.use('/api/invect', createInvectRouter({
  baseDatabaseConfig: {
    type: 'sqlite',
    connectionString: 'file:./dev.db',
    id: 'main',
  },
}));

app.listen(3000);

Configuration

createInvectRouter accepts the full InvectConfig object:

createInvectRouter({
  // Required
  baseDatabaseConfig: {
    type: 'sqlite',            // 'sqlite' | 'postgresql' | 'mysql'
    connectionString: string,  // Database connection URL
    id: string,                // Identifier for this database
  },

  // Optional
  plugins?: InvectPlugin[],   // Plugins to load
  auth?: { ... },              // Authentication/authorization config
  chat?: { ... },              // AI chat assistant config
  logging?: { ... },           // Log level configuration
  defaultCredentials?: [...],  // Credentials to seed on startup
});

How It Works

The router creates an Invect core instance internally. On creation:

  1. The core initializes and connects to the database
  2. All built-in actions are registered
  3. Batch polling starts automatically

Every route is a thin wrapper around a core method:

// Internally, the router does:
router.post('/flows/:flowId/run', async (req, res) => {
  const result = await core.startFlowRun(req.params.flowId, req.body.inputs);
  res.json(result);
});

API Endpoints

The router exposes 30+ endpoints. Key ones:

MethodPathDescription
GET/flowsList all flows
POST/flowsCreate a flow
POST/flows/:id/runExecute a flow
GET/flow-runs/:idGet execution details
GET/agent/toolsList available agent tools
GET/credentialsList credentials
POST/credentials/oauth2/startStart OAuth2 flow

Embedding in Admin Panels

A common pattern is mounting Invect alongside your existing admin panel:

admin-app.ts
import { createInvectRouter } from '@invect/express';

// Your existing admin API
app.use('/admin/api', adminRouter);

// Invect workflows — same server, same database
app.use('/admin/workflows', createInvectRouter({
  baseDatabaseConfig: {
    type: 'sqlite',
    connectionString: process.env.DATABASE_URL || 'file:./dev.db',
    id: 'main',
  },
}));

Then in your admin frontend, drop in the React component:

admin-workflows.tsx
import { Invect } from '@invect/frontend';
import '@invect/frontend/styles';

export function WorkflowsPage() {
  return <Invect apiBaseUrl="/admin/workflows" />;
}