Commit Graph

23 Commits

  • feat(coding-agent): complete steer()/followUp() migration
    - Update settings-manager with steeringMode/followUpMode (migrates old queueMode)
    - Update sdk.ts to use new mode options
    - Update settings-selector UI to show both modes
    - Add Alt+Enter keybind for follow-up messages
    - Update RPC API: steer/follow_up commands, set_steering_mode/set_follow_up_mode
    - Update rpc-client with new methods
    - Delete dead code: queue-mode-selector.ts
    - Update tests for new API
    - Update mom/context.ts stubs
    - Update web-ui example
  • AgentInterface sets default streamFn and getApiKey
    - Make Agent.streamFn and Agent.getApiKey public
    - AgentInterface sets defaults if not already set
    - Example no longer needs to configure these
  • Allow async streamFn for dynamic proxy settings
    - StreamFn type now allows returning Promise
    - agent-loop awaits streamFn result
    - createStreamFn takes getProxyUrl callback, reads settings on each call
  • Add createStreamFn for CORS proxy support
    - createStreamFn(proxyUrl?) returns a sync streamFn that applies proxy
    - Example reads proxy settings once when creating Agent
    - Matches old ProviderTransport behavior
  • Add getApiKey to web-ui example Agent config
    Provides API keys from the provider keys store, matching old ProviderTransport behavior.
  • Add defaultConvertToLlm to web-ui, simplify example
    - web-ui exports: defaultConvertToLlm, convertAttachments, isUserMessageWithAttachments, isArtifactMessage
    - defaultConvertToLlm handles UserMessageWithAttachments and filters ArtifactMessage
    - Example's customMessageTransformer now extends defaultConvertToLlm
    - Removes duplicated attachment conversion logic from example
  • Fix web-ui and example for new agent API
    - AgentInterface composes UserMessageWithAttachments for attachments
    - Updated example to use convertToLlm instead of transport/messageTransformer
    - Fixed declaration merging: target pi-agent-core, add path to example tsconfig
    - Fixed typo in CustomAgentMessages key (user-with-attachment -> user-with-attachments)
    - customMessageTransformer properly converts UserMessageWithAttachments to content blocks
  • 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
  • WIP: Remove global state from pi-ai OAuth/API key handling
    - Remove setApiKey, resolveApiKey, and global apiKeys Map from stream.ts
    - Rename getApiKey to getApiKeyFromEnv (only checks env vars)
    - Remove OAuth storage layer (storage.ts deleted)
    - OAuth login/refresh functions now return credentials instead of saving
    - getOAuthApiKey/refreshOAuthToken now take credentials as params
    - Add test/oauth.ts helper for ai package tests
    - Simplify root npm run check (single biome + tsgo pass)
    - Remove redundant check scripts from most packages
    - Add web-ui and coding-agent examples to biome/tsgo includes
    
    coding-agent still has compile errors - needs refactoring for new API
  • 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
  • Fix Lit dependency duplication and update mini-lit to 0.2.0
    - Move lit from dependencies to peerDependencies in web-ui to prevent multiple Lit instances being loaded
    - Update mini-lit from 0.1.8/0.1.10 to 0.2.0 in root package.json and web-ui/package.json
    - Install @tailwindcss/vite in web-ui/example
    - Run biome formatting fixes across codebase
    
    This resolves HMR custom element re-registration errors caused by duplicate Lit registries.
  • Add artifact message persistence for session reconstruction
    - Add ArtifactMessage type as core part of AppMessage union (not CustomMessages)
    - ArtifactsRuntimeProvider appends artifact messages on create/update/delete
    - MessageList filters out artifact messages (UI display only)
    - artifacts.ts reconstructFromMessages handles artifact messages
    - Export ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION from main index
    - Fix artifact creation bug: pass filename as title instead of mimeType
    
    Changes:
    - web-ui/src/components/Messages.ts: Add ArtifactMessage to BaseMessage union
    - web-ui/src/components/MessageList.ts: Skip artifact messages in render
    - web-ui/src/components/sandbox/ArtifactsRuntimeProvider.ts: Append messages, fix title parameter
    - web-ui/src/ChatPanel.ts: Pass agent.appendMessage callback
    - web-ui/src/tools/artifacts/artifacts.ts: Handle artifact messages in reconstructFromMessages
    - web-ui/src/index.ts: Export ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION
    - web-ui/example/src/custom-messages.ts: Update message transformer to filter artifacts
  • 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
  • Fix SessionListDialog behavior and document PersistentStorageDialog bug
    - Fix SessionListDialog to not reload when user selects a session after deleting others
      - Track if dialog closed via selection vs other means
      - Only call delete callback if not closed via selection
      - Batch deletions to avoid reload on every delete
    - Comment out PersistentStorageDialog in both web-ui example and browser extension (TODO: fix)
    - Add Known Bugs section to both README.md files documenting PersistentStorageDialog issue
    - Clean up navigation tracking variable names in browser extension
  • Add custom message extension system with typed renderers and message transformer
    - Implement CustomMessages interface for type-safe message extension via declaration merging
    - Add MessageRenderer<T> with generic typing for custom message rendering
    - Add messageTransformer to Agent for filtering/transforming messages before LLM
    - Move message filtering from transports to Agent (separation of concerns)
    - Add message renderer registry with typed role support
    - Update web-ui example with SystemNotificationMessage demo
    - Add custom transformer that converts notifications to <system> tags
    - Add SessionListDialog onDelete callback for active session cleanup
    - Handle non-existent session IDs in URL (redirect to new session)
    - Update both web-ui example and browser extension with session fixes
  • 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)