mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 22:04:46 +00:00
Add Anthropic prompt caching, pluggable storage, and CORS proxy support
Storage Architecture:
- New pluggable storage system with backends (LocalStorage, ChromeStorage, IndexedDB)
- SettingsRepository for app settings (proxy config, etc.)
- ProviderKeysRepository for API key management
- AppStorage with global accessors (getAppStorage, setAppStorage, initAppStorage)
Transport Refactoring:
- Renamed DirectTransport → ProviderTransport (calls LLM providers with optional CORS proxy)
- Renamed ProxyTransport → AppTransport (uses app server with user auth)
- Updated TransportMode: "direct" → "provider", "proxy" → "app"
CORS Proxy Integration:
- ProviderTransport checks proxy.enabled/proxy.url from storage
- When enabled, modifies model baseUrl to route through proxy: {proxyUrl}/?url={originalBaseUrl}
- ProviderKeyInput test function also honors proxy settings
- Settings dialog with Proxy tab (Switch toggle, URL input, explanatory description)
Anthropic Prompt Caching:
- System prompt cached with cache_control markers (both OAuth and regular API keys)
- Last user message cached to cache conversation history
- Saves 90% on input tokens for cached content (10x cost reduction)
Settings Dialog Improvements:
- Configurable tab system with SettingsTab base class
- ApiKeysTab and ProxyTab as custom elements
- Switch toggle for proxy enable (instead of Checkbox)
- Explanatory paragraphs for each tab
- ApiKeyPromptDialog reuses ProviderKeyInput component
Removed:
- Deprecated ApiKeysDialog (replaced by ProviderKeyInput in SettingsDialog)
- Old storage-adapter and key-store (replaced by new storage architecture)
This commit is contained in:
parent
66f092c0c6
commit
0496651308
31 changed files with 1141 additions and 488 deletions
53
packages/web-ui/src/storage/app-storage.ts
Normal file
53
packages/web-ui/src/storage/app-storage.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { LocalStorageBackend } from "./backends/local-storage-backend.js";
|
||||
import { ProviderKeysRepository } from "./repositories/provider-keys-repository.js";
|
||||
import { SettingsRepository } from "./repositories/settings-repository.js";
|
||||
import type { AppStorageConfig } from "./types.js";
|
||||
|
||||
/**
|
||||
* High-level storage API aggregating all repositories.
|
||||
* Apps configure backends and use repositories through this interface.
|
||||
*/
|
||||
export class AppStorage {
|
||||
readonly settings: SettingsRepository;
|
||||
readonly providerKeys: ProviderKeysRepository;
|
||||
|
||||
constructor(config: AppStorageConfig = {}) {
|
||||
// Use LocalStorage with prefixes as defaults
|
||||
const settingsBackend = config.settings ?? new LocalStorageBackend("settings");
|
||||
const providerKeysBackend = config.providerKeys ?? new LocalStorageBackend("providerKeys");
|
||||
|
||||
this.settings = new SettingsRepository(settingsBackend);
|
||||
this.providerKeys = new ProviderKeysRepository(providerKeysBackend);
|
||||
}
|
||||
}
|
||||
|
||||
// Global instance management
|
||||
let globalAppStorage: AppStorage | null = null;
|
||||
|
||||
/**
|
||||
* Get the global AppStorage instance.
|
||||
* Throws if not initialized.
|
||||
*/
|
||||
export function getAppStorage(): AppStorage {
|
||||
if (!globalAppStorage) {
|
||||
throw new Error("AppStorage not initialized. Call setAppStorage() first.");
|
||||
}
|
||||
return globalAppStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the global AppStorage instance.
|
||||
*/
|
||||
export function setAppStorage(storage: AppStorage): void {
|
||||
globalAppStorage = storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize AppStorage with default configuration if not already set.
|
||||
*/
|
||||
export function initAppStorage(config: AppStorageConfig = {}): AppStorage {
|
||||
if (!globalAppStorage) {
|
||||
globalAppStorage = new AppStorage(config);
|
||||
}
|
||||
return globalAppStorage;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue