Commit Graph

1951 Commits

Author SHA1 Message Date
LTbinglingfeng
2659e490a8 fix: expose plugin support header for CORS 2026-06-13 05:53:19 +08:00
LTbinglingfeng
4f5f1b8f2b fix(plugins): guard config read with mutex 2026-06-13 05:05:49 +08:00
LTbinglingfeng
b60ec43944 fix(plugins): expose saved plugin config 2026-06-13 04:51:07 +08:00
LTbinglingfeng
b2b5d10b75 feat(pluginstore): make registry version field optional
The latest release is now the source of truth for plugin versions, so
the registry version only serves as a display fallback. Validate its
format only when present.
2026-06-13 04:10:11 +08:00
LTbinglingfeng
220b4e5bbd feat(management): resolve plugin store versions from latest releases
List entries now show each plugin's latest release version and compute
update availability against it, falling back to the registry version
when the lookup fails. Lookups run concurrently and are cached per
repository with a short failure TTL to respect API rate limits.
2026-06-13 04:05:09 +08:00
LTbinglingfeng
40f4b8b856 feat(pluginstore): fetch and install plugins from latest release
Replace the tag-pinned release lookup with the repository latest
release endpoint. Derive the plugin version from the release tag,
validate it, and attach an optional token to API requests to raise
the rate limit.
2026-06-13 04:00:05 +08:00
Luis Pater
44d3066a9c feat(htmlsanitize): add HTML and JSON sanitization utilities with integration across plugins and APIs
- Introduced `htmlsanitize` package for escaping HTML and handling JSON body sanitization to prevent XSS vulnerabilities.
- Integrated sanitization functions into plugin store, plugin host, and API management handlers to ensure all user-facing content is escaped.
- Added unit tests to verify proper escaping of HTML strings, JSON bodies, and nested data structures.
- Updated existing management and plugin-related tests to validate sanitization implementations.
2026-06-13 01:10:27 +08:00
Luis Pater
60f6a54282 feat(pluginstore, pluginhost): add plugin unload handling and preserve config during plugin updates
- Introduced logic to handle plugin unloading during updates to prevent conflicts with loaded plugins.
- Preserved existing plugin configurations during updates, ensuring seamless transitions and maintaining custom fields.
- Added support for reloading the configuration after management saves changes.
- Enhanced unit tests to validate unloading, configuration preservation, and reloading behaviors.
2026-06-13 00:33:21 +08:00
Luis Pater
049ced5c3f feat(pluginhost, api): add support for "X-CPA-SUPPORT-PLUGIN" header with CGO detection
- Introduced `SupportPluginHeaderValue` to indicate CGO build status (`1` for enabled, `0` for disabled).
- Updated API response headers in `handler.go` to include "X-CPA-SUPPORT-PLUGIN".
- Added unit tests to verify proper header behavior under varying conditions.
2026-06-12 23:54:26 +08:00
Luis Pater
69b7462860 refactor(translator): update test strings to use English for consistency
- Replaced Chinese test strings in `claude_openai-responses_response_test.go` with English equivalents (e.g., "**对比竞品**" -> "**Compare competitors**").
- Updated comments in `config.example.yaml` to English to align with project language standards.
2026-06-12 23:44:57 +08:00
Luis Pater
0626b22e61 Merge pull request #3818 from router-for-me/Plugin-stone
feat(pluginstore): add lightweight plugin store installer APIs
2026-06-12 23:36:44 +08:00
LTbinglingfeng
e38ba28db5 feat(pluginstore): add plugin store support 2026-06-12 23:15:00 +08:00
Luis Pater
9dbf4cd07e feat(translator): add usage token details for cache input/output aggregation
- Introduced `claudeResponsesUsageTokens` to manage detailed token statistics, including input, output, cache read, and cache creation tokens.
- Updated aggregation logic to include cached tokens in total usage calculations.
- Refactored usage processing to simplify token merging and ensure consistent handling across streaming and non-streaming responses.
- Added unit tests (`TestConvertClaudeResponseToOpenAIResponses_ReportsCacheTokens`) to verify correct cache token inclusion in usage metrics.

Closes: #3807
2026-06-12 21:03:39 +08:00
Luis Pater
538e3416db feat(plugin, api): prevent plugin recursion on host model callbacks, enable targeted interceptor skipping
- Updated host model callback logic to skip originating plugin's interceptors during nested model executions.
- Added `SkipInterceptorPluginID` field to plugin API structs for controlling interceptor bypass behavior.
- Introduced supporting logic in host API handlers, plugin host registry, and callback contexts to identify and skip specific plugins.
- Enhanced unit tests across plugin host, API handlers, and execution paths to verify interceptor skipping behavior and plugin isolation.
- Revised documentation to clarify non-recursive behavior of host model callbacks and the use of `SkipInterceptorPluginID`.
2026-06-12 02:38:51 +08:00
Luis Pater
8e39db2ec7 feat(plugin, api): introduce host model callback support with Go example and API handlers
- Added an example plugin `host-model-callback` in Go to summarize host model callbacks.
- Implemented `cliproxy_plugin_init`, `cliproxyPluginCall`, and other plugin functions for callback handling.
- Introduced API handlers for `ModelExecution` and `ModelExecutionStream` with support for both streaming and non-streaming requests.
- Included unit tests (`model_execution_test.go`) to validate execution logic and streaming responses.
2026-06-12 02:22:23 +08:00
Luis Pater
ac4017ea0e Merge branch 'dev' of github.com:router-for-me/CLIProxyAPI into dev 2026-06-11 10:38:16 +08:00
Luis Pater
030c4a9385 Merge pull request #3795 from router-for-me/webui
feat(auto-updater): refactor skip logic and add unit tests for autoUpdateSkipReason
2026-06-11 10:31:58 +08:00
Luis Pater
9985976ebd feat(translator, pluginhost): add stream-specific response transformation support
- Introduced `HasStreamResponseTransformer` and `HasNonStreamResponseTransformer` to handle streaming and non-streaming transformations.
- Updated `executorResponseTranslatorExists` logic to correctly validate stream-specific transformers.
- Enhanced `TranslateStream` to suppress raw fallback when registered native transformers return empty output.
- Added comprehensive tests (`TestHasResponseTransformerChecksConcreteResponseKinds`, `TestHasResponseTransformerIgnoresEmptyRegistration`) for stream and non-stream transformer validation.
2026-06-11 10:16:58 +08:00
Luis Pater
dc04d8be52 feat(translator): enhance response aggregation and annotation handling
- Implemented logic to aggregate text blocks until `message_stop` for improved consistency.
- Introduced support for message annotations like `citations_delta` in content responses.
- Added methods (`finalizeAssistantMessage`, `appendMessageAnnotation`) to handle message grouping and annotation appending cleanly.
- Updated unit tests to verify message aggregation, annotation handling, and suppression of unwanted native events.

Closes: #3801
2026-06-11 03:14:03 +08:00
Luis Pater
58bf645e66 feat(translator): ensure correct finish_reason handling for all response chunks
- Added tests (`TestCliFinishReasonOnlyOnFinalChunk`, `TestGeminiFinishReasonOnlyOnFinalChunk`) to validate correct `finish_reason` and `native_finish_reason` assignment.
- Refactored Gemini and CLI translators to track `SawToolCall` and `UpstreamFinishReason` for accurate final-chunk determination.
- Improved response parsing logic to align with upstream metadata and provide consistent reasoning on chunk outputs.
2026-06-11 00:17:45 +08:00
Luis Pater
1ca048abdc feat(auth, interceptor, jshandler): add post-auth request interceptors and enhance format handling
- Introduced `applyRequestAfterAuthInterceptor` to modify requests after credential selection and before executor translation.
- Added `InterceptRequestAfterAuth` method across plugin adapters with corresponding tests for context validation.
- Enhanced format resolution logic (`requestToFormat`) to support additional providers and formats.
- Updated JavaScript handler to include a new `on_after_auth_request` hook for post-auth request handling.
- Refactored interceptor methods for clarity and better encapsulation of request/response lifecycles.
2026-06-10 20:58:59 +08:00
hkfires
3c773b6d92 feat(auto-updater): refactor skip logic and add unit tests for autoUpdateSkipReason 2026-06-10 16:15:33 +08:00
Luis Pater
8e52c403f7 feat(auth): deduplicate concurrent refresh token requests with singleflight
- Introduced `singleflight.Group` to prevent redundant token refresh calls across multiple auth implementations (`antigravity`, `kimi`, `xai`, `codex`).
- Added tests to verify shared upstream calls during concurrent refresh requests.
- Refactored token refresh logic to centralize and standardize deduplication mechanisms.
2026-06-10 03:19:26 +08:00
Luis Pater
8caf47464c Merge pull request #3788 from shoucandanghehe/fix/codex-backend-request-id
fix(logging): track Codex backend request IDs
2026-06-10 02:58:36 +08:00
Luis Pater
efd69d8ece feat(models): add Claude Fable 5 to registry
- Added new model `Claude Fable 5` to `models.json` with enhanced reasoning and long-horizon capabilities.
- Included detailed parameters such as context length, max completion tokens, and thinking level configurations.
2026-06-10 02:38:04 +08:00
shoucandanghehe
dc3152d2e3 fix(logging): tighten Codex backend request ID prefix 2026-06-10 01:29:42 +08:00
shoucandanghehe
e1864fbf33 fix(logging): track Codex backend request IDs 2026-06-10 01:05:09 +08:00
Luis Pater
44ea9abced feat(pluginhost): introduce browser-navigable plugin resources in Management API
- Added `resources` field in `management.register` for defining browser-accessible resources.
- Updated examples and documentation to reflect resource-based paths under `/v0/resource/plugins/<pluginID>/...`.
- Replaced legacy `GET` menu routes with resource-based implementations for consistent plugin behavior.
- Enhanced request handling for resource paths, including proper response headers and streamlined test coverage.
2026-06-09 22:46:27 +08:00
Luis Pater
2aeb41cecf feat(pluginhost, jshandler): integrate HostCallbackID with interceptors and JS engine logging
- Added `HostCallbackID` to request, response, and stream chunk interceptors for enhanced context tracking.
- Updated JavaScript engine to support custom console logging with `HostCallbackID` forwarding.
- Introduced tests verifying proper integration of `HostCallbackID` in all interceptor flows and engine logging.
- Enhanced logging and error handling for consistent callback-related logic implementation.
2026-06-09 14:36:42 +08:00
Luis Pater
41a4dba670 feat(auth): enhance plugin scheduler with HasScheduler support and fast-path tests
- Added `pluginSchedulerState` interface with `HasScheduler` method for improved plugin scheduler state checks.
- Updated `Manager.hasPluginScheduler` to handle `HasScheduler` logic.
- Implemented and tested fast-path handling for inactive plugin schedulers, including mixed provider scenarios.
- Expanded unit test coverage to ensure correct behavior in various scheduler states.
2026-06-09 13:57:37 +08:00
Luis Pater
693ce1c55a feat(pluginhost, scheduler): introduce Go-based plugin with scheduler capabilities
- Added a Go scheduler plugin demonstrating CLIProxyAPI capabilities, such as `plugin.register`, `plugin.reconfigure`, and `scheduler.pick`.
- Implemented methods for plugin configuration, built-in scheduler delegation (`fill-first`, `round-robin`), dynamic candidate selection, and error handling.
- Extended `pluginhost` with scheduler handling, candidate normalization, and fallback mechanisms.
- Included examples, tests, and detailed documentation for scheduler usage and implementation.
2026-06-09 13:57:36 +08:00
sususu98
a2db6a6108 Merge pull request #3773 from sususu98/fix/antigravity-version-upstream-dev
fix: update antigravity version lookup
2026-06-09 11:43:59 +08:00
sususu98
9fb9e9154b Merge pull request #3770 from sususu98/fix/codex-claude-stream-error-upstream-dev
fix: translate codex stream errors for claude
2026-06-09 11:43:43 +08:00
sususu98
c7cc3a1a4d fix: update antigravity version lookup 2026-06-09 11:32:57 +08:00
Luis Pater
fabf06154f feat(access, pluginhost): add support for exclusive frontend auth providers
- Introduced `FrontendAuthProviderExclusive` capability to restrict authentication to a single selected provider.
- Added `SetExclusiveProvider` and `ClearExclusiveProvider` methods for managing exclusive providers in the access registry.
- Updated `pluginhost` to prioritize and enforce exclusive providers based on plugin priority and ID.
- Enhanced RPC capabilities schema to include `FrontendAuthProviderExclusive` field.
- Added example plugin and tests for exclusive frontend auth behavior.
2026-06-09 10:56:58 +08:00
Luis Pater
5e41e079e5 fix(runtime): update formatting in codex image extraction comment 2026-06-09 02:20:57 +08:00
Luis Pater
d128578efa Merge pull request #3771 from Folyd/perf/codex-image-streaming-memory
perf(codex): avoid rebuilding completed JSON when extracting generated images
2026-06-09 01:49:12 +08:00
Luis Pater
1762ee0d2e feat(pluginhost): add support for interceptors and metadata sanitization
- Implemented `RequestInterceptor`, `ResponseInterceptor`, and `StreamChunkInterceptor` capabilities.
- Added `sanitizePluginMetadata` to clean metadata for RPC compatibility.
- Enhanced interceptor chaining, error handling, and test coverage.
- Updated plugin configuration to register and dispatch interceptor methods.
2026-06-09 01:41:46 +08:00
Folyd
2e81766c92 perf(codex): preallocate results and skip empty index sort
Apply review feedback on codexExtractImageResults: preallocate the results
slice to its known maximum capacity to avoid growth reallocations, and guard
the itemsByIndex index-build/sort with a length check so no empty slice is
allocated or sorted when only the fallback items are present.
2026-06-08 15:55:42 +00:00
Folyd
4330b92612 perf(codex): avoid rebuilding completed JSON when extracting generated images
The OpenAI images path (/v1/images/*) previously called patchCodexCompletedOutput
to concatenate collected output_item.done items back into the completed event and
then re-parsed that rebuilt JSON to pull out the image results. For multi-megabyte
base64 image payloads this produced two extra full-size copies per request (the
concatenated output array plus the rebuilt completed event), inflating peak memory
under concurrent image generation.

Add codexExtractImageResults, which extracts image_generation_call results directly
from either the completed event's response.output or the collected items, without
the concatenate-and-reparse step. Semantics are preserved: completed output is
preferred and collected items are used only when it is empty, matching the original
patchCodexCompletedOutput behaviour. patchCodexCompletedOutput remains in use by the
text/responses path, which still forwards the patched event downstream.

Adds unit tests covering the completed-output path, the ordered fallback to
collected items, output preference, fallback list, and the wrong-event-type guard.
2026-06-08 15:47:14 +00:00
sususu98
702295d73a fix: translate codex stream errors for claude 2026-06-08 21:07:21 +08:00
Luis Pater
856dc81748 feat(safemode): support /management.html route in ExampleAPIKeyWarningHandler
- Added handling for `/management.html` in `ExampleAPIKeyWarningHandler`.
- Updated tests to validate correct behavior for the new route.
2026-06-08 12:41:28 +08:00
Luis Pater
ec672446d1 feat(translator): implement signature delta handling and enhance chunk processing in Gemini and Antigravity translators
- Added support for processing `signature-only` chunks without opening empty text blocks.
- Refactored chunk handling logic to include `signature_delta` events for improved fidelity.
- Unified logic for emitting final message states, including `message_delta` and `message_stop`, to ensure consistent behavior across different scenarios.
- Enhanced caching mechanism for thought signatures.
2026-06-08 11:30:17 +08:00
Luis Pater
365415c87a fix(translator): add fallback for system_instruction key in Gemini request parsing
- Added fallback to handle cases where `system_instruction.parts` is absent by checking for `systemInstruction.parts`.
2026-06-08 08:10:41 +08:00
Luis Pater
bc58c21673 chore(build): update dependencies, enhance cross-compilation, and refactor workflows
- Updated `golang.org/x/sys` to v0.38.0 in `go.mod` and replaced `syscall` with `windows` package for memory allocation in `loader_windows.go`.
- Improved cross-compilation in `.goreleaser.yml` using Zig-based toolchains for better platform support.
- Changed GitHub Actions workflow to use macOS runners and added Zig toolchain setup.
2026-06-07 04:13:15 +08:00
Luis Pater
0ed85bb88b feat(pluginhost): refactor and enhance plugin system with new execution and thinking capabilities
- Removed `examples/plugin/main.go` and `internal/pluginhost/loader_plugin.go` after migrating to a more modular system.
- Introduced `streamBridge` in `internal/pluginhost/stream_bridge.go` for efficient stream handling and communication.
- Added examples of `thinking` plugins written in both Rust and Go under `examples/plugin/thinking`.
- Enhanced test coverage for plugin host system changes, including stream chunk translation and thinking logic.
- Improved API compatibility and ensured backward-compatible upgrades for plugin execution.
2026-06-07 03:20:04 +08:00
Luis Pater
3abfc83d96 Merge branch 'dynamic' into dev
# Conflicts:
#	internal/cmd/run.go
2026-06-06 18:41:13 +08:00
Luis Pater
d625caddd9 feat(pluginhost): add capabilities for command-line flag handling and plugin execution
- Implemented command-line flag registration and execution for plugins with priority-based conflict resolution.
- Enabled plugin-owned command-line flag execution and persistence of plugin-auth data.
- Added new `Host` methods to support command-line capabilities, including flag normalization, validation, and execution state management.
- Introduced unit tests to ensure coverage for command-line plugin functionality, including auth data persistence.
- Updated configs to normalize plugins during initialization.
2026-06-06 18:35:17 +08:00
hkfires
bc38b68902 feat(safemode): implement example API key warning server and related functionality 2026-06-06 11:42:21 +08:00
Luis Pater
5753d1a089 feat(logging): enable file-backed request/response sources for enhanced API logging
- Introduced support for file-backed logging of API requests and responses to handle large payloads efficiently.
- Refactored `attachWebsocketLogSources` to `attachRequestLogSources` for broader request and response handling.
- Added new methods for appending request/response data to file-backed sources and updated existing logging workflows for compatibility.
- Improved cleanup and merge logic for file-backed sources during request processing.
- Updated tests to cover newly introduced file-backed logging functionality.
2026-06-05 01:48:05 +08:00