{"_id":"@aivue/chatbot-server","name":"@aivue/chatbot-server","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@aivue/chatbot-server","version":"0.1.0","description":"Backend utilities and database integration for @aivue/chatbot","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"npm run clean && tsup","dev":"tsup --watch","lint":"eslint \"src/**/*.ts\"","clean":"rm -rf dist","test":"vitest run","test:watch":"vitest","prepublishOnly":"npm run build"},"keywords":["chatbot","server","database","orm","api","backend","express","sequelize","mongoose","drizzle"],"author":{"name":"reachbrt"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/reachbrt/vueai.git","directory":"packages/chatbot-server"},"homepage":"https://github.com/reachbrt/vueai#readme","bugs":{"url":"https://github.com/reachbrt/vueai/issues"},"publishConfig":{"access":"public"},"dependencies":{"cors":"^2.8.5","dotenv":"^16.3.1","express":"^4.18.2","winston":"^3.10.0"},"peerDependencies":{"@prisma/client":"^5.1.1","drizzle-orm":">=0.28.5","mongoose":"^7.4.3","prisma":"^5.1.1","sequelize":"^6.32.1"},"peerDependenciesMeta":{"sequelize":{"optional":true},"mongoose":{"optional":true},"drizzle-orm":{"optional":true},"prisma":{"optional":true},"@prisma/client":{"optional":true}},"devDependencies":{"@types/cors":"^2.8.18","@types/express":"^4.17.17","@types/node":"^20.5.0","@types/sequelize":"^4.28.20","eslint":"^8.47.0","tsup":"^7.2.0","typescript":"^5.1.6","vitest":"^0.34.2"},"_id":"@aivue/chatbot-server@0.1.0","gitHead":"60c17c4c4094be2923484286db4c84a89a6a21d6","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-NrcOkl///EJ4pQYY860ngxb9WU34p4InSU48DfP4W3QbJgE+xMw4K2hTYLaWzQgnoTz5R1rPTyKSxv221hFSvw==","shasum":"e218134b5ec2542e8c1f73e3bd976a6f95c68171","tarball":"https://registry.npmjs.org/@aivue/chatbot-server/-/chatbot-server-0.1.0.tgz","fileCount":9,"unpackedSize":297940,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCmRRbWA3gLei5cEMh79AYvSW7aVszjPmny4QKuew7ynAIgYvvpBWU18wI740JabZISY1qT+SnqdSZ82zoiQTAnUV4="}]},"_npmUser":{"name":"aivue","email":"Reachbrt@gmail.com"},"directories":{},"maintainers":[{"name":"aivue","email":"Reachbrt@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/chatbot-server_0.1.0_1747366549726_0.4422787008334066"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-16T03:35:49.644Z","0.1.0":"2025-05-16T03:35:49.924Z","modified":"2025-05-16T03:35:50.169Z"},"maintainers":[{"name":"aivue","email":"Reachbrt@gmail.com"}],"description":"Backend utilities and database integration for @aivue/chatbot","homepage":"https://github.com/reachbrt/vueai#readme","keywords":["chatbot","server","database","orm","api","backend","express","sequelize","mongoose","drizzle"],"repository":{"type":"git","url":"git+https://github.com/reachbrt/vueai.git","directory":"packages/chatbot-server"},"author":{"name":"reachbrt"},"bugs":{"url":"https://github.com/reachbrt/vueai/issues"},"license":"MIT","readme":"# @aivue/chatbot-server\n\nBackend utilities and database integration for @aivue/chatbot.\n\n> **Note:** This is an optional package that provides server-side functionality for storing and managing chatbot conversations. It is not required for using the @aivue/chatbot package, but it provides additional features for applications that need to store conversation history.\n\n## Features\n\n- Database storage for chatbot conversations\n- Support for multiple databases and ORMs:\n  - PostgreSQL, MySQL, SQLite, MongoDB\n  - Sequelize, Mongoose, Drizzle, Prisma\n- Admin API for conversation management\n- Easy integration with Express.js applications\n- Flexible configuration options\n\n## Installation\n\n```bash\nnpm install @aivue/chatbot-server\n```\n\nYou'll also need to install the ORM of your choice:\n\n```bash\n# For Sequelize\nnpm install sequelize\n\n# For Mongoose\nnpm install mongoose\n\n# For Drizzle\nnpm install drizzle-orm\n\n# For Prisma\nnpm install prisma @prisma/client\n```\n\n## Quick Start\n\n```javascript\nconst express = require('express');\nconst { createChatbotServer } = require('@aivue/chatbot-server');\n\nasync function start() {\n  // Create Express app\n  const app = express();\n\n  // Create chatbot server\n  const chatbotServer = await createChatbotServer({\n    database: {\n      type: 'postgres',\n      orm: 'sequelize',\n      connectionString: process.env.DATABASE_URL\n    },\n    auth: {\n      adminApiKey: process.env.ADMIN_API_KEY\n    }\n  });\n\n  // Mount chatbot server middleware\n  app.use('/api', chatbotServer.middleware);\n\n  // Start server\n  app.listen(3000, () => {\n    console.log('Server running on port 3000');\n  });\n}\n\nstart().catch(console.error);\n```\n\n## Configuration\n\nThe `createChatbotServer` function accepts a configuration object with the following options:\n\n```typescript\ninterface ChatbotServerConfig {\n  // Required: Database configuration\n  database: {\n    type: 'postgres' | 'mysql' | 'sqlite' | 'mongodb';\n    orm: 'sequelize' | 'mongoose' | 'drizzle' | 'prisma';\n    connectionString?: string;\n    host?: string;\n    port?: number;\n    username?: string;\n    password?: string;\n    database?: string;\n    file?: string; // For SQLite\n    options?: Record<string, any>;\n  };\n\n  // Optional: Authentication configuration\n  auth?: {\n    adminApiKey?: string;\n    apiKeyHeader?: string;\n    jwtSecret?: string;\n    jwtExpiresIn?: string;\n  };\n\n  // Optional: API configuration\n  api?: {\n    basePath?: string;\n    adminPath?: string;\n    enableCors?: boolean;\n    corsOptions?: Record<string, any>;\n  };\n\n  // Optional: Storage configuration\n  storage?: {\n    messageLimit?: number;\n    enableArchiving?: boolean;\n    archiveAfterDays?: number;\n    deleteAfterDays?: number;\n  };\n\n  // Optional: Logging configuration\n  logging?: {\n    level?: 'error' | 'warn' | 'info' | 'debug';\n    format?: 'json' | 'text';\n    file?: string;\n  };\n}\n```\n\n## API Endpoints\n\n### Chat Endpoints\n\n- `POST /api/chat` - Process a chat message and store it in the database\n- `GET /api/user/:userId/conversations` - Get conversations for a specific user\n\n### Admin Endpoints\n\nAll admin endpoints require authentication using the `X-Admin-API-Key` header.\n\n- `GET /api/admin/conversations` - List all conversations with pagination and filtering\n- `GET /api/admin/conversations/:id` - Get a specific conversation with all messages\n- `POST /api/admin/conversations/:id/status` - Update a conversation's status\n- `GET /api/admin/stats` - Get conversation statistics\n\n## Integration with @aivue/chatbot\n\nThis package is designed to work seamlessly with the @aivue/chatbot package. The @aivue/chatbot package has been enhanced to support server-side persistence through the `serverPersistence` option.\n\n### Client-Side Configuration\n\nTo use this server with the @aivue/chatbot package, configure the chatbot to use the server for persistence:\n\n```javascript\nimport { useChatEngine } from '@aivue/chatbot';\n\nconst {\n  messages,\n  isLoading,\n  error,\n  conversationId,\n  sendMessage\n} = useChatEngine({\n  provider: 'openai',\n  apiKey: process.env.OPENAI_API_KEY,\n\n  // Enable server persistence\n  serverPersistence: true,\n  userId: 123, // Optional user ID\n\n  useProxy: true,\n  proxyUrl: '/api/chat'\n});\n```\n\n### How It Works\n\n1. The @aivue/chatbot package sends chat messages to the server endpoint\n2. The server stores the messages in the database\n3. The server returns the AI response along with a conversation ID\n4. The client stores the conversation ID for future messages\n5. Subsequent messages are associated with the same conversation\n\nThis allows you to:\n- Store conversation history for later retrieval\n- Build admin interfaces to view and manage conversations\n- Analyze conversation data\n- Implement user-specific conversation history\n\n## Advanced Usage\n\n### Standalone Server\n\nYou can run the chatbot server as a standalone Express application:\n\n```javascript\nconst { createChatbotServer } = require('@aivue/chatbot-server');\n\nasync function start() {\n  const server = await createChatbotServer({\n    database: {\n      type: 'postgres',\n      orm: 'sequelize',\n      connectionString: process.env.DATABASE_URL\n    }\n  });\n\n  // Start the server on port 3000\n  await server.start(3000);\n}\n\nstart().catch(console.error);\n```\n\n### Using Individual Components\n\nYou can also use the individual components of the package:\n\n```javascript\nconst express = require('express');\nconst {\n  createDatabaseConnection,\n  getModels,\n  createChatRoutes,\n  createAdminRoutes,\n  adminAuthMiddleware\n} = require('@aivue/chatbot-server');\n\nasync function start() {\n  // Create database connection\n  const db = await createDatabaseConnection({\n    type: 'postgres',\n    orm: 'sequelize',\n    connectionString: process.env.DATABASE_URL\n  });\n\n  // Get models\n  const models = await getModels('sequelize', db);\n\n  // Create Express app\n  const app = express();\n  app.use(express.json());\n\n  // Create chat routes\n  const chatRoutes = createChatRoutes({\n    db,\n    orm: 'sequelize',\n    models\n  });\n\n  // Create admin routes\n  const adminRoutes = createAdminRoutes({\n    db,\n    orm: 'sequelize',\n    models,\n    auth: {\n      adminApiKey: process.env.ADMIN_API_KEY\n    }\n  });\n\n  // Mount routes\n  app.use('/api', chatRoutes);\n  app.use('/api/admin', adminRoutes);\n\n  // Start server\n  app.listen(3000, () => {\n    console.log('Server running on port 3000');\n  });\n}\n\nstart().catch(console.error);\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-78cdcc9254206be5b7e52496ad0dcd0f"}