Commit graph

36 commits

Author SHA1 Message Date
Mario Zechner
4079bced36 Fix TypeScript errors and export UserMessageWithAttachments
- Export UserMessageWithAttachments type from web-ui index
- Remove unused i18n import from extract-document tool
- Update models.generated.ts (model order changes from API)

This fixes type errors when sitegeist uses custom user message renderer
2025-10-12 17:09:14 +02:00
Mario Zechner
f93e72a805 Committing manually like the monkey I am 2025-10-12 02:59:46 +02:00
Mario Zechner
8a96741441 Revert: Fix extension context detection - original logic was correct
The negated approach broke browser_script which runs in page context.
browser_script injects into web pages (http://, https://) where
chrome.runtime.sendMessage doesn't work. The original whitelist
approach correctly identifies extension contexts only.

The real issue with artifacts in sandbox iframes needs a different fix.
2025-10-11 19:32:33 +02:00
Mario Zechner
91c1dc6475 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)
2025-10-08 17:49:56 +02:00
Mario Zechner
9a57aa7e1a Prevent default and stop propagation when clicking artifact pill
This prevents the collapsible header from toggling when the pill is clicked.
2025-10-08 14:17:04 +02:00
Mario Zechner
58b9c36268 Make renderHeader and renderCollapsibleHeader accept string | TemplateResult
- Update renderHeader and renderCollapsibleHeader in renderer-registry.ts to accept `text: string | TemplateResult`
- Remove duplicated renderCollapsibleHeaderWithPill helper in artifacts-tool-renderer.ts
- Update all artifact renderer calls to use renderHeaderWithPill() inline
- Remove all separate pill rendering below headers

This allows artifact pills to be rendered inline with header text without code duplication.
2025-10-08 14:12:02 +02:00
Mario Zechner
33145c5f24 Make mini-lit a peer dependency in pi-web-ui
- Move mini-lit from dependencies to peerDependencies
- Keep in devDependencies for development
- Prevents bundlers from including mini-lit when consuming pi-web-ui
- Consumer (sitegeist) provides mini-lit, esbuild bundles it once
- Fixes duplicate mini-lit bundling issue permanently
2025-10-06 18:59:08 +02:00
Mario Zechner
9d6267a915 Fix javascript-repl renderer to use console-block component 2025-10-04 21:44:23 +02:00
Mario Zechner
99983af597 Fix lints. 2025-10-03 23:21:59 +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
f55985f633 Fix GPT-5 no-reasoning mode. Somewhat. There's no real off-switch ... 2025-09-19 01:45:00 +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
c9d735bbbd Clean-up 2025-09-16 12:27:30 +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
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
Mario Zechner
35fe8f21e9 feat(ai): Implement Zod-based tool validation and improve Agent API
- Replace JSON Schema with Zod schemas for tool parameter definitions
- Add runtime validation for all tool calls at provider level
- Create shared validation module with detailed error formatting
- Update Agent API with comprehensive event system
- Add agent tests with calculator tool for multi-turn execution
- Add abort test to verify proper handling of aborted requests
- Update documentation with detailed event flow examples
- Rename generate.ts to stream.ts for clarity
2025-09-09 14:58:54 +02:00
Mario Zechner
d073953ef7 feat(ai): Add zAI provider support
- Add 'zai' as a KnownProvider type
- Add ZAI_API_KEY environment variable mapping
- Generate 4 zAI models (glm-4.5-air, glm-4.5v, etc.) using anthropic-messages API
- Add comprehensive test coverage for zAI provider in generate.test.ts and empty.test.ts
- Models support reasoning/thinking capabilities and tool calling
2025-09-07 00:09:15 +02:00
Mario Zechner
6679a83b32 fix(ai): Sanitize tool call IDs for Anthropic API compatibility
- Anthropic API requires tool call IDs to match pattern ^[a-zA-Z0-9_-]+$
- OpenAI Responses API generates IDs with pipe character (|) which breaks Anthropic
- Added sanitizeToolCallId() to replace invalid characters with underscores
- Fixes cross-provider handoffs from OpenAI Responses to Anthropic
- Added test to verify the fix works
2025-09-04 05:17:08 +02:00
Mario Zechner
4cee070bdd refactor(ai): Simplify API with new streaming interface and model management
- Replace createLLM with getModel/getModels/getProviders functions
- Rename PROVIDERS to MODELS (internal only, not exposed)
- Add streamSimple/completeSimple for unified reasoning interface
- Update README with new API examples and comprehensive documentation
- Remove model registration (models are now fixed from build time)
- Add proper TypeScript typing for provider-specific options
- Document context serialization, cross-provider handoffs, and browser usage
2025-09-03 01:25:19 +02:00
Mario Zechner
66cefb236e Massive refactor of API
- Switch to function based API
- Anthropic SDK style async generator
- Fully typed with escape hatches for custom models
2025-09-02 23:59:36 +02:00
Mario Zechner
0fbb0921bb feat(ai): Add gpt-5-chat-latest model to generated models
- Added hardcoded gpt-5-chat-latest model since it's not in models.dev yet
- Model has image input support and proper pricing configuration
2025-09-02 01:32:26 +02:00
Mario Zechner
efaa5cdb39 feat(ai): Fetch Anthropic, Google, and OpenAI models from models.dev instead of OpenRouter
- Updated generate-models.ts to fetch these providers directly from models.dev API
- OpenRouter now only used for xAI and other third-party providers
- Fixed test model IDs to match new model names from models.dev
- Removed unused import from google.ts
2025-09-02 01:18:59 +02:00
Mario Zechner
32bede3352 docs(ai): Add browser usage section to README
- Document browser support and API key requirements
- Add security warning about exposing keys in frontend
- Keep documentation concise and practical
2025-09-01 22:09:24 +02:00
Mario Zechner
cf35215686 fix(ai): Fix browser compatibility for Anthropic OAuth tokens
- Check if process exists before modifying process.env
- Prevents errors in browser environments
- Maintains OAuth token functionality in Node.js
2025-09-01 21:46:22 +02:00
Mario Zechner
80da49cd40 docs(ai): Update README for new content blocks API
- Add API changes section explaining v0.5.15+ changes
- Update Quick Start example to show content array usage
- Update Tool Calling example to filter tool calls from content blocks
- Update Streaming example to use new onEvent callback
- Fix model IDs in provider-specific examples
2025-08-31 22:17:17 +02:00
Mario Zechner
cff766d3e2 fix(ai): Fix OpenAI Responses provider multi-turn conversation support
- Added contentSignature tracking for assistant messages
- Fixed message format in convertToResponsesFormat (output_text instead of input_text)
- Properly preserve message IDs for multi-turn conversations
- Added proper ResponseOutputMessage type satisfaction
- Updated tests to cover more providers and multi-turn scenarios
2025-08-30 22:55:29 +02:00
Mario Zechner
889208dccd docs(ai): Fix model names in README examples
- Changed gpt-4o-mini to gpt-5-mini in examples to match actual model names
- Minor formatting fixes
2025-08-30 21:48:17 +02:00
Mario Zechner
dae40167a3 docs(ai): Improve README with model discovery and capabilities documentation
- Added note that library only includes tool-calling capable models
- Added Model Discovery section showing how to enumerate models
- Added examples for finding models with specific capabilities
- Added cache read/write costs to model capabilities display
- Clarified that models are auto-fetched from APIs at build time
2025-08-30 21:46:54 +02:00
Mario Zechner
d46a98ec10 feat(ai): Rename package to @mariozechner/pi-ai and improve documentation
- Changed package name from @mariozechner/ai to @mariozechner/pi-ai
- Fixed generate-models.ts to fetch from models.dev API instead of local file
- Completely rewrote README with practical examples:
  - Image input with base64 encoding
  - Proper tool calling with context management
  - Streaming with completion indicators
  - Abort signal usage
  - Provider-specific options (reasoning/thinking)
  - Custom model definitions for local/self-hosted LLMs
  - Environment variables explanation
- Bumped version to 0.5.9 and published
2025-08-30 21:41:22 +02:00
Mario Zechner
f9d688d577 refactor(ai): Update LLM implementations to use Model objects
- LLM constructors now take Model objects instead of string IDs
- Added provider field to AssistantMessage interface
- Updated getModel function with type-safe model ID autocomplete
- Fixed Anthropic model ID mapping for proper API aliases
- Added baseUrl to Model interface for provider-specific endpoints
- Updated all tests to use getModel for model instantiation
- Removed deprecated models.json in favor of generated models
2025-08-30 00:21:03 +02:00
Mario Zechner
d61d09b88d fix(ai): Deduplicate models and add Anthropic aliases
- Add proper Anthropic model aliases (claude-opus-4-1, claude-sonnet-4-0, etc.)
- Deduplicate models when same ID appears in both models.dev and OpenRouter
- models.dev takes priority over OpenRouter for duplicate IDs
- Fix test to use correct claude-3-5-haiku-latest alias
- Reduces Anthropic models from 11 to 10 (removed duplicate)
2025-08-29 23:34:01 +02:00
Mario Zechner
9c3f32b91e feat(ai): Add models.generated.ts with 181 tool-capable models
- Generated from OpenRouter API and models.dev
- Includes models from Google, OpenAI, Anthropic, xAI, Groq, Cerebras, OpenRouter
- Provides type-safe model selection with autocomplete
2025-08-29 23:20:53 +02:00