Commit graph

172 commits

Author SHA1 Message Date
Mario Zechner
c9be21ebad Add navigation message tracking to browser extension
- Add onBeforeSend callback to ChatPanel and AgentInterface
- Add onBeforeToolCall callback (for future permission dialogs)
- Create NavigationMessage custom message type
- Add browserMessageTransformer that converts nav messages to <system> tags
- Track last submitted URL and tab index
- Auto-insert navigation message when URL/tab changes on user submit
- Navigation message shows favicon + page title in UI
- LLM receives: <system>Navigated to [title] (tab X): [url]</system>
2025-10-06 13:49:28 +02:00
Mario Zechner
05dfaa11a8 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
2025-10-06 13:45:08 +02:00
Mario Zechner
cf6b3466f8 Remove refresh. 2025-10-06 12:55:41 +02:00
Mario Zechner
e5cf25a267 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
2025-10-06 12:47:52 +02:00
Mario Zechner
c18923a8c5 Clean-up 2025-10-06 01:41:00 +02:00
Mario Zechner
9a4e4b086e Remove old plan.md 2025-10-06 01:33:57 +02:00
Mario Zechner
12910a5940 Remove todos folder. 2025-10-05 23:39:37 +02:00
Mario Zechner
53e339ddb8 Enable thinking selector in MessageEditor
- Import Select component from mini-lit and Brain icon from lucide
- Add thinkingLevel property to track current thinking level (off/minimal/low/medium/high)
- Enable showThinkingSelector (was disabled before)
- Add onThinkingChange callback for thinking level changes
- Render Select component with thinking level options when model supports reasoning
- Position thinking selector on left side next to attachment button
- Add i18n translations for Off/Minimal/Low/Medium/High in English and German
- Rename showThinking → showThinkingSelector in AgentInterface and ChatPanel for consistency
- Remove showDebugToggle property from AgentInterface (unused)
- Clean up browser-javascript tool output message (remove CSP note)
2025-10-05 23:32:30 +02:00
Mario Zechner
414a4eb8fd Bump version to 0.5.44 2025-10-05 23:00:59 +02:00
Mario Zechner
0496651308 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)
2025-10-05 23:00:36 +02:00
Mario Zechner
66f092c0c6 Proxy package 2025-10-05 19:02:15 +02:00
Mario Zechner
aaea0f4600 Integrate JailJS for CSP-restricted execution in browser extension
Major changes:
- Migrate browser-extension to use web-ui package (85% code reduction)
- Add JailJS content script with ES6+ transform support
- Expose DOM constructors (Event, KeyboardEvent, etc.) to JailJS
- Support top-level await by wrapping code in async IIFE
- Add returnFile() support in JailJS execution
- Refactor KeyStore into pluggable storage-adapter pattern
- Make ChatPanel configurable with sandboxUrlProvider and additionalTools
- Update jailjs to 0.1.1

Files deleted (33 duplicate files):
- All browser-extension components, dialogs, state, tools, utils
- Now using web-ui versions via @mariozechner/pi-web-ui

Files added:
- packages/browser-extension/src/content.ts (JailJS content script)
- packages/web-ui/src/state/storage-adapter.ts
- packages/web-ui/src/state/key-store.ts

Browser extension now has only 5 source files (down from 38).
2025-10-05 16:58:31 +02:00
Mario Zechner
f2eecb78d2 web-ui package 2025-10-05 13:30:08 +02:00
Mario Zechner
7159c9734e Update web-ui example to use javascript-repl instead of calculate/getCurrentTime tools 2025-10-04 21:52:30 +02:00
Mario Zechner
9d6267a915 Fix javascript-repl renderer to use console-block component 2025-10-04 21:44:23 +02:00
Mario Zechner
8212623af0 Add JavaScript REPL tool to web-ui package
- Created javascript-repl.ts tool with SandboxedIframe for code execution
- Integrated into ChatPanel replacing calculate and getCurrentTime tools
- REPL provides full browser API access with external library support
- Auto-registers renderer for tool output display
- Uses srcdoc instead of sandbox.html (no CSP restrictions in web apps)
2025-10-04 19:12:38 +02:00
Mario Zechner
0af33ce79a Fix race condition in web-ui SandboxedIframe
Fixed loadContent() and execute() to set srcdoc at the correct time:
- loadContent(): Now sets srcdoc after creating iframe (was missing entirely)
- execute(): Now sets srcdoc after setting up message listeners and creating iframe (was setting before iframe existed)

This prevents missing postMessage events from the sandboxed iframe.
2025-10-04 19:09:17 +02:00
Mario Zechner
5520963841 Better detection of eval/<script> capability on current site wrt CSP 2025-10-04 01:13:07 +02:00
Mario Zechner
3481aeec26 Make browser_javascript tool abortable 2025-10-04 00:45:16 +02:00
Mario Zechner
c2427d375c Fix browser javascript tool wrt navigation. Needs to be its own tool call as execution context gets smoked. 2025-10-03 23:48:15 +02:00
Mario Zechner
99983af597 Fix lints. 2025-10-03 23:21:59 +02:00
Mario Zechner
6d046236bf Fix HtmlArtifacts no loading/updating 2025-10-03 11:35:12 +02:00
Mario Zechner
79dd23b6da Restructuring and refactoring 2025-10-03 02:15:37 +02:00
Mario Zechner
3331701e7e Clean-up 2025-10-02 02:48:25 +02:00
Mario Zechner
6a355d7a7e Fix KeyStore for Firefox. 2025-10-02 02:45:38 +02:00
Mario Zechner
af426d2682 Fix sandboxed iframe. 2025-10-02 02:41:15 +02:00
Mario Zechner
faefc63309 iframe and Firefox fixes 2025-10-02 02:15:33 +02:00
Mario Zechner
4b0703cd5b Artifacts tool, V1, htmlartifact broken due to CSP 2025-10-01 23:32:14 +02:00
Mario Zechner
51f5448a5c Remove tool calls for which there are no results in subsequent user messages. 2025-10-01 22:18:30 +02:00
Mario Zechner
0e932a97df More browser extension work, disable ajv validation in browser extensions, it uses eval/new Function, which is not allowed in manifest v3 extensions 2025-10-01 20:30:49 +02:00
Mario Zechner
fc1ef04b6d UX fixes 2025-10-01 18:35:02 +02:00
Mario Zechner
d0b2d47b4a More browser extension work. Old interface fully ported. Direct transport. Small UX fixes. 2025-10-01 18:27:40 +02:00
Mario Zechner
b3a7b35ec5 Port PDF/Office support, message editor, overlays, key setter 2025-10-01 17:31:13 +02:00
Mario Zechner
b67c10dfb1 feat: add cross-browser extension with AI reading assistant
- Create Pi Reader browser extension for Chrome/Firefox
- Chrome uses Side Panel API, Firefox uses Sidebar Action API
- Supports both browsers with separate manifests and unified codebase
- Built with mini-lit components and Tailwind CSS v4
- Features model selection dialog with Ollama support
- Hot reload development server watches both browser builds
- Add useDefineForClassFields: false to fix LitElement reactivity
2025-10-01 04:33:56 +02:00
Mario Zechner
c1185c7b95 chore: bump version to 0.5.43 2025-09-19 01:49:46 +02:00
Mario Zechner
f55985f633 Fix GPT-5 no-reasoning mode. Somewhat. There's no real off-switch ... 2025-09-19 01:45:00 +02:00
Mario Zechner
0f7ed33ba5 chore: bump version to 0.5.42 2025-09-19 00:14:23 +02:00
Mario Zechner
9e86079386 Fix block indexing in Google provider impl 2025-09-19 00:10:43 +02:00
Mario Zechner
2296dc4052 refactor(ai): improve error handling and stop reason types
- Add 'aborted' as a distinct stop reason separate from 'error'
- Change AssistantMessage.error to errorMessage for clarity
- Update error event to include reason field ('error' | 'aborted')
- Map provider-specific safety/refusal reasons to 'error' stop reason
- Reorganize utility functions into utils/ directory
- Rename agent.ts to agent-loop.ts for better clarity
- Fix error handling in all providers to properly distinguish abort from error
2025-09-18 19:57:13 +02:00
Mario Zechner
293a6e878d chore: bump version to 0.5.41 2025-09-18 11:18:02 +02:00
Mario Zechner
b6af05bbf6 fix(ai): correct streaming event documentation and API methods 2025-09-18 11:17:33 +02:00
Mario Zechner
c9d735bbbd Clean-up 2025-09-16 12:27:30 +02:00
Mario Zechner
9c921049a6 chore: bump version to 0.5.40 2025-09-16 12:24:00 +02:00
Mario Zechner
39c626b6c9 feat(ai): add partial JSON parsing for streaming tool calls
- Added partial-json package for parsing incomplete JSON during streaming
- Tool call arguments now contain partially parsed JSON during toolcall_delta events
- Enables progressive UI updates (e.g., showing file paths before content is complete)
- Arguments are always valid objects (minimum empty {}), never undefined
- Full validation still occurs at toolcall_end when arguments are complete
- Updated all providers (Anthropic, OpenAI Completions/Responses) to use parseStreamingJson
- Added comprehensive documentation and examples in README
- Added test to verify arguments are always defined during streaming
2025-09-16 12:23:34 +02:00
Mario Zechner
197259c88a Fix NodeJS compat 2025-09-16 02:19:47 +02:00
Mario Zechner
e2d23a5abb Update AI models and index exports 2025-09-16 01:29:44 +02:00
Mario Zechner
365b9ec390 chore: bump version to 0.5.36 2025-09-16 01:11:28 +02:00
Mario Zechner
e8370436d7 Replace Zod with TypeBox for schema validation
- Switch from Zod to TypeBox for tool parameter schemas
- TypeBox schemas can be serialized/deserialized as JSON
- Use AJV for runtime validation instead of Zod's parse
- Add StringEnum helper for Google API compatibility (avoids anyOf/const patterns)
- Export Type and Static from main package for convenience
- Update all tests and documentation to reflect TypeBox usage
2025-09-16 01:10:40 +02:00
Mario Zechner
f5ac1ef521 chore: bump version to 0.5.35 2025-09-15 20:32:50 +02:00
Mario Zechner
5f7a50deef Make stream function configurable in agent 2025-09-15 20:31:53 +02:00