Commit Graph

14 Commits

  • WIP: Major cleanup - move Attachment to consumers, simplify agent API
    - Removed Attachment from agent package (now in web-ui/coding-agent)
    - Agent.prompt now takes (text, images?: ImageContent[])
    - Removed transports from web-ui (duplicate of agent package)
    - Updated coding-agent to use local message types
    - Updated mom package for new agent API
    
    Remaining: Fix AgentInterface.ts to compose UserMessageWithAttachments
  • Add totalTokens field to Usage type
    - Added totalTokens field to Usage interface in pi-ai
    - Anthropic: computed as input + output + cacheRead + cacheWrite
    - OpenAI/Google: uses native total_tokens/totalTokenCount
    - Fixed openai-completions to compute totalTokens when reasoning tokens present
    - Updated calculateContextTokens() to use totalTokens field
    - Added comprehensive test covering 13 providers
    
    fixes #130
  • Add getAllFromIndex method for efficient sorted queries
    - Add getAllFromIndex to StorageBackend interface for index-based queries
    - Implement getAllFromIndex in IndexedDBStorageBackend using cursor API
    - Update SessionsStore.getAllMetadata to use lastModified index
    - Enables database-native sorting instead of fetching all keys and sorting in JS
    
    Benefits:
    - Much faster for large datasets (uses IndexedDB cursor with direction)
    - Reduces memory usage (no need to load all keys first)
    - Leverages existing indices for optimal performance
  • Add ollama dependency and dialog backdrop blur
    - Add ollama package to web-ui dependencies for ModelSelector
    - Add backdrop blur to SettingsDialog (bg-black/50 backdrop-blur-sm)
    - Update mini-lit to 0.1.9 for backdropClassName prop support
    - Fix TypeScript errors in ModelSelector (ollama import, parameter types)
    - Add backward compatibility methods to SessionsStore (saveSession, loadSession, getLatestSessionId)
  • Fix IndexedDB in-line vs out-of-line key handling
    - Check if store has keyPath before calling put()
    - If keyPath exists (in-line keys), only pass value: store.put(value)
    - If no keyPath (out-of-line keys), pass both: store.put(value, key)
    - Apply fix to both set() and transaction.set()
    - Fixes DataError when saving sessions with keyPath: 'id'
  • 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
  • Implement unified storage architecture
    - Replace fragmented storage backends with single IndexedDBStorageBackend
    - Create multi-store StorageBackend interface (storeName parameter)
    - Remove old backends: IndexedDBBackend, LocalStorageBackend, SessionIndexedDBBackend, WebExtensionStorageBackend
    - Remove old repositories: ProviderKeysRepository, SessionRepository, SettingsRepository
    - Simplify AppStorage to directly expose storage methods (getSetting/setSetting, getProviderKey/setProviderKey)
    - Create SessionsRepository for session-specific operations
    - Update all consumers to use new simplified API
    - Update example app to use new storage architecture
    - Benefits: 10GB+ quota (vs 10MB chrome.storage), single database, consistent API
  • Rename ChromeStorageBackend to WebExtensionStorageBackend for cross-browser support
    - Rename chrome-storage-backend.ts to web-extension-storage-backend.ts
    - Update to use globalThis.browser || globalThis.chrome for Firefox/Chrome compatibility
    - Export both names for backward compatibility
    - Fix tsc --preserveWatchOutput in web-ui dev script to prevent console clearing
    
    This fixes the "browser is not defined" error in Chrome extensions.
  • Refactor agent architecture and add session storage
    Major architectural improvements:
    - Renamed AgentSession → Agent (state/ → agent/)
    - Removed id field from AgentState
    - Fixed transport abstraction to pass messages directly instead of using callbacks
    - Eliminated circular dependencies in transport creation
    
    Transport changes:
    - Changed signature: run(messages, userMessage, config, signal)
    - Removed getMessages callback from ProviderTransport and AppTransport
    - Transports now filter attachments internally
    
    Session storage:
    - Added SessionRepository with IndexedDB backend
    - Auto-save sessions after first exchange
    - Auto-generate titles from first user message
    - Session list dialog with search and delete
    - Persistent storage permission dialog
    - Browser extension now auto-loads last session
    
    UI improvements:
    - ChatPanel creates single AgentInterface instance in setAgent()
    - Added drag & drop file upload to MessageEditor
    - Fixed artifacts panel auto-opening on session load
    - Added "Drop files here" i18n strings
    - Changed "Continue Without Saving" → "Continue Anyway"
    
    Web example:
    - Complete rewrite of main.ts with clean architecture
    - Added check script to package.json
    - Session management with URL state
    - Editable session titles
    
    Browser extension:
    - Added full session storage support
    - History and new session buttons
    - Auto-load most recent session on open
    - Session titles in header
  • 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)