Skip to content

Commit 84f0ede

Browse files
author
Ruben Gomez
committed
Fix config new validation, config schema
1 parent 6b5b88d commit 84f0ede

3 files changed

Lines changed: 40 additions & 96 deletions

File tree

ainara/framework/config.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
import copy
2020
# import logging
2121
import os
22-
import platform
2322
import shutil
2423
import sys
2524
from pathlib import Path
2625
# import traceback
2726
import yaml
2827
import json
29-
from jsonschema import validate, ValidationError, Draft7Validator
28+
from jsonschema import Draft7Validator
3029

3130
from ainara.framework.platform_utils import (
3231
get_default_cache_dir,
@@ -108,6 +107,12 @@ def _get_schema_path(self):
108107

109108
def create_default_config(self, target_path):
110109
"""Create a new configuration file from defaults"""
110+
dry_run = False
111+
112+
if self.needs_load():
113+
print("INFO: Configuration file has changed won't update")
114+
dry_run = True
115+
111116
default_path = self._get_default_config_path()
112117

113118
if not default_path:
@@ -123,9 +128,10 @@ def create_default_config(self, target_path):
123128
target_dir = os.path.dirname(target_path)
124129
os.makedirs(target_dir, exist_ok=True)
125130

126-
# Copy the default config
127-
shutil.copy(default_path, target_path)
128-
print(f"Created new configuration file at: {target_path}")
131+
if not dry_run:
132+
# Copy the default config
133+
shutil.copy(default_path, target_path)
134+
print(f"Created new configuration file at: {target_path}")
129135

130136
return target_path
131137

@@ -295,6 +301,11 @@ def save(self):
295301
def update_config(self, new_config, save=True):
296302
"""Update configuration with new values"""
297303

304+
if self.needs_load():
305+
print("INFO: Configuration file has changed, reloading.")
306+
self.load_config()
307+
return True
308+
298309
# Recursively update the configuration
299310
def update_dict(target, source):
300311
# Update existing keys and add new ones from source
@@ -425,6 +436,10 @@ def validate_config(self, config_data):
425436
# This is a simple validation - in a real implementation, you might want to use
426437
# a more formal schema validation
427438

439+
if self.needs_load():
440+
print("INFO: Configuration file has changed, reloading.")
441+
self.load_config()
442+
428443
result = {"valid": True, "errors": []}
429444

430445
# Check for required top-level sections

polaris/main.js

Lines changed: 19 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -55,85 +55,16 @@ const triggerKey = config.get('shortcuts.trigger', 'Space');
5555
const hideKey = config.get('shortcuts.hide', 'Escape');
5656
const myEmitter = new EventEmitter();
5757

58-
function applyAutoStartSetting() {
59-
const autoStartEnabled = config.get('startup.autoStart', false);
60-
Logger.info(`Applying auto-start setting. Enabled: ${autoStartEnabled}`);
61-
// This API is cross-platform and handles the underlying OS specifics.
62-
app.setLoginItemSettings({
63-
openAtLogin: autoStartEnabled,
64-
path: app.getPath('exe') // This is used by Windows and ignored by others.
65-
});
66-
}
67-
68-
// // Add service management to tray menu
69-
// const contextMenu = Menu.buildFromTemplate([
70-
// {
71-
// label: 'KK Setup',
72-
// click: () => { windowManager.hideAll(true); showSetupWizard(); }
73-
// },
74-
// { type: 'separator' },
75-
// {
76-
// label: 'LLM Models',
77-
// submenu: [
78-
// {
79-
// label: 'Configure Providers',
80-
// click: () => showSetupWizard()
81-
// },
82-
// { type: 'separator' },
83-
// {
84-
// label: 'Loading providers...',
85-
// enabled: false
86-
// }
87-
// ]
88-
// },
89-
// { type: 'separator' },
90-
// {
91-
// label: 'Show',
92-
// click: () => windowManager.showAll()
93-
// },
94-
// {
95-
// label: 'Hide',
96-
// click: () => windowManager.hideAll(true)
97-
// },
98-
// { type: 'separator' },
99-
// {
100-
// label: 'Check for Updates',
101-
// click: () => checkForUpdates(true)
102-
// },
103-
// { type: 'separator' },
104-
// {
105-
// label: 'Help',
106-
// click: () => {
107-
// const comRing = windowManager.getWindow('comRing');
108-
// if (comRing) {
109-
// if (!comRing.isVisible()) {
110-
// windowManager.showAll();
111-
// }
112-
// comRing.send('show-help');
113-
// }
114-
// }
115-
// },
116-
// {
117-
// label: 'About',
118-
// click: () => {
119-
// const comRing = windowManager.getWindow('comRing');
120-
// if (comRing) {
121-
// if (!comRing.isVisible()) {
122-
// windowManager.showAll();
123-
// }
124-
// comRing.send('show-about');
125-
// }
126-
// }
127-
// },
128-
// { type: 'separator' },
129-
// {
130-
// label: 'Quit',
131-
// click: () => {
132-
// app.isQuitting = true;
133-
// app.quit();
134-
// }
135-
// }
136-
// ]);
58+
// TODO delayed to v0.10
59+
// function applyAutoStartSetting() {
60+
// const autoStartEnabled = config.get('startup.autoStart', false);
61+
// Logger.info(`Applying auto-start setting. Enabled: ${autoStartEnabled}`);
62+
// // This API is cross-platform and handles the underlying OS specifics.
63+
// app.setLoginItemSettings({
64+
// openAtLogin: autoStartEnabled,
65+
// path: app.getPath('exe') // This is used by Windows and ignored by others.
66+
// });
67+
// }
13768

13869
// Check if this is the first run of the application
13970
function isFirstRun() {
@@ -143,9 +74,7 @@ function isFirstRun() {
14374
// Show the setup wizard for first-time users
14475
function showSetupWizard(validationErrors = []) {
14576
console.trace();
146-
if (validationErrors && validationErrors.length > 0) {
147-
// ServiceManager.stopServices({ force: true });
148-
// app.exit(1)
77+
if (validationErrors && validationErrors.length > 0 && config.get("setup.completed", false)) {
14978
Logger.warn('Configuration validation failed, invalidating setup.complete because of these errors:', validationErrors);
15079
config.set("setup.completed", false);
15180
} else {
@@ -200,14 +129,14 @@ function showSetupWizard(validationErrors = []) {
200129
setupWindow.loadFile(path.join(__dirname, 'components', 'setup.html'));
201130

202131
setupWindow.once('ready-to-show', () => {
203-
setupWindow.show();
204-
if (validationErrors && validationErrors.length > 0) {
132+
if (validationErrors && validationErrors.length > 0 && config.get("setup.completed", false)) {
205133
dialog.showErrorBox(
206134
'Configuration Error',
207135
'The configuration is missing some required values. The setup wizard will now launch. Error(s):\n\n' + validationErrors,
208136
// 'The configuration file contains the following errors:\n\n' + validationErrors + "\n\nThe setup wizard will be opened now."
209137
);
210138
}
139+
setupWindow.show();
211140
// // Pass validation errors to the wizard window
212141
// if (validationErrors && validationErrors.length > 0) {
213142
// setupWindow.webContents.send('config-validation-errors', validationErrors);
@@ -394,8 +323,8 @@ async function appInitialization() {
394323
app.isQuitting = false;
395324
await app.whenReady();
396325

397-
// Apply auto-start setting on launch
398-
applyAutoStartSetting();
326+
// // Apply auto-start setting on launch
327+
// applyAutoStartSetting();
399328

400329
// Initialize Ollama client
401330
initializeOllamaClient();
@@ -1092,10 +1021,10 @@ function appSetupEventHandlers() {
10921021
shell.openExternal(url);
10931022
});
10941023

1095-
// Handle auto-start setting changes from setup wizard
1096-
ipcMain.on('set-auto-start', () => {
1097-
applyAutoStartSetting();
1098-
});
1024+
// // Handle auto-start setting changes from setup wizard
1025+
// ipcMain.on('set-auto-start', () => {
1026+
// applyAutoStartSetting();
1027+
// });
10991028

11001029
// Handle backup directory selection from setup wizard
11011030
ipcMain.on('select-backup-directory', async (event) => {

resources/config.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"api_base": {"type": "string", "format": "uri"},
7979
"enable_thinking": {"type": "boolean"}
8080
},
81-
"required": ["model", "context_window"]
81+
"required": ["model"]
8282
}
8383
},
8484
"selected_backend": {"type": "string"},

0 commit comments

Comments
 (0)