@vezlo/assistant-server 2.1.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/Dockerfile +6 -4
  2. package/README.md +27 -15
  3. package/database-schema.sql +9 -0
  4. package/dist/knexfile.d.ts.map +1 -1
  5. package/dist/knexfile.js +37 -17
  6. package/dist/knexfile.js.map +1 -1
  7. package/dist/src/bootstrap/initializeServices.d.ts.map +1 -1
  8. package/dist/src/bootstrap/initializeServices.js +12 -1
  9. package/dist/src/bootstrap/initializeServices.js.map +1 -1
  10. package/dist/src/config/global.d.ts.map +1 -1
  11. package/dist/src/config/global.js +10 -1
  12. package/dist/src/config/global.js.map +1 -1
  13. package/dist/src/controllers/AuthController.d.ts +4 -1
  14. package/dist/src/controllers/AuthController.d.ts.map +1 -1
  15. package/dist/src/controllers/AuthController.js +8 -3
  16. package/dist/src/controllers/AuthController.js.map +1 -1
  17. package/dist/src/controllers/ChatController.d.ts +8 -1
  18. package/dist/src/controllers/ChatController.d.ts.map +1 -1
  19. package/dist/src/controllers/ChatController.js +476 -15
  20. package/dist/src/controllers/ChatController.js.map +1 -1
  21. package/dist/src/migrations/005_add_conversation_handoff_columns.d.ts +4 -0
  22. package/dist/src/migrations/005_add_conversation_handoff_columns.d.ts.map +1 -0
  23. package/dist/src/migrations/005_add_conversation_handoff_columns.js +42 -0
  24. package/dist/src/migrations/005_add_conversation_handoff_columns.js.map +1 -0
  25. package/dist/src/schemas/ConversationSchemas.d.ts +125 -33
  26. package/dist/src/schemas/ConversationSchemas.d.ts.map +1 -1
  27. package/dist/src/schemas/ConversationSchemas.js +47 -18
  28. package/dist/src/schemas/ConversationSchemas.js.map +1 -1
  29. package/dist/src/schemas/MessageSchemas.d.ts +9 -0
  30. package/dist/src/schemas/MessageSchemas.d.ts.map +1 -1
  31. package/dist/src/schemas/MessageSchemas.js +3 -1
  32. package/dist/src/schemas/MessageSchemas.js.map +1 -1
  33. package/dist/src/schemas/index.d.ts +134 -33
  34. package/dist/src/schemas/index.d.ts.map +1 -1
  35. package/dist/src/server.js +222 -27
  36. package/dist/src/server.js.map +1 -1
  37. package/dist/src/services/ChatManager.d.ts.map +1 -1
  38. package/dist/src/services/ChatManager.js +26 -29
  39. package/dist/src/services/ChatManager.js.map +1 -1
  40. package/dist/src/services/IntentService.d.ts.map +1 -1
  41. package/dist/src/services/IntentService.js +6 -3
  42. package/dist/src/services/IntentService.js.map +1 -1
  43. package/dist/src/services/RealtimePublisher.d.ts +6 -0
  44. package/dist/src/services/RealtimePublisher.d.ts.map +1 -0
  45. package/dist/src/services/RealtimePublisher.js +43 -0
  46. package/dist/src/services/RealtimePublisher.js.map +1 -0
  47. package/dist/src/services/SetupService.d.ts +2 -0
  48. package/dist/src/services/SetupService.d.ts.map +1 -1
  49. package/dist/src/services/SetupService.js +60 -47
  50. package/dist/src/services/SetupService.js.map +1 -1
  51. package/dist/src/storage/ConversationRepository.d.ts +2 -2
  52. package/dist/src/storage/ConversationRepository.d.ts.map +1 -1
  53. package/dist/src/storage/ConversationRepository.js +36 -19
  54. package/dist/src/storage/ConversationRepository.js.map +1 -1
  55. package/dist/src/storage/MessageRepository.d.ts +4 -1
  56. package/dist/src/storage/MessageRepository.d.ts.map +1 -1
  57. package/dist/src/storage/MessageRepository.js +10 -4
  58. package/dist/src/storage/MessageRepository.js.map +1 -1
  59. package/dist/src/storage/SupabaseStorage.d.ts +5 -3
  60. package/dist/src/storage/SupabaseStorage.d.ts.map +1 -1
  61. package/dist/src/storage/SupabaseStorage.js +42 -11
  62. package/dist/src/storage/SupabaseStorage.js.map +1 -1
  63. package/dist/src/storage/UnifiedStorage.d.ts +5 -3
  64. package/dist/src/storage/UnifiedStorage.d.ts.map +1 -1
  65. package/dist/src/storage/UnifiedStorage.js +4 -4
  66. package/dist/src/storage/UnifiedStorage.js.map +1 -1
  67. package/dist/src/types/index.d.ts +24 -4
  68. package/dist/src/types/index.d.ts.map +1 -1
  69. package/knexfile.ts +44 -17
  70. package/package.json +5 -4
  71. package/scripts/entrypoint.sh +44 -4
  72. package/scripts/seed-default.js +0 -0
  73. package/scripts/setup.js +66 -12
package/scripts/setup.js CHANGED
@@ -9,6 +9,29 @@ const fs = require('fs');
9
9
  const path = require('path');
10
10
  const readline = require('readline');
11
11
  const { createClient } = require('@supabase/supabase-js');
12
+ const knexLib = require('knex');
13
+ const pkgRoot = path.join(__dirname, '..');
14
+
15
+ const migrationCandidates = [
16
+ path.join(pkgRoot, 'dist', 'src', 'migrations'),
17
+ path.join(pkgRoot, 'dist', 'migrations'),
18
+ path.join(pkgRoot, 'src', 'migrations'),
19
+ path.join(process.cwd(), 'dist', 'src', 'migrations'),
20
+ path.join(process.cwd(), 'src', 'migrations')
21
+ ];
22
+
23
+ const fallbackMigrationDir = path.join(pkgRoot, 'dist', 'src', 'migrations');
24
+ const migrationDirectory = migrationCandidates.find(dir => fs.existsSync(dir)) || fallbackMigrationDir;
25
+
26
+ if (!fs.existsSync(migrationDirectory)) {
27
+ console.error(`❌ Migration directory not found. Expected one of:\n${migrationCandidates.concat(fallbackMigrationDir).join('\n')}`);
28
+ console.error('Run `npm run build` (or reinstall the package) to ensure compiled migrations exist.');
29
+ process.exit(1);
30
+ }
31
+
32
+ const usingDistMigrations = migrationDirectory.includes(`${path.sep}dist${path.sep}`);
33
+ const migrationExtension = usingDistMigrations ? 'js' : 'ts';
34
+ const migrationLoadExtensions = migrationExtension === 'ts' ? ['.ts'] : ['.js'];
12
35
 
13
36
  const rl = readline.createInterface({
14
37
  input: process.stdin,
@@ -300,9 +323,13 @@ async function saveEnvFile(envPath, config) {
300
323
  if (!config.MIGRATION_SECRET_KEY) {
301
324
  config.MIGRATION_SECRET_KEY = crypto.randomBytes(32).toString('hex');
302
325
  }
326
+ if (!config.JWT_SECRET) {
327
+ config.JWT_SECRET = crypto.randomBytes(32).toString('hex');
328
+ }
303
329
  } catch (_) {
304
- // Fallback simple key if crypto unavailable (very unlikely)
330
+ // Fallback simple values if crypto unavailable (very unlikely)
305
331
  config.MIGRATION_SECRET_KEY = config.MIGRATION_SECRET_KEY || `msk_${Date.now()}`;
332
+ config.JWT_SECRET = config.JWT_SECRET || `jwt_${Date.now()}`;
306
333
  }
307
334
  const envContent = `# Vezlo Assistant Server Configuration
308
335
  # Generated by setup wizard on ${new Date().toISOString()}
@@ -348,8 +375,16 @@ ASSISTANT_NAME=Vezlo Assistant
348
375
  CHUNK_SIZE=1000
349
376
  CHUNK_OVERLAP=200
350
377
 
378
+ # Chat History
379
+ CHAT_HISTORY_LENGTH=${config.CHAT_HISTORY_LENGTH || '2'}
380
+
351
381
  # Migration Security
352
382
  MIGRATION_SECRET_KEY=${config.MIGRATION_SECRET_KEY}
383
+
384
+ # Authentication / Defaults
385
+ JWT_SECRET=${config.JWT_SECRET}
386
+ DEFAULT_ADMIN_EMAIL=${config.DEFAULT_ADMIN_EMAIL || 'admin@vezlo.org'}
387
+ DEFAULT_ADMIN_PASSWORD=${config.DEFAULT_ADMIN_PASSWORD || 'admin123'}
353
388
  `;
354
389
 
355
390
  fs.writeFileSync(envPath, envContent, 'utf8');
@@ -459,15 +494,7 @@ async function setupMigrations(config, validationStatus) {
459
494
  if (runMigrations.toLowerCase() === 'y') {
460
495
  log('🔄 Running migrations...', 'yellow');
461
496
 
462
- // Set environment variables for migration
463
- process.env.SUPABASE_DB_HOST = config.SUPABASE_DB_HOST;
464
- process.env.SUPABASE_DB_PORT = config.SUPABASE_DB_PORT;
465
- process.env.SUPABASE_DB_NAME = config.SUPABASE_DB_NAME;
466
- process.env.SUPABASE_DB_USER = config.SUPABASE_DB_USER;
467
- process.env.SUPABASE_DB_PASSWORD = config.SUPABASE_DB_PASSWORD;
468
-
469
- const { execSync } = require('child_process');
470
- execSync('npm run migrate:latest', { stdio: 'inherit' });
497
+ await runMigrationsWithConfig(config);
471
498
 
472
499
  log('✅ Migrations completed successfully!', 'green');
473
500
  return { migrations: 'success' };
@@ -491,8 +518,7 @@ async function setupMigrations(config, validationStatus) {
491
518
  if (runPending.toLowerCase() === 'y') {
492
519
  log('🔄 Checking for pending migrations...', 'yellow');
493
520
 
494
- const { execSync } = require('child_process');
495
- execSync('npm run migrate:latest', { stdio: 'inherit' });
521
+ await runMigrationsWithConfig(config);
496
522
 
497
523
  log('✅ Migration check completed!', 'green');
498
524
  await client.end();
@@ -531,6 +557,34 @@ main().catch(error => {
531
557
  rl.close();
532
558
  process.exit(1);
533
559
  });
560
+
561
+ async function runMigrationsWithConfig(config) {
562
+ const knexInstance = knexLib({
563
+ client: 'postgresql',
564
+ connection: {
565
+ host: config.SUPABASE_DB_HOST,
566
+ port: parseInt(config.SUPABASE_DB_PORT),
567
+ database: config.SUPABASE_DB_NAME,
568
+ user: config.SUPABASE_DB_USER,
569
+ password: config.SUPABASE_DB_PASSWORD,
570
+ ssl: { rejectUnauthorized: false }
571
+ },
572
+ migrations: {
573
+ directory: migrationDirectory,
574
+ tableName: 'knex_migrations',
575
+ extension: migrationExtension,
576
+ loadExtensions: migrationLoadExtensions
577
+ },
578
+ pool: { min: 0, max: 10 }
579
+ });
580
+
581
+ try {
582
+ await knexInstance.migrate.latest();
583
+ } finally {
584
+ await knexInstance.destroy();
585
+ }
586
+ }
587
+
534
588
  async function setupDefaultData(config) {
535
589
  log('🔄 Setting up default company and admin user...', 'yellow');
536
590