Skip to content

feat: add Mistral, Codex, Chrome on-device providers; fix Gemini/DeepSeek streaming and reasoning - #1393

Closed
oakimov wants to merge 37 commits into
musistudio:mainfrom
oakimov:feat/fork-contributions
Closed

feat: add Mistral, Codex, Chrome on-device providers; fix Gemini/DeepSeek streaming and reasoning#1393
oakimov wants to merge 37 commits into
musistudio:mainfrom
oakimov:feat/fork-contributions

Conversation

@oakimov

@oakimov oakimov commented May 12, 2026

Copy link
Copy Markdown

Summary

This PR consolidates 30 commits from a downstream fork, bringing new provider support, architectural refactoring, deployment tooling, and reliability improvements.

96 files changed, +10,774 / -2,929 lines (excluding fork-specific README and TODO).


New Providers

Mistral Transformer (packages/core/src/transformer/mistral.transformer.ts)

  • Direct Mistral API support with reasoning/thinking model detection
  • Extracted utility module (packages/core/src/utils/mistral.util.ts) for transformation logic decoupling
  • Strips thinking blocks from message payloads for reasoning models
  • Model-specific reasoning parameter handling

Codex Transformer (packages/core/src/transformer/codex.transformer.ts)

  • Full Codex API integration with streaming support
  • OAuth authentication flow (packages/server/src/routes/codex-auth.ts, packages/core/src/utils/codex-auth.ts)
  • CLI-side Codex auth helper (packages/cli/src/utils/codex-cli-auth.ts)
  • Restores streaming usage reporting for Codex/Responses endpoints

Chrome On-Device Bridge — Gemini Nano (packages/cli/src/utils/chrome-device-bridge.ts)

  • Enables Gemini Nano via the Chrome Prompt API for fully local, on-device inference
  • Transformer: packages/core/src/transformer/chrome-on-device.transformer.ts
  • Multi-session management with idle eviction
  • Reflexive tool-loop prevention and whitespace stall detection with dynamic fallback (temperature + abort recovery)
  • Explicit <tool_result> XML tag migration for consistent tool interaction
  • Dashboard for session monitoring
  • Cross-platform support (macOS, Linux, Windows)

Architectural Refactoring

Modularized Shared Utilities

  • Streaming (packages/core/src/utils/stream.ts): Reusable stream utilities extracted from individual transformers
  • Thinking/Reasoning (packages/core/src/utils/thinking.ts): Ordered thinking sequence handling
  • Google (packages/core/src/utils/google.util.ts): Shared Gemini/Vertex utilities
  • DeepSeek (packages/core/src/utils/deepseek.util.ts): Reasoning replay logic
  • OpenAI (packages/core/src/utils/openai.util.ts): Common OpenAI-compatible API handling
  • Schema (packages/core/src/utils/schema.ts): Tool schema sanitization
  • Cache Control (packages/core/src/utils/cacheControl.ts): Cache header management

Streaming Improvements

  • ThinkingSequencer for ordered Gemini streaming output
  • Improved SSE reader resilience and message grouping
  • Latex-to-unicode integration targeting specific math blocks (not global replacement)
  • Retry-After header propagation from provider errors

Codebase Localization

  • All code comments translated to English for broader contributor accessibility

New Features

Custom Provider Model Discovery

  • packages/cli/src/utils/modelGet.ts: Utility for fetching available models from custom providers
  • Enables dynamic model listing in the routing configuration

Docker Compose Deployment

  • packages/server/docker-compose.yml: Full containerized deployment with config mounting
  • packages/server/Dockerfile: Rebuilt to include UI package assets and multi-stage build
  • .dockerignore added for optimized Docker context

Configuration Improvements

  • Raw config reading without environment variable interpolation

Bug Fixes

  • Gemini 500 errors: Resolved tool use failures in multi-turn conversations
  • Gemini/Gemma streaming: Fixed autocompact and tool schema sanitization
  • Anthropic usage tracking: Included server_tool_use in usage stats
  • DeepSeek reasoning: Implemented mandatory reasoning replay to prevent silent thinking-block loss
  • Mistral reasoning: Corrected reasoning parameter handling per model variant

Testing & Documentation

Testing

  • packages/core/src/tests/gemini.parity.ts: Gemini parity testing suite
  • packages/core/src/tests/deepseek.reasoning.ts: DeepSeek reasoning validation
  • packages/cli/src/tests/ccr-anthropic-flow.test.ts: Anthropic flow integration test

Documentation

  • tasks/lessons.md: Hard-won integration knowledge (DeepSeek reasoning, Mistral thinking, Gemini streaming, Nano constraints)
  • examples/README.md: Internationalized with dynamic preset examples
  • CLAUDE.md: Updated with Docker Compose instructions, knowledge base references, and core objectives

Test Plan

  • pnpm build passes locally
  • Docker build: cd packages/server && docker compose build succeeds
  • Mistral transformer verified with Mistral Large / Codestral reasoning models
  • Codex OAuth flow and streaming validated
  • Chrome on-device bridge tested with Gemini Nano on Chrome 130+
  • DeepSeek reasoning replay validated against live API
  • Gemini parity suite passes baseline checks

unmodeled-tyler and others added 30 commits April 22, 2026 16:50
Add MistralTransformer to enable direct integration with Mistral AI API.
This transformer handles the conversion from Anthropic-style requests to
Mistral's OpenAI-compatible format by:

- Removing cache_control fields (not supported by Mistral)
- Flattening array content to strings where appropriate
- Converting tool_choice 'required' to 'any' (Mistral's equivalent)
- Preserving image content in array format when present

Fixes musistudio#509
- Remove JSON.parse/stringify deep clone, mutate request directly for
  consistency with other transformers (groq, cleancache, deepseek)
- Add  removal from tool function parameters (like groq.transformer)
- Remove unnecessary 'as any' type assertion on tool_choice
- Simplify transformMessage to mutate in place instead of creating new object
feat: improve OpenAI API handling borrowig functionality from y-router and claude-code-proxy
…ities for better maintainability across transformers
- gemini.util.ts: flush pendingContent on stream end, fixing lost text for
  Gemma models with thinking but no thoughtSignature (e.g. gemma-4-31b-it);
  map Gemini 400 context-too-long errors to finish_reason
  "model_context_window_exceeded" to trigger Claude Code autocompact;
  remove temporary debug logs

- anthropic.transformer.ts: pass through model_context_window_exceeded as
  stop_reason in both streaming and non-streaming paths

- schema.ts (new): sanitizeJsonSchema strips unknown fields via whitelist and
  removes invalid format/enum/uri combinations; fixes bug where property
  schemas bypassed the whitelist; normalizeToolParameters wraps it for tools

- groq.transformer.ts, mistral.util.ts: use normalizeToolParameters for full
  schema sanitization instead of only deleting $schema

- gemini.transformer.ts: resolve model name from context before URL build

- vertex-gemini.transformer.ts: fall back to provider.model when request.model
  is empty
…nversations

- gemini.util.ts: Rebuild thinking history as proper {thought:true, thoughtSignature} parts
  instead of attaching thoughtSignature to text/functionCall parts; Gemini requires the
  thought part structure when replaying conversation history
- anthropic.transformer.ts: Extract plain text from tool_result content arrays instead of
  JSON.stringify-ing them, so models receive actual file content rather than JSON wrappers
- routes.ts: Only use SSE streaming path when response.ok; error responses now return as
  JSON regardless of stream mode, preventing Web ReadableStream being sent to Fastify
- index.ts: Remove buggy done(payload.error, null)/done(payload, null) calls in onSend hook
  that were treating valid payloads as Fastify errors, causing unhandledRejection crashes
…ze thought_signature naming in Gemini integration
… reader resilience, and introduce parity testing suite.
…add Docker Compose configuration to the documentation
… Prompt API

Gemini Nano is a ~4GB on-device LLM built into Chrome, accessed through the
Prompt API (window.LanguageModel). It runs locally with no API costs or
network round-trips, using Chrome's built-in model download.

The chrome-on-device transformer routes requests through a host-side bridge
(ccr chrome-bridge) that connects to Chrome via CDP/Puppeteer. The bridge
maintains a persistent LanguageModel session with responseConstraint (JSON
Schema) to force structured tool-call output, replacing Claude Code's verbose
system prompt with a compact 7-tool version. It strips system-reminder blocks,
truncates tool results, detects whitespace stalling, and auto-compacts at 85%
context usage to fit within the ~9K token window and ~1200 char/turn output
limit.
oakimov added 7 commits May 12, 2026 12:57
- Implement dynamic temperature scaling and fallback retry for whitespace stalling
- Add 'OPERATIONAL OVERRIDE' and strict path guidelines to prevent hallucinations
- Implement tool result labeling and context-aware result checking
- Fix session recreation loop and add parameter clamping for Prompt API
- Improve JSON extraction robustness and update documentation
…tool_result> XML tags and updating system prompts for improved tool interaction consistency.
…hen reflexive tool-loop prevention

- Add per-session stats tracking with lastActivityAt timestamps
- Add session list table to dashboard with turn count, idle time, context %, and Evict buttons
- Add idle session eviction timer (5 min threshold, 60s check interval, 'cli' protected)
- Fix updateDashboard() to update for ALL sessions, not just 'cli' gate
- Fix updateStats() to accept sessionId instead of hardcoding 'cli'
- Fix resetSession() to clear lastActivityAt for proper eviction hygiene
- Strengthen [NOTICE] prefix to name exact tools already called and instruct ExitTool usage
- Update README.md: multi-session architecture, session eviction, system-reminder transformation docs
- Update lessons.md: reflexive loop prevention, first-turn assistant inclusion, multi-session pitfalls
- Update TODO.md: mark assistant history management as complete
Revert README.md to upstream version, remove tasks/TODO.md,
and remove TODO.md reference from CLAUDE.md.
@oakimov oakimov closed this May 31, 2026
@oakimov
oakimov deleted the feat/fork-contributions branch June 2, 2026 08:19
@oakimov
oakimov restored the feat/fork-contributions branch June 28, 2026 21:59
@oakimov
oakimov deleted the feat/fork-contributions branch June 28, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants