Registry / ai-ml / sql-chatbot-agent

sql-chatbot-agent

JSON →
library1.2.1jsnpmunverified

AI-powered chatbot for any PostgreSQL app. Version 1.2.1 auto-discovers database schema, indexes code for context, executes SQL, and streams answers via a chat widget. Runs as a standalone CLI (npx or global install) or as Express middleware. Supports multiple LLM providers (OpenAI, Groq, Ollama) with zero-config setup. Differentiators: framework-aware code indexing for route detection, enum discovery, and business logic context; row-level filters and alias overrides for domain-specific queries. Requires Node >=18.

npm install sql-chatbot-agent
INSTALL
IMPORT
SIG · SQL-CHATBOT-AGENT
S
sql-chatbot-agent
ai-mljavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import sqlChatbotAgent from 'sql-chatbot-agent'
const sqlChatbotAgent = require('sql-chatbot-agent')
ESM-only since v1; CommonJS require will fail.
middleware
import { middleware } from 'sql-chatbot-agent'
import sqlChatbotAgent from 'sql-chatbot-agent'; app.use(sqlChatbotAgent)
The default export is the CLI setup function, not Express middleware. Use the named 'middleware' export for Express integration.
ChatbotAgent
import { ChatbotAgent } from 'sql-chatbot-agent'
const { ChatbotAgent } = require('sql-chatbot-agent')
The class for programmatic use; also available as named export. For TypeScript, types are bundled (no @types package needed).

Express middleware integration with PostgreSQL, OpenAI, and code indexing enabled.

import { middleware } from 'sql-chatbot-agent'; import express from 'express'; const app = express(); app.use('/chatbot', middleware({ databaseUrl: process.env.DATABASE_URL ?? 'postgresql://localhost/mydb', llmApiKey: process.env.OPENAI_API_KEY ?? '', provider: 'openai', codePaths: ['./src'], port: 3456, secret: process.env.CHATBOT_SECRET ?? '', })); app.listen(3000, () => { console.log('App running on http://localhost:3000'); });
Debug
Known issues
breakingIn v1.0, the default export was Express middleware; in v1.1+, the default export is the CLI entry point and middleware is a named export.
fix
Change `import sqlChatbotAgent from 'sql-chatbot-agent'` to `import { middleware } from 'sql-chatbot-agent'`.
affects: >=1.1
deprecatedThe `groqApiKey` config field is deprecated in favor of `llmApiKey` (still accepted but mapped internally).
fix
Use `llmApiKey` instead of `groqApiKey` in configuration.
affects: >=1.2
gotchaThe `databaseUrl` must point to an existing PostgreSQL database; the tool will modify the schema by adding an `ai_chatbot_log` table for conversation history.
fix
Ensure your database user has CREATE TABLE privileges, or set `readOnly: true` to disable logging.
affects: >=1.0
gotchaWhen using `npx`, the tool may prompt to install if not cached. Use `npx sql-chatbot-agent@1.2.1` to pin version.
fix
Specify version: `npx sql-chatbot-agent@1.2.1 --db postgresql://...`
affects: >=1.0
gotchaThe tool indexes `node_modules`, `.git`, `dist`, and `build` by default? No — but it does scan all directories under `codePaths`. Ensure large irrelevant folders are excluded via `.gitignore` patterns or use more specific paths.
fix
Set `codePaths` to narrow directories (e.g., `['./src']` instead of `['.']`).
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module 'sql-chatbot-agent'
Missing global or local installation; npx not used.
fix
Run `npm install -g sql-chatbot-agent` or `npx sql-chatbot-agent` instead of bare command.
TypeError: sqlChatbotAgent is not a function
Using default import for middleware after v1.1.
fix
Use `import { middleware } from 'sql-chatbot-agent'`.
Error: connect ECONNREFUSED ::1:5432
PostgreSQL not running or wrong connection string (IPv6 localhost vs IPv4).
fix
Use `postgresql://127.0.0.1:5432/mydb` or ensure PostgreSQL is listening.
Error: 401 Invalid API key
Missing or wrong LLM API key.
fix
Set `OPENAI_API_KEY` environment variable or pass `--key` flag with correct key.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources