Commit Graph
72 Commits
Author SHA1 Message Date
RCD 3d853cb295 chore: merge upstream CLIProxyAPI v6.9.10 2026-04-03 13:13:41 +07:00
hkfires 34339f61ee Refactor websocket logging and error handling
- Introduced new logging functions for websocket requests, handshakes, errors, and responses in `logging_helpers.go`.
- Updated `CodexWebsocketsExecutor` to utilize the new logging functions for improved clarity and consistency in websocket operations.
- Modified the handling of websocket upgrade rejections to log relevant metadata.
- Changed the request body key to a timeline body key in `openai_responses_websocket.go` to better reflect its purpose.
- Enhanced tests to verify the correct logging of websocket events and responses, including disconnect events and error handling scenarios.
2026-04-02 17:30:51 +08:00
RCD 0af0ad14e5 Merge upstream CLIProxyAPI v6.8.28–v6.8.32
Upstream changes:
- Codex responses compaction payload compatibility
- Codex usage_limit_reached retry-after, deterministic parsing
- Codex refresh_token_reused non-retryable fix
- Qwen rate limiting and quota error handling
- Context management compatibility simplification
- Antigravity tool_result image fix, model list backfill, deep copy cache
- Auth auto-refresh interval/concurrency limiting
- Auth hook OnResult refactor (replaces MarkResult)
- Gemini-3.1-flash-image support
- Registry cleanup of outdated model definitions

Fork resolution:
- Accept upstream's consolidated conductor.go (auto-refresh, round-tripper)
- Delete stale conductor_oauth.go, conductor_token.go (upstream reversed split)
- Delete stale provider_rotation_test.go (references removed method)
2026-02-27 20:58:16 +07:00
RCD cf558dd166 Merge upstream CLIProxyAPI v6.8.18–v6.8.26
Upstream changes:
- Codex WebSocket executor and Codex response handlers
- Header passthrough (upstream response headers forwarded to clients)
- ExecuteStream returns *StreamResult (wraps channel + headers)
- Embeddings handler with synthetic fallback
- User ID cache for executors
- Gemini schema/request fixes
- New test coverage for bootstrap retries, error responses

Fork resolution:
- Delete upstream's modular TUI files (app.go, styles.go, dashboard.go,
  auth_tab.go, config_tab.go, keys_tab.go, logs_tab.go, oauth_tab.go,
  usage_tab.go, i18n.go, loghook.go) — keep fork's Flight Deck tui.go
- Add PassthroughHeaders field to SDKConfig
- Fix embeddings handler to capture 3-value ExecuteWithAuthManager return
- Update test mocks (conductor_test, auth_flow_test, multi_provider_test,
  gemini_executor_test) for new ExecuteStream signature
- Fix tuiMode → launchTUI flag variable reference
- Remove unused "io" import from main.go
2026-02-23 11:58:54 +07:00
Luis Pater bb86a0c0c4 feat(logging, executor): add request logging tests and WebSocket-based Codex executor
- Introduced unit tests for request logging middleware to enhance coverage.
- Added WebSocket-based Codex executor to support Responses API upgrade.
- Updated middleware logic to selectively capture request bodies for memory efficiency.
- Enhanced Codex configuration handling with new WebSocket attributes.
2026-02-19 01:57:02 +08:00
RCDandClaude 3e4dccf857 fix(middleware): address remaining code review findings
MEDIUM: Return 400 on body read error instead of passing empty body
- Previously, on io.ReadAll error, body was consumed but c.Next()
  was called, causing downstream handlers to see empty body
- Now returns http.StatusBadRequest on read errors

MEDIUM: Recompute token analysis after scaffold injection
- Token analysis was computed before scaffold state was injected
- If scaffold pushed request over token threshold, trimming was skipped
- Now recomputes analyzeTokenBudget() after injection

LOW: Always strip X-CLIProxyAPI-Todo header
- Header was only stripped when memory store was available
- If memory disabled, internal header leaked upstream
- Now stripped immediately regardless of memory store state

Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
2026-02-01 12:52:57 +07:00
RCDandClaude 4491089ad1 fix(middleware): ensure prompt budget trimming loop executes
The trimming loop condition `for keep >= minKeep` was never true because
`keep` started at 20 while `minKeep` defaults to 25. Added clamp to ensure
`keep >= minKeep` at initialization, fixing prompt budget enforcement.

Affected functions:
- trimOpenAIChatCompletions
- trimOpenAIResponses
- trimOpenAIChatCompletionsWithMemory
- trimOpenAIResponsesWithMemory
- trimClaudeMessagesWithMemory

Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
2026-02-01 12:50:05 +07:00
RCDandClaude 7cc4e9d8f5 refactor(middleware): split codex_prompt_budget.go into logical modules
Split the 2,762 line codex_prompt_budget.go into focused modules:
- codex_prompt_budget.go (1,272 lines): Main middleware, scaffold injection
- codex_budget_types.go (498 lines): Constants, package vars, config functions
- codex_budget_calculator.go (944 lines): Token analysis, trim functions

Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
2026-02-01 12:28:00 +07:00
RCDandClaude b5077879d0 chore: clarify GetRequestMonitor stub comment
Remove TODO marker and update comment to indicate the stub is
intentional for API compatibility, not incomplete work.

Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
2026-02-01 11:54:32 +07:00
RCDandClaude 71a502075e fix(logging): capture streaming TTFB on first chunk and make timestamps required
- Add firstChunkTimestamp field to ResponseWriterWrapper for sync capture
- Capture TTFB in Write() and WriteString() before async channel send
- Add SetFirstChunkTimestamp() to StreamingLogWriter interface
- Make requestTimestamp/apiResponseTimestamp required in LogRequest()
- Remove timestamp capture from WriteAPIResponse() (now via setter)
- Fix Gemini handler to set API_RESPONSE_TIMESTAMP before writing response

This ensures accurate TTFB measurement for all streaming API formats
(OpenAI, Gemini, Claude) by capturing timestamp synchronously when
the first response chunk arrives, not when the stream finalizes.

Cherry-picked from upstream: 295f34d7

Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
2026-01-30 15:31:30 +07:00
RCDandClaude bcd735b2a8 fix(logging): add API response timestamp and fix request timestamp timing
Previously:
- REQUEST INFO timestamp was captured at log write time (not request arrival)
- API RESPONSE had NO timestamp at all

This fix:
- Captures REQUEST INFO timestamp when request first arrives
- Adds API RESPONSE timestamp when upstream response arrives
- Add Timestamp field to RequestInfo, set at middleware initialization
- Set API_RESPONSE_TIMESTAMP in appendAPIResponse() and gemini handler
- Pass timestamps through logging chain to writeNonStreamingLog()
- Add timestamp output to API RESPONSE section

Cherry-picked from upstream: c41ce77e

Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
2026-01-30 15:30:56 +07:00
sususu98 295f34d7f0 fix(logging): capture streaming TTFB on first chunk and make timestamps required
- Add firstChunkTimestamp field to ResponseWriterWrapper for sync capture
- Capture TTFB in Write() and WriteString() before async channel send
- Add SetFirstChunkTimestamp() to StreamingLogWriter interface
- Make requestTimestamp/apiResponseTimestamp required in LogRequest()
- Remove timestamp capture from WriteAPIResponse() (now via setter)
- Fix Gemini handler to set API_RESPONSE_TIMESTAMP before writing response

This ensures accurate TTFB measurement for all streaming API formats
(OpenAI, Gemini, Claude) by capturing timestamp synchronously when
the first response chunk arrives, not when the stream finalizes.
2026-01-29 22:32:24 +08:00
RCDandClaude 41b1ad654e feat(config): add oauth-model-alias migration support
Add migration logic for converting oauth-model-mappings to oauth-model-alias
with comprehensive test coverage.

Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
2026-01-29 21:30:09 +07:00
sususu98 c41ce77eea fix(logging): add API response timestamp and fix request timestamp timing
Previously:
- REQUEST INFO timestamp was captured at log write time (not request arrival)
- API RESPONSE had NO timestamp at all

This fix:
- Captures REQUEST INFO timestamp when request first arrives
- Adds API RESPONSE timestamp when upstream response arrives

Changes:
- Add Timestamp field to RequestInfo, set at middleware initialization
- Set API_RESPONSE_TIMESTAMP in appendAPIResponse() and gemini handler
- Pass timestamps through logging chain to writeNonStreamingLog()
- Add timestamp output to API RESPONSE section

This enables accurate measurement of backend response latency in error logs.
2026-01-29 22:22:18 +08:00
RCD e6e7e6db30 feat(registry): support provider-specific model info lookup
Add InfoByProvider map to ModelRegistration to store provider-specific
ModelInfo, enabling different capabilities for the same model across
providers (e.g., direct API vs OpenRouter).

Changes:
- Add InfoByProvider field to ModelRegistration struct
- Update GetModelInfo to accept provider parameter for provider-specific lookup
- Update LookupModelInfo to accept variadic provider parameter
- Add LookupStaticModelInfo for fallback to static model definitions
- Update ApplyThinking to pass providerKey for registry lookups
- Update all GetModelInfo callers to use new signature
- Remove ensureMaxTokensForThinking test (function moved to thinking package)

Ported from CLIProxyAPI e641fde2
2026-01-20 11:15:39 +07:00
Finessse 69ba18a095 fix(middleware): respect request history sampling in logging middleware 2026-01-09 23:39:14 +07:00
Finessse 8b9f5ebe00 feat(middleware): add runtime toggle and sampling for request history 2026-01-09 23:39:00 +07:00
Finessse 65e243ec1b feat(middleware): add runtime toggle for Prometheus metrics 2026-01-09 23:38:47 +07:00
Finessse fce1e62aa4 perf(middleware): pool response body buffers to reduce GC pressure 2026-01-09 23:38:34 +07:00
Finessse 30978f1f17 feat(cache): add response cache and prompt cache tracking
Response cache stores completions keyed by request hash.
Prompt cache tracking aggregates cache_read/cache_creation tokens.
WebUI CacheStats component shows hit rates and token savings.
2026-01-06 06:21:54 +07:00
Finessse 99c4d3ccc3 feat(memory): harden summarization pipeline 2026-01-01 00:51:56 +07:00
Finessse e5aec4a28e fix(harness): skip initializer in existing projects 2026-01-01 00:51:46 +07:00
Finessse 2219bc04e4 feat(api): add Prometheus metrics endpoint
Expose /metrics endpoint for observability with request counts,
latencies, and connection stats.
2025-12-31 02:00:01 +07:00
Finessse 94ef02e19d feat(api): add connection tracker middleware
Track active HTTP connections with thread-safe counter.
Exposes ActiveConnections.Count() for monitoring.
2025-12-31 01:59:17 +07:00
Finessse f7ae19d960 feat(api): add request history API endpoints
Add management endpoints for request history:
- GET /request-history - list entries with pagination
- GET /request-history/stats - aggregate statistics
- DELETE /request-history - clear all entries
- POST /request-history/export - export to JSON
- POST /request-history/import - import from JSON
- POST /request-history/save - force save to disk

Integrate RequestHistoryManager with request logging middleware.
2025-12-29 21:18:45 +07:00
Finessse ad355f75a7 feat(api): add persistent request history storage
Add RequestHistoryManager with file-based persistence at
~/.cli-proxy-api/request-history.json. Features:
- Max 500 entries with automatic pruning
- Auto-save every 30 seconds
- Thread-safe with mutex protection
- In-memory ring buffer for performance
2025-12-29 21:18:31 +07:00
Finessse 281ac2e0ba refactor(backend): improve API and internal services
- Add request logging middleware
- Update integrations handler
- Improve desktopctl with browser opening
- Add client model interfaces
- Enhance usage logger plugin
- Update SDK handlers
2025-12-28 00:06:07 +07:00
FinessseandClaude Opus 4.5 f4e7d5b92e test(middleware): add session storage test for agentic harness
Add E2E test for session-based harness file detection.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 02:13:39 +07:00
FinessseandClaude Opus 4.5 eb84cbe543 refactor(middleware): remove Puppeteer MCP detection from harness
Removed feature not present in original Factory.ai or Anthropic sources.
Keep implementation pure to research references.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 02:13:31 +07:00
FinessseandClaude Opus 4.5 095718e31e feat(middleware): add InitSummarizerWithAuthManager for compression setup
Enables Factory.ai-style LLM summarization by wiring the summarizer
executor to the core auth manager.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 02:12:46 +07:00
FinessseandClaude Opus 4.5 87dbbedd4b feat(middleware): enhance agentic harness prompts
Improve INITIALIZER and CODING prompts based on Anthropic guidance:
- Structured feature_list.json format
- GET BEARINGS workflow for coding mode
- Puppeteer MCP detection for browser testing
- Session-aware state detection

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 05:08:15 +07:00
FinessseandClaude Opus 4.5 25dd8b2087 feat(middleware): add token-aware context compression
Implement proactive compression based on token count rather than bytes:
- Uses tiktoken for accurate token estimation
- Compresses at 75% threshold before hitting limits
- Reserves tokens for output generation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 05:07:42 +07:00
FinessseandClaude Opus 4.5 221a386040 feat: sync with CLIProxyAPIPlus (excludes Amp, GitHub Copilot)
Synced all changes from router-for-me/CLIProxyAPIPlus including:

Executor updates:
- claude_executor: response decompression, beta extraction, model resolution
- gemini_executor/codex_executor: usage reporting
- antigravity_executor: fallback URLs, thinking metadata, token refresh
- kiro_executor: token refresh, profile ARN handling, quota fallback

Translator updates:
- Updated all translators for improved request/response handling
- Enhanced tool result formatting and streaming support

Configuration:
- Added IncognitoBrowser option for OAuth
- Updated KiroKey configuration
- Enhanced PayloadConfig options

SDK updates:
- Auth refresh registry improvements
- Cliproxy service enhancements
- Added ErrNotImplemented for executor interface

Excluded features (not synced):
- Amp CLI Integration module
- GitHub Copilot executor

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 02:10:20 +07:00
hkfires e76ba0ede9 feat(logging): implement request ID tracking and propagation 2025-12-24 08:32:17 +08:00
Finessse 1a405d7976 middleware: add rate limits and semantic truncation 2025-12-20 15:47:50 +07:00
Finessse d96d9e0b8e middleware: update agentic memory pipeline 2025-12-20 15:00:46 +07:00
Finessse 33cf877a15 feat: add scaffolded prompt state and semantic memory 2025-12-20 05:58:08 +07:00
Finessse 40722131ee feat: add agentic harness middleware 2025-12-20 05:47:56 +07:00
Finessse e505267093 chore: remove temporary reproduction scripts
Deletes repro_merge.go and test_gjson.go which were likely used for debugging or testing during development.
2025-12-20 04:02:08 +07:00
Finessse ae506ce66e feat(api): add AgenticHarnessMiddleware for long-running agent support
Implements a new middleware to handle agentic headers and dynamically inject system prompts for 'Initializer' and 'Coding' agents. Also registers this middleware in the server setup.
2025-12-20 04:01:32 +07:00
Finessse f019f43879 feat(middleware): add Claude Code CLI support and diagnostic headers
- Add claude-cli detection to isAgenticCLI and mustKeepTools checks
- Add /v1/messages Claude Messages API format support
- Implement trimClaudeMessagesWithMemory with tool_use/tool_result adjacency preservation
- Add extractLastUserTextFromClaude, extractTextFromClaudeMessage, truncateClaudeMessageContent helpers
- Add claude case to prependToLastUserText, appendToLastUserText, extractPinnedContext
- Add response headers for localhost diagnostics:
  - X-ProxyPilot-Session: session ID
  - X-ProxyPilot-Request-Shape: detected format (chat/responses/claude)
  - X-ProxyPilot-Memory-Stored: dropped message count
  - X-ProxyPilot-Memory-Retrieved: injected snippet count
2025-12-20 02:24:56 +07:00
Finessse 428b1f04c1 server: decompress gzip request bodies 2025-12-18 16:49:37 +07:00
Finessse 893c43ae30 agentic: preserve tool call/result pairs when trimming chat payloads 2025-12-18 16:12:01 +07:00
Finessse 34082f2eef middleware: pack state into last user message 2025-12-17 21:15:58 +07:00
Finessse 0a74cf7efb middleware: inject persistent todo 2025-12-17 21:01:14 +07:00
Finessse 11b994cd14 memory: anchored summary + pinned context 2025-12-17 20:53:54 +07:00
Finessse 80e383098f middleware: persist + retrieve trimmed history 2025-12-17 20:45:47 +07:00
Finessse 72be557be8 middleware: keep tools for droid/factory 2025-12-17 20:34:06 +07:00
Finessse d23af0518d middleware: model-aware prompt budget 2025-12-17 20:30:03 +07:00
Finessse 755291cef8 middleware: preserve tool call/result pairs when trimming 2025-12-17 17:15:45 +07:00