Skip to content

Commit 1ea30fb

Browse files
authored
Merge pull request #3 from silexi/fix/cli-start-missing-repo-init
fix: Initialize repo caches in CLI start & include local providers in demo mode
2 parents 9e3d608 + 6cbdf10 commit 1ea30fb

4 files changed

Lines changed: 47 additions & 4 deletions

File tree

packages/cli/src/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ import {
1818
configChangePassword,
1919
loadCredentialsToEnv,
2020
} from './commands/config.js';
21+
import {
22+
initializeAdapter,
23+
initializeSettingsRepo,
24+
initializeConfigServicesRepo,
25+
initializeLocalProvidersRepo,
26+
initializePluginsRepo,
27+
seedConfigServices,
28+
} from '@ownpilot/gateway';
29+
30+
/**
31+
* Initialize database adapter and all repository caches.
32+
* Must run before any code that accesses settings or local providers.
33+
*/
34+
async function initializeAll(): Promise<void> {
35+
await initializeAdapter();
36+
await initializeSettingsRepo();
37+
await initializeConfigServicesRepo();
38+
await seedConfigServices();
39+
await initializePluginsRepo();
40+
await initializeLocalProvidersRepo();
41+
}
2142
import {
2243
channelList,
2344
channelAdd,
@@ -54,7 +75,7 @@ program
5475
.option('-p, --password <password>', 'Master password (will prompt if not provided)')
5576
.action(setup);
5677

57-
// Server command - loads credentials before starting
78+
// Server command - initializes repos before starting
5879
program
5980
.command('server')
6081
.description('Start the HTTP API server')
@@ -63,6 +84,7 @@ program
6384
.option('--no-auth', 'Disable authentication')
6485
.option('--no-rate-limit', 'Disable rate limiting')
6586
.action(async (options) => {
87+
await initializeAll();
6688
await loadCredentialsToEnv();
6789
await startServer(options);
6890
});
@@ -76,17 +98,19 @@ program
7698
.option('--users <ids>', 'Comma-separated allowed user IDs')
7799
.option('--chats <ids>', 'Comma-separated allowed chat IDs')
78100
.action(async (options) => {
101+
await initializeAll();
79102
await loadCredentialsToEnv();
80103
await startBot(options);
81104
});
82105

83-
// Start all command - loads credentials before starting
106+
// Start all command - initializes repos before starting
84107
program
85108
.command('start')
86109
.description('Start both server and bot')
87110
.option('-p, --port <port>', 'Server port', '8080')
88111
.option('--no-bot', 'Skip starting the Telegram bot')
89112
.action(async (options) => {
113+
await initializeAll();
90114
await loadCredentialsToEnv();
91115
await startAll(options);
92116
});

packages/gateway/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export {
7272
// Database
7373
export { initializeAdapter, closeAdapter, getAdapter } from './db/adapters/index.js';
7474
export { settingsRepo } from './db/repositories/index.js';
75+
export { initializeSettingsRepo } from './db/repositories/settings.js';
76+
export { initializeConfigServicesRepo } from './db/repositories/config-services.js';
77+
export { initializeLocalProvidersRepo } from './db/repositories/local-providers.js';
78+
export { initializePluginsRepo } from './db/repositories/plugins.js';
79+
export { seedConfigServices } from './db/seeds/config-services-seed.js';
7580

7681
// Plugins
7782
export { initializePlugins, getDefaultPluginRegistry } from './plugins/index.js';

packages/gateway/src/routes/agent-service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
getConfiguredProviderIds,
3232
getEnabledToolGroupIds,
3333
} from './settings.js';
34+
import { localProvidersRepo } from '../db/repositories/local-providers.js';
3435
import { gatewayConfigCenter } from '../services/config-center-impl.js';
3536
import { getLog } from '../services/log.js';
3637
import { BASE_SYSTEM_PROMPT } from './agent-prompt.js';
@@ -744,6 +745,7 @@ export function getWorkspaceContext(sessionWorkspaceDir?: string): WorkspaceCont
744745
* Check if demo mode is enabled (no API keys configured)
745746
*/
746747
export async function isDemoMode(): Promise<boolean> {
748+
// Check cloud providers
747749
const configured = await getConfiguredProviderIds();
748750
const providers = [
749751
'openai',
@@ -758,5 +760,11 @@ export async function isDemoMode(): Promise<boolean> {
758760
'fireworks',
759761
'perplexity',
760762
];
761-
return !providers.some((p) => configured.has(p));
763+
if (providers.some((p) => configured.has(p))) return false;
764+
765+
// Check local providers (Ollama, LM Studio, etc.)
766+
const localProviders = await localProvidersRepo.listProviders();
767+
if (localProviders.some((p: { isEnabled: boolean }) => p.isEnabled)) return false;
768+
769+
return true;
762770
}

packages/gateway/src/routes/settings.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,13 @@ export async function resolveProviderAndModel(
326326
*/
327327
export async function isDemoModeFromSettings(): Promise<boolean> {
328328
const apiKeySettings = await settingsRepo.getByPrefix(API_KEY_PREFIX);
329-
return apiKeySettings.length === 0;
329+
if (apiKeySettings.length > 0) return false;
330+
331+
// Check local providers (Ollama, LM Studio, etc.)
332+
const localProviders = await localProvidersRepo.listProviders();
333+
if (localProviders.some((p: { isEnabled: boolean }) => p.isEnabled)) return false;
334+
335+
return true;
330336
}
331337

332338
/**

0 commit comments

Comments
 (0)