cli4ai 1.2.6 → 1.2.7

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.
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Allows other cli4ai instances to execute tools on this machine.
5
5
  */
6
- import { output, outputError } from '../lib/cli.js';
6
+ import { output, outputError, log } from '../lib/cli.js';
7
7
  import { startService } from '../server/service.js';
8
8
  export async function serveCommand(options) {
9
9
  const serviceOptions = {
@@ -38,7 +38,16 @@ export async function serveCommand(options) {
38
38
  }
39
39
  // Enable dashboard UI
40
40
  if (options.ui) {
41
- serviceOptions.enableDashboard = true;
41
+ // Check if sqlite is available for dashboard
42
+ const { isSqliteAvailable } = await import('../dashboard/db/index.js');
43
+ if (!isSqliteAvailable()) {
44
+ log('Warning: Dashboard requires better-sqlite3 which is not installed.');
45
+ log('Dashboard will be disabled. Install with: npm install better-sqlite3');
46
+ log('');
47
+ }
48
+ else {
49
+ serviceOptions.enableDashboard = true;
50
+ }
42
51
  }
43
52
  // Additional allowed paths for file downloads (adds to defaults)
44
53
  if (options.allowPath && options.allowPath.length > 0) {
@@ -3,8 +3,10 @@
3
3
  *
4
4
  * Manages the SQLite database for storing run history, logs, and metrics.
5
5
  * Database is stored at ~/.cli4ai/dashboard.db
6
+ *
7
+ * NOTE: better-sqlite3 is an optional dependency. If not installed,
8
+ * dashboard features will be disabled.
6
9
  */
7
- import Database from 'better-sqlite3';
8
10
  export interface DatabaseConfig {
9
11
  /** Path to database file (default: ~/.cli4ai/dashboard.db) */
10
12
  path?: string;
@@ -13,6 +15,12 @@ export interface DatabaseConfig {
13
15
  /** Enable verbose logging (default: false) */
14
16
  verbose?: boolean;
15
17
  }
18
+ type DatabaseInstance = any;
19
+ declare let Database: any;
20
+ /**
21
+ * Check if better-sqlite3 is available
22
+ */
23
+ export declare function isSqliteAvailable(): boolean;
16
24
  /**
17
25
  * Get the default database path
18
26
  */
@@ -20,8 +28,9 @@ export declare function getDefaultDbPath(): string;
20
28
  /**
21
29
  * Initialize and return the database connection.
22
30
  * Creates the database and tables if they don't exist.
31
+ * Returns null if better-sqlite3 is not installed.
23
32
  */
24
- export declare function getDatabase(config?: DatabaseConfig): Database.Database;
33
+ export declare function getDatabase(config?: DatabaseConfig): DatabaseInstance | null;
25
34
  /**
26
35
  * Close the database connection.
27
36
  */
@@ -29,5 +38,5 @@ export declare function closeDatabase(): void;
29
38
  /**
30
39
  * Get database for testing (allows custom path)
31
40
  */
32
- export declare function getTestDatabase(path: string): Database.Database;
41
+ export declare function getTestDatabase(path: string): DatabaseInstance | null;
33
42
  export { Database };
@@ -3,12 +3,43 @@
3
3
  *
4
4
  * Manages the SQLite database for storing run history, logs, and metrics.
5
5
  * Database is stored at ~/.cli4ai/dashboard.db
6
+ *
7
+ * NOTE: better-sqlite3 is an optional dependency. If not installed,
8
+ * dashboard features will be disabled.
6
9
  */
7
- import Database from 'better-sqlite3';
8
10
  import { homedir } from 'os';
9
11
  import { join } from 'path';
10
12
  import { existsSync, mkdirSync } from 'fs';
11
- import { initSchema } from './schema.js';
13
+ // ═══════════════════════════════════════════════════════════════════════════
14
+ // SQLITE AVAILABILITY CHECK
15
+ // ═══════════════════════════════════════════════════════════════════════════
16
+ let sqliteAvailable = null;
17
+ let Database = null;
18
+ /**
19
+ * Try to load better-sqlite3 synchronously
20
+ */
21
+ function tryLoadSqlite() {
22
+ if (sqliteAvailable !== null) {
23
+ return sqliteAvailable;
24
+ }
25
+ try {
26
+ // Use require for synchronous loading
27
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
28
+ Database = require('better-sqlite3');
29
+ sqliteAvailable = true;
30
+ return true;
31
+ }
32
+ catch {
33
+ sqliteAvailable = false;
34
+ return false;
35
+ }
36
+ }
37
+ /**
38
+ * Check if better-sqlite3 is available
39
+ */
40
+ export function isSqliteAvailable() {
41
+ return tryLoadSqlite();
42
+ }
12
43
  // ═══════════════════════════════════════════════════════════════════════════
13
44
  // SINGLETON DATABASE INSTANCE
14
45
  // ═══════════════════════════════════════════════════════════════════════════
@@ -22,11 +53,16 @@ export function getDefaultDbPath() {
22
53
  /**
23
54
  * Initialize and return the database connection.
24
55
  * Creates the database and tables if they don't exist.
56
+ * Returns null if better-sqlite3 is not installed.
25
57
  */
26
58
  export function getDatabase(config = {}) {
27
59
  if (db) {
28
60
  return db;
29
61
  }
62
+ // Check if sqlite is available
63
+ if (!tryLoadSqlite()) {
64
+ return null;
65
+ }
30
66
  const dbPath = config.path ?? getDefaultDbPath();
31
67
  const dbDir = join(dbPath, '..');
32
68
  // Ensure the directory exists
@@ -44,6 +80,8 @@ export function getDatabase(config = {}) {
44
80
  // Enable foreign keys
45
81
  db.pragma('foreign_keys = ON');
46
82
  // Initialize schema (creates tables if they don't exist)
83
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
84
+ const { initSchema } = require('./schema.js');
47
85
  initSchema(db);
48
86
  return db;
49
87
  }
@@ -60,9 +98,14 @@ export function closeDatabase() {
60
98
  * Get database for testing (allows custom path)
61
99
  */
62
100
  export function getTestDatabase(path) {
101
+ if (!tryLoadSqlite()) {
102
+ return null;
103
+ }
63
104
  const testDb = new Database(path);
64
105
  testDb.pragma('journal_mode = WAL');
65
106
  testDb.pragma('foreign_keys = ON');
107
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
108
+ const { initSchema } = require('./schema.js');
66
109
  initSchema(testDb);
67
110
  return testDb;
68
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli4ai",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "The package manager for AI CLI tools - cli4ai.com",
5
5
  "type": "module",
6
6
  "bin": {
@@ -19,13 +19,15 @@
19
19
  "dashboard:build": "cd src/dashboard/web && npm run build"
20
20
  },
21
21
  "dependencies": {
22
- "better-sqlite3": "^11.7.0",
23
22
  "commander": "^14.0.0",
24
23
  "cron-parser": "^4.9.0",
25
24
  "semver": "^7.6.0",
26
25
  "ws": "^8.18.0",
27
26
  "yaml": "^2.8.2"
28
27
  },
28
+ "optionalDependencies": {
29
+ "better-sqlite3": "^11.7.0"
30
+ },
29
31
  "devDependencies": {
30
32
  "@types/better-sqlite3": "^7.6.11",
31
33
  "@types/node": "^22.0.0",