Refactor to Store-based architecture

- Create base Store class with private backend and protected getBackend()
- Add SettingsStore, ProviderKeysStore, SessionsStore
- Each store defines its own schema via getConfig()
- AppStorage now takes stores + backend in constructor
- Remove SessionsRepository (logic moved to SessionsStore)
- Update all consumers to use store API (storage.settings.get/set, storage.providerKeys.get/set)
- Update example app to follow new pattern: create stores, gather configs, create backend, wire
- Benefits: stores own their schema, no circular deps, cleaner separation
This commit is contained in:
Mario Zechner 2025-10-08 16:41:02 +02:00
parent bbbc232c7c
commit 0de89a750e
13 changed files with 243 additions and 126 deletions

View file

@ -173,7 +173,7 @@ export class AgentInterface extends LitElement {
// Check if API key exists for the provider (only needed in direct mode)
const provider = session.state.model.provider;
const apiKey = await getAppStorage().getProviderKey(provider);
const apiKey = await getAppStorage().providerKeys.get(provider);
// If no API key, prompt for it
if (!apiKey) {

View file

@ -35,7 +35,7 @@ export class ProviderKeyInput extends LitElement {
private async checkKeyStatus() {
try {
const key = await getAppStorage().getProviderKey(this.provider);
const key = await getAppStorage().providerKeys.get(this.provider);
this.hasKey = !!key;
} catch (error) {
console.error("Failed to check key status:", error);
@ -51,8 +51,8 @@ export class ProviderKeyInput extends LitElement {
if (!model) return false;
// Check if CORS proxy is enabled and apply it
const proxyEnabled = await getAppStorage().getSetting<boolean>("proxy.enabled");
const proxyUrl = await getAppStorage().getSetting<string>("proxy.url");
const proxyEnabled = await getAppStorage().settings.get<boolean>("proxy.enabled");
const proxyUrl = await getAppStorage().settings.get<string>("proxy.url");
if (proxyEnabled && proxyUrl && model.baseUrl) {
model = {
@ -89,7 +89,7 @@ export class ProviderKeyInput extends LitElement {
if (success) {
try {
await getAppStorage().setProviderKey(this.provider, this.keyInput);
await getAppStorage().providerKeys.set(this.provider, this.keyInput);
this.hasKey = true;
this.keyInput = "";
this.requestUpdate();
@ -112,7 +112,7 @@ export class ProviderKeyInput extends LitElement {
private async removeKey() {
try {
await getAppStorage().deleteProviderKey(this.provider);
await getAppStorage().providerKeys.delete(this.provider);
this.hasKey = false;
this.keyInput = "";
this.requestUpdate();