Commit graph

107 commits

Author SHA1 Message Date
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
21750c230a More clean-up 2025-09-03 00:01:56 +02:00
Mario Zechner
acf0f5aee2 Clean-up 2025-09-03 00:01:32 +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
004de3c9d0 feat(ai): Add new streaming generate API with AsyncIterable interface
- Implement QueuedGenerateStream class that extends AsyncIterable with finalMessage() method
- Add new types: GenerateStream, GenerateOptions, GenerateOptionsUnified, GenerateFunction
- Create generateAnthropic function-based implementation replacing class-based approach
- Add comprehensive test suite for the new generate API
- Support streaming events with text, thinking, and tool call deltas
- Map ReasoningEffort to provider-specific options
- Include apiKey in options instead of constructor parameter
2025-09-02 18:07:46 +02:00
Mario Zechner
be07c08a75 test(ai): Add empty assistant message tests
- Test providers handling empty assistant messages in conversation flow
- Pattern: user message -> empty assistant -> user message
- All providers handle empty assistant messages gracefully
- Tests ensure providers can continue conversation after empty response
2025-09-02 02:10:07 +02:00
Mario Zechner
0ac05a0676 test(ai): Add empty message tests for all providers
- Test handling of empty content arrays
- Test handling of empty string content
- Test handling of whitespace-only content
- All providers handle these edge cases gracefully
2025-09-02 02:03:06 +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
f1c3d44602 chore: Bump version to 0.5.25 2025-09-02 00:20:26 +02:00
Mario Zechner
2cfd8ff3c3 fix(ai): Use API type instead of model for message compatibility checks
- Add getApi() method to all providers to identify the API type
- Add api field to AssistantMessage to track which API generated it
- Update transformMessages to check API compatibility instead of model
- Fixes issue where OpenAI Responses API failed when switching models
- Preserves thinking blocks and signatures when staying within same API
2025-09-02 00:20:06 +02:00
Mario Zechner
3007b7a5ac chore: Bump version to 0.5.24 2025-09-01 22:09:47 +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
14d93ca8c6 chore: Bump version to 0.5.23 2025-09-01 22:03:09 +02:00
Mario Zechner
a62231987c fix(ai): Add anthropic-dangerous-direct-browser-access header
- Required header for browser-based access to Anthropic API
- Added to both OAuth and regular API key authentication
- Ensures full browser compatibility
2025-09-01 22:02:50 +02:00
Mario Zechner
8324cd4192 chore: Bump version to 0.5.22 2025-09-01 21:56:12 +02:00
Mario Zechner
da43e625f8 fix(ai): Add dangerouslyAllowBrowser flag for Anthropic client
- Enables browser support for Anthropic SDK
- Required for browser-based applications using the AI library
2025-09-01 21:55:52 +02:00
Mario Zechner
3caa3af8fc chore: Bump version to 0.5.21 2025-09-01 21:46:41 +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
add1b76b6c chore: Bump version to 0.5.20 2025-09-01 18:44:15 +02:00
Mario Zechner
46b5800d36 feat(ai): Add cross-provider message handoff support
- Add transformMessages utility to handle cross-provider compatibility
- Convert thinking blocks to <thinking> tagged text when switching providers
- Preserve native thinking blocks when staying with same provider/model
- Add comprehensive handoff tests verifying all provider combinations
- Fix OpenAI Completions to return partial results on abort
- Update tool call ID format for Anthropic compatibility
- Document cross-provider handoff capabilities in README
2025-09-01 18:43:49 +02:00
Mario Zechner
bf1f410c2b refactor(ai): Update API to support partial results on abort
- Anthropic, Google, and OpenAI Responses providers now return partial results when aborted
- Restructured streaming to accumulate content blocks incrementally
- Prevents submission of thinking/toolCall blocks from aborted completions in multi-turn conversations
- Makes UI development easier by providing partial content even when requests are interrupted
2025-09-01 01:57:45 +02:00
Mario Zechner
5d5cd7955b chore: Bump version to 0.5.19 2025-08-31 23:56:58 +02:00
Mario Zechner
7db3068cee fix(ai): Fix OpenAI Responses provider import order and cost calculation 2025-08-31 23:56:39 +02:00
Mario Zechner
f87ac359bb chore: Bump version to 0.5.18 2025-08-31 23:49:29 +02:00
Mario Zechner
8430b91e59 fix(build): Improve source maps for better debugging
- Add inlineSources: true to embed TypeScript source in source maps
- Keeps source maps in separate files (inlineSourceMap: false)
- Enables proper debugging and breakpoints when using packages from npm
2025-08-31 23:49:09 +02:00
Mario Zechner
683263ba27 chore: Bump version to 0.5.17 2025-08-31 23:09:35 +02:00
Mario Zechner
a132b8140c feat(ai): Add start event emission to all providers
- Emit start event with model and provider info after creating stream
- Add abort signal tests for all providers
- Update README abort signal section to reflect non-throwing API
- Fix model references in README examples
2025-08-31 23:09:14 +02:00
Mario Zechner
8d4edf6458 docs(ai): Add all event types to streaming example
- Add 'start' event with model/provider info
- Add 'done' event with stop reason and usage stats
- Add 'error' event handling
- Show more detailed event data in examples
2025-08-31 22:38:13 +02:00
Mario Zechner
8cca5597e4 docs(ai): Remove 'now' language and fix model IDs in README 2025-08-31 22:36:58 +02:00
Mario Zechner
c960d36da1 docs(ai): Remove old API reference from README 2025-08-31 22:35:23 +02:00
Mario Zechner
8f4e96f207 chore: Bump version to 0.5.16 2025-08-31 22:17:35 +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
0f2eaa70e9 chore: Bump version to 0.5.15 2025-08-31 22:11:50 +02:00
Mario Zechner
ee4c131873 fix(ai): Fix OpenAI Responses provider multi-turn conversation support
- Collect complete output items during streaming instead of building blocks incrementally
- Handle reasoning summary parts with proper newline separation
- Support refusal content in message outputs
- Preserve full reasoning items and message IDs for multi-turn resubmission
- Emit proper streaming events for text and thinking deltas
2025-08-31 22:11:08 +02:00
Mario Zechner
a72e6d08d4 refactor(ai): Update OpenAI Completions provider to new content block API 2025-08-31 20:59:57 +02:00
Mario Zechner
7c8cdacc09 refactor(ai): Simplify Google provider with cleaner block handling 2025-08-31 20:31:08 +02:00
Mario Zechner
f29752ac82 refactor(ai): Update API to support multiple thinking and text blocks
BREAKING CHANGE: AssistantMessage now uses content array instead of separate fields
- Changed AssistantMessage.content from string to array of content blocks
- Removed separate thinking, toolCalls, and signature fields
- Content blocks can be TextContent, ThinkingContent, or ToolCall types
- Updated streaming events to include start/end events for text and thinking
- Fixed multiTurn test to handle new content structure

Note: Currently only Anthropic provider is updated to work with new API
Other providers need to be updated to match the new interface
2025-08-31 19:32:12 +02:00
Mario Zechner
f8a81b9453 test(ai): Add image input test for Anthropic Haiku 3.5
- Added image handling test for Claude 3.5 Haiku
- Ensures vision capabilities are properly tested
2025-08-30 23:00:30 +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
2e90f8f8bc feat(ai): Enable browser support for OpenAI providers
- Added dangerouslyAllowBrowser: true to OpenAI client initialization
- Allows usage of the library in browser environments
- Applies to both OpenAICompletionsLLM and OpenAIResponsesLLM
2025-08-30 22:29:14 +02:00
Mario Zechner
444580fd2f docs: Update project description with AI package information
- Added @mariozechner/pi-ai package to the structure
- Updated features to include unified LLM API
- Expanded supported providers list
- Updated tech stack with multiple SDKs
- Added architecture details for AI package
- Updated version numbers to current 0.5.12
- Added testing information for AI package (Vitest)
- Included all packages in build order example
2025-08-30 21:56:40 +02:00
Mario Zechner
8b12312d72 chore: Mark AI package implementation task as complete
- Moved completed AI package implementation task to done folder
- Task successfully implemented the unified AI API (@mariozechner/pi-ai)
- Package renamed, documentation improved, and published as v0.5.12
2025-08-30 21:53:23 +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
796e48b80e feat(ai): Add image input tests for vision-capable models
- Added image tests to OpenAI Completions (gpt-4o-mini)
- Added image tests to Anthropic (claude-sonnet-4-0)
- Added image tests to Google (gemini-2.5-flash)
- Tests verify models can process and describe the red circle test image
2025-08-30 18:37:17 +02:00
Mario Zechner
4ac0c6ea28 docs(ai): Simplify ImageContent interface to base64-only approach
- Change ImageContent to simple { type, data, mimeType } structure
- Remove URL and file path support from core interface
- Simplify provider converters to work with base64 data only
- Update validation and implementation considerations
- Clarify that preprocessing is user's responsibility
2025-08-30 18:12:36 +02:00
Mario Zechner
0b50c3f36d docs(ai): Add comprehensive image input documentation for all LLM providers
- Document image support for Anthropic, Google GenAI, OpenAI APIs
- Include format requirements, size limits, and API examples
- Propose unified abstraction layer for cross-provider image handling
- Add implementation examples for format conversion and validation
2025-08-30 18:07:35 +02:00
Mario Zechner
545d04fc5c fix(ai): Fix OpenAI completions store field type issue
- Cast params to any for store field assignment
- Maintains compatibility with providers that don't support store field
2025-08-30 01:08:08 +02:00