Commit Graph

43 Commits

  • fix(ai): clean up openai-codex models and token limits
    - Remove model aliases (gpt-5, gpt-5-mini, gpt-5-nano, codex-mini-latest, gpt-5-codex, gpt-5.1-codex, gpt-5.1-chat-latest)
    - Fix context window from 400k to 272k tokens to match Codex CLI defaults
    - Keep maxTokens at 128k (original value)
    - Simplify reasoning effort clamping
    
    closes #536
  • fix: add accurate pricing for openai-codex OAuth models (#501)
    Previously all openai-codex models had pricing set to 0, causing the
    TUI to always show $0.00 for cost tracking.
    
    Updated pricing based on OpenAI Standard tier rates:
    - gpt-5.2/gpt-5.2-codex: $1.75/$14.00 per 1M tokens
    - gpt-5.1/gpt-5.1-codex/gpt-5.1-codex-max: $1.25/$10.00 per 1M tokens
    - gpt-5/gpt-5-codex: $1.25/$10.00 per 1M tokens
    - codex-mini-latest: $1.50/$6.00 per 1M tokens
    - gpt-5-mini/gpt-5.1-codex-mini/gpt-5-codex-mini: $0.25/$2.00 per 1M tokens
    - gpt-5-nano: $0.05/$0.40 per 1M tokens
    
    Source: https://platform.openai.com/docs/pricing
  • fix: clean up Codex thinking level handling
    - Remove per-thinking-level model variants (gpt-5.2-codex-high, etc.)
    - Remove thinkingLevels from Model type
    - Provider clamps reasoning effort internally
    - Omit reasoning field when thinking is off
    
    fixes #472
  • Add Vertex AI provider with ADC support
    - Implement google-vertex provider in packages/ai
    - Support ADC (Application Default Credentials) via @google/generative-ai
    - Add Gemini model catalog for Vertex AI
    - Update packages/coding-agent to handle google-vertex provider
  • Migrate zai provider from Anthropic to OpenAI-compatible API
    - Migrate glm-4.5, glm-4.5-air, glm-4.5-flash, glm-4.6, glm-4.7 from anthropic-messages to openai-completions API
    - Updated baseUrl from https://api.z.ai/api/anthropic to https://api.z.ai/api/coding/paas/v4
    - Added compat setting to disable developer role for zai models
    - Filter empty text blocks in openai-completions to avoid zai API validation errors
    - Fixed zai provider tests to use OpenAI-style options (reasoningEffort)
  • Add Gemini 3 preview models to google-gemini-cli provider
    - Add gemini-3-pro-preview and gemini-3-flash-preview to Cloud Code Assist
    - Handle thinkingLevel config for Gemini 3 (vs thinkingBudget for Gemini 2.x)
    - Gemini 3 Pro: LOW/HIGH levels only
    - Gemini 3 Flash: all four levels (MINIMAL/LOW/MEDIUM/HIGH)
  • Add Google Gemini CLI and Antigravity OAuth providers
    - Add google-gemini-cli provider: free Gemini 2.0/2.5 via Cloud Code Assist
    - Add google-antigravity provider: free Gemini 3, Claude, GPT-OSS via sandbox
    - Move OAuth infrastructure from coding-agent to ai package
    - Fix thinking signature handling for cross-model handoff
    - Fix OpenAI message ID length limit (max 64 chars)
    - Add GitHub Copilot overflow pattern detection
    - Add OAuth provider tests for context overflow and streaming
  • feat(ai): add Google Cloud Code Assist provider
    - Add new API type 'google-cloud-code-assist' for Gemini CLI / Antigravity auth
    - Extract shared Google utilities to google-shared.ts
    - Implement streaming provider for Cloud Code Assist endpoint
    - Add 7 models: gemini-3-pro-high/low, gemini-3-flash, claude-sonnet/opus, gpt-oss
    
    Models use OAuth authentication and have sh cost (uses Google account quota).
    OAuth flow will be implemented in coding-agent in a follow-up.
  • GitHub Copilot: auto-enable models, fix gpt-5 API, normalize tool call IDs
    - Auto-enable all models after /login via POST /models/{model}/policy
    - Use openai-responses API for gpt-5/o3/o4 models (not accessible via completions)
    - Normalize tool call IDs when switching between github-copilot models with different APIs
      (fixes #198: openai-responses generates 450+ char IDs with special chars that break other models)
    - Update README with streamlined GitHub Copilot docs
  • Add GitHub Copilot support (#191)
    - OAuth login for GitHub Copilot via /login command
    - Support for github.com and GitHub Enterprise
    - Models sourced from models.dev (Claude, GPT, Gemini, Grok, etc.)
    - Dynamic base URL from token's proxy-ep field
    - Use vscode-chat integration ID for API compatibility
    - Documentation for model enablement at github.com/settings/copilot/features
    
    Co-authored-by: cau1k <cau1k@users.noreply.github.com>
  • feat: added filter for generate-models and regenerated
    - blacklisted gpt-4o-2024-08-06, gpt-4o-2024-11-20, gpt-3.5-turbo-0613,
    gpt-4, gpt-4-0613
  • feat: models.dev in generate models - too many deprecated models
    could have opted for a whitelist but we'll just fetch from the copilot
    /models endpoint
  • feat: initial impl
    - add GitHub Copilot model discovery (env token fallback, headers,
    compat) plus fallback list and quoted provider keys in generated map
    - surface Copilot provider end-to-end (KnownProvider/default, env+OAuth
    token refresh/save, enterprise base URL swap, available only when
    creds/env exist)
    - tweak interactive OAuth UI to render instruction text and prompt
    placeholders
    
    gpt-5.2-high took about 35 minutes. It had a lot of trouble with `npm
    check`  and went off on a "let's adjust every tsconfig" side quest.
    Device code flow works, but the ai/scripts/generate-models.ts impl is
    wrong as models from months ago are missing and only those deprecated
    are accessible in the /models picker.
  • Add Mistral as AI provider
    - Add Mistral to KnownProvider type and model generation
    - Implement Mistral-specific compat handling in openai-completions:
      - requiresToolResultName: tool results need name field
      - requiresAssistantAfterToolResult: synthetic assistant message between tool/user
      - requiresThinkingAsText: thinking blocks as <thinking> text
      - requiresMistralToolIds: tool IDs must be exactly 9 alphanumeric chars
    - Add MISTRAL_API_KEY environment variable support
    - Add Mistral tests across all test files
    - Update documentation (README, CHANGELOG) for both ai and coding-agent packages
    - Remove client IDs from gemini.md, reference upstream source instead
    
    Closes #165
  • mom: add centralized logging, usage tracking, and improve prompt caching
    Major improvements to mom's logging and cost reporting:
    
    Centralized Logging System:
    - Add src/log.ts with type-safe logging functions
    - Colored console output (green=user, yellow=mom, dim=details)
    - Consistent format: [HH:MM:SS] [context] message
    - Replace scattered console.log/error calls throughout codebase
    
    Usage Tracking & Cost Reporting:
    - Track tokens (input, output, cache read/write) and costs per run
    - Display summary at end of each run in console and Slack thread
    - Example: 💰 Usage: 12,543 in + 847 out (5,234 cache read) = $0.0234
    
    Prompt Caching Optimization:
    - Move recent messages from system prompt to user message
    - System prompt now mostly static (only changes with memory files)
    - Enables effective use of Anthropic's prompt caching
    - Significantly reduces costs on subsequent requests
    
    Model & Cost Improvements:
    - Switch from Claude Opus 4.5 to Sonnet 4.5 (~40% cost reduction)
    - Fix Claude Opus 4.5 cache pricing in ai package (was 3x too expensive)
    - Add manual override in generate-models.ts until upstream fix merges
    - Submitted PR to models.dev: https://github.com/sst/models.dev/pull/439
    
    UI/UX Improvements:
    - Extract actual text from tool results instead of JSON wrapper
    - Cleaner Slack thread formatting with duration and labels
    - Tool args formatting shows paths with offset:limit notation
    - Add chalk for colored terminal output
    
    Dependencies:
    - Add chalk package for terminal colors
  • Add ANSI-aware word wrapping to TUI components
    - Created shared wrapTextWithAnsi() function in utils.ts
    - Handles word-based wrapping while preserving ANSI escape codes
    - Properly tracks active ANSI codes across wrapped lines
    - Supports multi-byte characters (emoji, surrogate pairs)
    - Updated Markdown and Text components to use shared wrapping
    - Removed duplicate wrapping logic (158 lines total)
  • feat(coding-agent): add OAuth authentication for Claude Pro/Max
    - Add /login and /logout commands for OAuth flow
    - OAuth tokens stored in ~/.pi/agent/oauth.json with 0600 permissions
    - Auto-refresh tokens when expired (5min buffer)
    - Priority: OAuth > ANTHROPIC_OAUTH_TOKEN env > ANTHROPIC_API_KEY env
    - Fix model selector async loading and re-render
    - Add bracketed paste support to Input component for long codes
    - Update README.md with OAuth documentation
    - Add implementation docs and testing checklist
  • 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
  • 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
  • Massive refactor of API
    - Switch to function based API
    - Anthropic SDK style async generator
    - Fully typed with escape hatches for custom models
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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)
  • refactor(ai): Implement unified model system with type-safe createLLM
    - Add Model interface to types.ts with normalized structure
    - Create type-safe generic createLLM function with provider-specific model constraints
    - Generate models from OpenRouter API and models.dev data
    - Strip provider prefixes for direct providers (google, openai, anthropic, xai)
    - Keep full model IDs for OpenRouter-proxied models
    - Clean separation: types.ts (Model interface), models.ts (factory logic), models.generated.ts (data)
    - Remove old model scripts and unused dependencies
    - Rename GeminiLLM to GoogleLLM for consistency
    - Add tests for new providers (xAI, Groq, Cerebras, OpenRouter)
    - Support 181 tool-capable models across 7 providers with full type safety
  • feat(ai): Add auto-generated TypeScript models with factory function
    - Generate models.generated.ts from models.json with proper types
    - Categorize providers: OpenAI (Responses), OpenAI-compatible, Anthropic, Gemini
    - Create createLLM() factory with TypeScript overloads for type safety
    - Auto-detect base URLs and environment variables for providers
    - Support 353 models across 39 providers with full autocompletion
    - Exclude generated file from git (rebuilt on npm build)