112 lines
2.4 KiB
TypeScript
112 lines
2.4 KiB
TypeScript
import Store from 'electron-store';
|
|
|
|
interface WindowState {
|
|
width: number;
|
|
height: number;
|
|
}
|
|
|
|
interface LLMConfig {
|
|
provider: 'openai' | 'openrouter' | 'ollama';
|
|
apiKey?: string | null;
|
|
model?: string;
|
|
baseUrl?: string;
|
|
temperature?: number;
|
|
}
|
|
|
|
interface Document {
|
|
path: string;
|
|
type: string;
|
|
lastModified: number;
|
|
size: number;
|
|
}
|
|
|
|
interface Schema {
|
|
windowState: WindowState;
|
|
llm_config: LLMConfig;
|
|
watchedPaths: string[];
|
|
excludedPaths: string[];
|
|
documents: Record<string, Document>;
|
|
}
|
|
|
|
const schema: Store.Schema<Schema> = {
|
|
windowState: {
|
|
type: 'object',
|
|
properties: {
|
|
width: { type: 'number', minimum: 400 },
|
|
height: { type: 'number', minimum: 300 }
|
|
},
|
|
required: ['width', 'height'],
|
|
additionalProperties: false,
|
|
default: {
|
|
width: 1200,
|
|
height: 800
|
|
}
|
|
},
|
|
llm_config: {
|
|
type: 'object',
|
|
properties: {
|
|
provider: {
|
|
type: 'string',
|
|
enum: ['openai', 'openrouter', 'ollama']
|
|
},
|
|
apiKey: { type: ['string', 'null'] },
|
|
model: { type: 'string' },
|
|
baseUrl: { type: 'string' },
|
|
temperature: { type: 'number', minimum: 0, maximum: 1 }
|
|
},
|
|
required: ['provider'],
|
|
additionalProperties: false,
|
|
default: {
|
|
provider: 'ollama',
|
|
model: 'phi4',
|
|
baseUrl: 'http://localhost:11434',
|
|
temperature: 0.7
|
|
}
|
|
},
|
|
watchedPaths: {
|
|
type: 'array',
|
|
items: { type: 'string' },
|
|
default: []
|
|
},
|
|
excludedPaths: {
|
|
type: 'array',
|
|
items: { type: 'string' },
|
|
default: []
|
|
},
|
|
documents: {
|
|
type: 'object',
|
|
additionalProperties: {
|
|
type: 'object',
|
|
properties: {
|
|
path: { type: 'string' },
|
|
type: { type: 'string' },
|
|
lastModified: { type: 'number' },
|
|
size: { type: 'number' }
|
|
},
|
|
required: ['path', 'type', 'lastModified', 'size']
|
|
},
|
|
default: {}
|
|
}
|
|
};
|
|
|
|
export const store = new Store<Schema>({
|
|
schema,
|
|
name: 'config',
|
|
clearInvalidConfig: true,
|
|
migrations: {
|
|
'>=0.0.1': (store) => {
|
|
const currentConfig = store.get('llm_config');
|
|
if (currentConfig) {
|
|
const cleanConfig = {
|
|
provider: currentConfig.provider || 'ollama',
|
|
apiKey: currentConfig.apiKey,
|
|
model: currentConfig.model,
|
|
baseUrl: currentConfig.baseUrl,
|
|
temperature: currentConfig.temperature
|
|
};
|
|
store.set('llm_config', cleanConfig);
|
|
}
|
|
}
|
|
}
|
|
});
|