139 Commits

Author SHA1 Message Date
Luis Pater
14e577174a fix(pluginhost): support credential-scoped rate limit errors from plugin executors
- Add optional credential_scoped metadata and documented routing/cooldown error code constants to pluginabi.Error so plugin executors can report account-wide 429 limits.
- Preserve credential-scoped classification on rpcError across synchronous RPC envelopes and streaming error callbacks while prioritizing credential quota scope over model-only or cooldown-skipping error codes.
- Recognize credential_quota error codes in core auth cooldown classification and cover whole-credential cooldown propagation and error events with regression tests.

Closes: #7359
2026-11-09 03:19:45 +08:00
Luis Pater
0074897481 feat(pluginhost): expose token modality details in usage.handle
- Extend pluginapi.UsageDetail with optional modality token counters matching core usage.Detail.
- Forward independent pointer copies of modality counters in usageAdapter.HandleUsage so plugins receive full breakdown details.
- Add adapter, SDK, and RPC regression tests covering populated, explicit zero, and absent modality counters.

Closes: #7352
2026-11-08 20:52:39 +08:00
Luis Pater
b5b724d06d fix(pluginhost): reuse content-addressed plugin shadow copies across restarts
- Reuse existing content-addressed shadow binaries in `<plugin_dir>/.shadow` (with a per-directory shared cache fallback) and verify target digests before creating any temporary files.
- Publish shadow binaries without unlinking active targets and coordinate plugin loading with stale shadow cleanup via OS-level file locks.
- Add regression tests covering cross-restart shadow reuse, zero-write cache hits, fallback isolation, and concurrent load/prune coordination.

Closes: #7323
2026-11-07 18:10:39 +08:00
Luis Pater
482efbf5a7 feat(auth): enhance OAuth provider handling with explicit hints and metadata preservation 2026-11-07 04:38:59 +08:00
Luis Pater
1c53721167 fix(auth): keep count_tokens 501 and unsupported capability responses availability-neutral
- Classify HTTP 501 and typed unsupported count_tokens errors as availability-neutral in isCountTokensEndpointNotFoundError while preserving explicit model-not-found, auth, and quota cooldowns.
- Expose ErrorCode() on plugin RPC and auth error types so resultErrorFromError retains structured plugin error codes during count_tokens execution.
- Add regression tests verifying that repeated count_tokens 501 responses neither suspend inference availability nor extend active model cooldowns.

Closes: #7271
2026-11-05 19:25:12 +08:00
Luis Pater
6e10359968 fix(pluginhost): abort hot reload on quiesce failure and coordinate usage replay
- Abort replacement loading and roll back the active plugin when plugin.quiesce fails with an operational error or panic while keeping unsupported-method fallback.
- Drain in-flight usage calls before quiescing and queue replacement-window usage records for ordered replay after replacement or rollback recovery.
- Retain held usage records across failed rollback recovery and bound synchronous replay so ApplyConfig cannot overlap native lifecycle calls or starve under load.

Closes: #7232
2026-11-04 03:29:11 +08:00
Luis Pater
04208efa8b fix(pluginhost): preserve disabled auth state across plugin refreshes
- Add preserveAuthDisabledState helper that carries the host-side Disabled flag and StatusDisabled into plugin refresh results so a minimal AuthData response no longer re-enables operator-disabled credentials.
- Apply the preservation in both Host.RefreshAuth and executorAdapter.Refresh backfill paths, and cover both directions plus the status-only edge case with regression tests.

Closes: #7225
2026-11-03 13:00:28 +08:00
Luis Pater
dde469d3c2 fix(pluginhost): isolate unix plugin dlopen crashes with a preflight subprocess probe
- Run an out-of-process preflight dlopen and initialization probe before mapping dynamic plugin libraries into the host process so fatal signals such as SIGILL do not crash-loop the gateway.
- Cache only deterministic probe outcomes with bounded stderr collection and non-blocking stdio handling across inherited child descriptors.
- Pin baseline Go and CGO CPU architecture flags in the plugin example build recipe and document baseline ISA flags for prebuilt c-shared plugin releases.

Closes: #7220
2026-11-03 11:49:10 +08:00
Luis Pater
6e6afab99a refactor: migrate gjson, sjson, and base64 to MoeForge/moego
- Replace tidwall/gjson and tidwall/sjson with github.com/MoeForge/moego/ojson
  and encoding/base64 with github.com/MoeForge/moego/base64 across the main
  module and examples
- Introduce cross-method *ojson.Doc request rewriting pipelines across
  thinking, signature, client/codex, runtime/executor/helps, pluginhost, and
  all provider executors with FinalizePayloadDoc as the final semantic barrier
- Convert all consecutive JSON mutations (>= 2 Set/SetRaw/Delete operations)
  to batch edits on ojson.Doc
- Upgrade read-only byte paths to ojson.GetBytesNoCopy,
  ojson.GetManyBytesNoCopy, and util.ParseGJSONBytesNoCopy with explicit
  strings.Clone ownership protection across streaming and persistent state
- Use base64.StdEncoding.ValidateString for zero-allocation signature checks
  and base64.EncodeDataURL for single-allocation data URL construction
2026-11-03 03:05:04 +08:00
sususu98
d7af371173 Merge pull request #7167 from sususu98/fix/pluginhost-model-stream-ownership-7159
fix(pluginhost): scope model execution streams to the owning plugin and instance
2026-11-02 18:22:07 +08:00
sususu
d96b194168 fix(pluginhost): reject model stream registration after concurrent teardown 2026-11-02 18:09:08 +08:00
Luis Pater
53ff2f9e74 feat(pluginhost): expose per-entry name and logo for multi-entry OAuth plugins
- Add AuthProviderEntry and AuthProviderEntries in sdk/pluginapi, forward entries over auth.identifier RPC, and send multi_auth_providers in lifecycle requests.
- Normalize per-entry OAuth display metadata with plugin metadata fallbacks in RegisteredPluginInfo while preserving legacy fields when entries are omitted.
- Expose HTML-sanitized oauth_provider_entries in management plugin list responses alongside oauth_provider and oauth_providers.

Closes: #7170
2026-11-01 22:46:17 +08:00
Luis Pater
f7331b5197 fix(pluginhost): deframe same-format plugin executor streams and gate hooks 2026-11-01 21:29:23 +08:00
Luis Pater
aca8dfe0f4 Merge pull request #7154 2026-11-01 21:29:23 +08:00
sususu
3698b1597a fix(pluginhost): scope model execution streams to the owning plugin and instance
Bind modelStreamBridge entries to the caller's plugin ID and callback instance
so host.model.stream_read and host.model.stream_close reject cross-plugin or
cross-instance access. Also close model streams when callback instances or
plugins are torn down.

Fixes #7159
2026-11-01 20:17:56 +08:00
Rick7C2
41c03b7451 fix(pluginhost): normalize same-format plugin executor streams through the stream translator
Plugin executor streams whose output format equaled the requested format bypassed stream translation, so SSE-framed chunks ("data: {...}" plus "data: [DONE]") reached the OpenAI/Gemini handlers unchanged. Those handlers add their own "data:" prefix and terminal marker, producing a doubled "data: data:" prefix and a duplicated [DONE] on the wire.

Built-in executors always run TranslateStream, and the registered same-format translators strip that framing. Route same-format plugin executor streams through the same translation instead of returning the channel or payload unchanged. Formats without a same-format translator keep the existing behavior via the TranslateStream fallback, which returns the payload unchanged, and the OpenAI Responses usage-details fixup still runs after translation.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-01 06:55:20 +00:00
sususu
fd02b720e6 fix(proxy): stamp keepalive on uTLS dialers, rebind stale compat executors, and close retired pools outside fence lock 2026-11-01 14:20:38 +08:00
Luis Pater
a8dbebabdf feat(pluginhost): allow plugins to register multiple OAuth login entries
- Add Capabilities.AuthProviders and MultiAuthProvider (Identifiers() []string) in sdk/pluginapi, bump sdk/pluginabi.SchemaVersion to 10, and forward AuthProviders in sdk/pluginhost
- Extend internal/pluginhost to register, expose, and route multiple OAuth login identifiers per plugin across StartLogin, PollLogin, RefreshAuth, ParseAuths, and ExchangeCallback, while preserving per-credential oauth_provider/portal attribution for shared credential providers
- Expose oauth_providers alongside primary oauth_provider in RegisteredPluginInfo and GET /v0/management/plugins, and support target-credential re-login (StartOAuthV8) across sibling portals

Closes: #7126
2026-10-31 20:20:16 +08:00
Luis Pater
bc81923ba6 feat(pluginhost): allow model registrars to publish models for multiple providers
- Add ProviderModels, Registrations, MultiProviderModels, and SchemaVersionMultiProviderModels so a single plugin can register model catalogs across multiple providers while preserving single-provider compatibility.
- Track per-plugin provider sets and multi-provider model registrations in the plugin host for catalog aggregation, per-auth model discovery matching, and targeted unload cleanup.

Closes: #7115
2026-10-30 14:38:48 +08:00
Luis Pater
0fe38224e5 feat(pluginhost): support raw request body byte-range patching
Existing request interceptors wrap the full request body in a JSON RPC envelope with Base64 encoding and skip subsequent duplex WebSocket business frames, causing ~3.33x memory and CPU amplification when rewriting small fields such as Codex `<timezone>` and `<current_date>` in large contexts.

- Add schema v8 raw request body patch methods (`request.patch_body_before` and `request.patch_body_after`) and capabilities (`request_interceptor_patch_body_before/after`, `request_body_patcher_before/after`) that pass raw `Body []byte` directly across the C ABI without JSON/Base64 request wrapping
- Add `RequestBodyEdit`, `RequestBodyPatchResponse`, and `RequestBodyPatcher` in `sdk/pluginapi` with single-pass host splicing, bounds/overlap validation, `json.Valid` verification, no-op original body reuse, and sequential multi-plugin chaining
- Eliminate redundant full-body slice clones in handler/conductor request interceptor application paths
- Run before-auth and after-auth request interceptors on subsequent duplex WebSocket `response.create`, `response.append`, and `response.steer` messages

Closes: #7072
2026-10-28 21:38:42 +08:00
Luis Pater
e324e4814c perf(pluginhost): allow frontend auth providers to opt out of request body delivery
- Let schema v7+ frontend auth providers opt out of receiving request bodies via frontend_auth_provider_omit_body / frontend_auth_omit_body so metadata-only auth plugins skip reading, decoding, cloning, and marshaling the request body during authentication.
- Avoid cloning the buffered request body slice before JSON serialization when invoking RPC-backed frontend auth providers that still inspect the body.

Closes: #7071
2026-10-28 20:42:52 +08:00
Luis Pater
6fe654bfc6 perf(pluginhost): gate request interceptor body delivery behind schema v7 opt-out
- Bump plugin SchemaVersion to 7 and let request interceptors declare per-phase body opt-out via request_interceptor_omit_body_before/after capabilities, so metadata-only plugins no longer pay for body cloning, Base64 encoding, and cross-ABI copies.
- Skip the body clone in interceptRequest for schema v7+ plugins that opt out of the current phase while preserving chain state, blind body replacement, and termination semantics.

Closes: #6998
2026-10-26 16:47:13 +08:00
Luis Pater
e5321f535c fix(auth,pluginapi,usage): share per-selection ID between Scheduler.Pick and UsageRecord
- generate a unique selection_id for each handled Scheduler.Pick decision and freeze it into the execution context and UsageReporter
- propagate SelectionID through core usage records and pluginapi.UsageRecord while clearing stale IDs on unhandled, rejected, Home, and credits fallback paths

Closes: #6988
2026-10-26 03:25:42 +08:00
Luis Pater
27f3abfb70 feat(management): support session-scoped OAuth proxy with per-account persistence (#6973) 2026-10-25 22:17:45 +08:00
Luis Pater
e48d780f9b fix(plugin): preserve caller scope for replayed Claude OAuth MCP tool aliases
- Expose the opaque caller scope handle on request interception structs and accept it on HostModelExecutionRequest and internal model execution requests so replayed executions retain caller-scoped metadata without exposing client API keys.
- Resolve Claude MCP tool alias secrets from caller_scope metadata before falling back to hashed context API keys so plugin replays reproduce the original upstream tool names and derived session identities.

Closes: #6961
2026-10-25 11:35:02 +08:00
Luis Pater
2bb6ac6faa fix(lint): resolve go vet lostcancel and static analysis warnings from v8.0.42
- Defer context cancellation in TestCancelableConnClosesUnderlyingTransportWhenCloseRacesCancel to satisfy go vet lostcancel across all control flow paths.
- Remove the unused streamBridgeStream.close wrapper left behind after the closeWithError refactor in internal/pluginhost.
- Annotate shared "gin" string context keys in TestIssue6825SDKCallerReplayIsolation with nolint:staticcheck directives.

Closes: #6953
2026-10-25 02:10:05 +08:00
Luis Pater
c9af5290a6 fix(pluginhost): run canonical thinking pipeline before plugin execution
- Apply canonical thinking normalization, suffix stripping, and plugin model metadata fallback in prepareExecutorCall across Execute, ExecuteStream, and CountTokens.
- Resolve plugin-registered ThinkingApplier by provider key before format fallback and validate unknown thinking suffixes on non-native-Responses models.
- Run thinking normalization before NewPayloadFinalizer so user payload rules act as the final host-side mutation.

Closes: #6940
2026-10-24 21:38:42 +08:00
Luis Pater
e42eee6e1c fix(pluginhost): apply user payload rules to plugin executor requests
- Apply helps.NewPayloadFinalizer once in prepareExecutorCall after translating requests to the plugin input format so Execute, ExecuteStream, and CountTokens honor configured payload rules.
- Match rules on the suffix-free model name while preserving the plugin request model, canonicalize source format aliases, and use the request root for Antigravity envelopes.

Closes: #6939
2026-10-24 21:10:45 +08:00
Luis Pater
35e834da24 feat(pluginabi): carry retry-after metadata from plugin executor errors
- Add optional retry_after_seconds to pluginabi.Error and preserve it in rpcError and structured stream error callbacks.
- Expose RetryAfter and SafeResponseHeaders on rpcError with duration overflow clamping so auth cooldowns and HTTP responses honor upstream retry hints.
- Allow auth.SafeResponseHeaders to extract Retry-After headers from errors implementing SafeResponseHeaders.

Closes: #6937
2026-10-24 20:42:20 +08:00
Luis Pater
44d1ddf538 fix(pluginhost): translate plugin count_tokens replies as token counts
- Route cross-format plugin executor count_tokens responses through sdktranslator.TranslateTokenCount when a valid token count and registered token-count transformer exist.
- Add sdktranslator.HasTokenCountTransformer and fallback handling so same-format replies, unrecognized payloads, and custom response translators retain existing behavior.

Closes: #6938
2026-10-24 20:42:19 +08:00
Luis Pater
9d08f0d430 fix(pluginhost): strip credential headers across cross-origin redirects
- Strip standard and credential-like headers from plugin HTTP callback requests whenever a redirect chain changes scheme, host, or port across both default and wire-profile client paths.
- Normalize default HTTP/HTTPS ports when comparing redirect origins and delete matching header map keys directly to handle non-canonical header casing across multi-hop redirects.

Closes: #6936
2026-10-24 20:42:17 +08:00
Luis Pater
13874f1f84 fix(pluginhost): pass decoded request body to frontend auth plugins
- Add DecodedBody to FrontendAuthRequest and populate it on routes decoded by ReadRequestBody while preserving raw Body and Headers.
- Enforce pre-auth zstd window, decoded size, coding layer, and concurrency bounds, keeping decode slots held until guarded RPC calls complete.
- Add regression tests covering zstd decoding, route filtering, size limits, RPC marshaling, and canceled RPC slot lifecycle.

Closes: #6886
2026-10-23 01:17:43 +08:00
Luis Pater
a014ba0e49 test(pluginhost,handlers): fix flaky races in plugin load and stream cancel tests
- Add a loadCleanupDoneHook callback in pluginhost.Host so canceled plugin load tests wait until the in-flight load token is cleared after client shutdown.
- Drain dataChan after canceling the context in TestHandlerPluginExecutorPublishesStreamCancellation before closing the chunk channel to avoid racing ctx.Done() against normal stream EOF.

Closes: #6885
2026-10-23 01:14:58 +08:00
Luis Pater
07b5a7a1ca feat(usage): report effective outbound service tier after payload rules
- Capture the post-translation, post-payload-rule service tier on UsageReporter and propagate EffectiveServiceTier through SDK usage records, plugin usage adapters, and Redis usage queue payloads.
- Ensure executors record translated request metadata after final payload configuration rules so server-side service_tier overrides are accurately reported alongside client and response tiers.

Closes: #6873
2026-10-22 21:05:27 +08:00
Luis Pater
b9bb031dcb fix(openai): reauthorize responses websocket turns and support denied status
- Re-run AccessManager authentication before each responses websocket turn and duplex continuation using a cloned POST request with handshake headers stripped.
- Add AuthErrorCodeDenied and NewDeniedError in sdk/access so terminal provider refusals preserve their HTTP status and stop the provider chain.
- Add DenyStatusCode and DenyMessage to pluginapi.FrontendAuthResponse and map explicit plugin denials in accessAdapter.Authenticate.

Closes: #6843
2026-10-22 03:41:06 +08:00
Luis Pater
4846a2893b feat(pluginhost): add host.auth.models callback for per-credential model lookup
- Define MethodHostAuthModels and HostAuthModels request/response types in pluginabi and pluginapi so plugins can query registered models by credential.
- Implement callHostAuthModels in pluginhost to return registry models for all or filtered credentials in the auth manager, including config-backed API keys.

Closes: #6815
2026-10-21 02:21:22 +08:00
Luis Pater
1ad175b637 feat(auth): snapshot plugin scheduler and release host lock during executor registration
- Snapshot plugin scheduler and preferences atomically to prevent deadlocks and data races during auth picking.
- Release host lock before notifying executor manager during adapter registration to prevent lock contention.

Closes: #6744
2026-10-19 02:00:22 +08:00
Luis Pater
2422c6b0f5 Merge pull request #6737 from router-for-me/plugins
fix(cliproxy): apply excluded models to plugin models
2026-10-18 21:05:44 +08:00
Luis Pater
66c2758159 feat(pluginhost): remove max line buffer size limit in stream executor to preserve usage telemetry
- Remove `maxLineBufferSize` constant and associated byte-length checks in plugin executor SSE stream processing.
- Prevent premature flushing and dropping of usage metrics for long SSE lines containing response completion payloads.

Closes: #6725
2026-10-18 17:41:30 +08:00
Luis Pater
a7608a8a25 feat(pluginhost): preserve auth identity and model registration for relative auth paths
- Update `authIDForPath` and path resolution logic to consistently handle relative paths within the auth directory.
- Add robust relative path checking to prevent path mismatch issues during credential saves and model lookups.

Closes: #6722
2026-10-18 17:30:27 +08:00
hkfires
adc436ff87 fix(pluginhost): bind catalog-only plugin models to credentials
Stop RegisterModels from publishing a synthetic plugin client for
plugins without an executor, which advertised their models without
any routable credential and bypassed per-auth model exclusions.

Retain the static catalog only for executor arbitration and
per-auth registration, so public availability now follows active
credentials and their exclusions. Reserve native provider models
before plugin arbitration to preserve native priority, and remove
the now unused model client commit path.
2026-10-18 16:12:11 +08:00
Luis Pater
ad9e456d4a feat(claude): support between_tools thinking disable type and adaptive fallbacks
- Add `DisableType` support to plugin host adapters and registry mappings.
- Route disabled thinking to `between_tools` for models like Claude Sonnet 5.5.
- Fall back to low-effort adaptive thinking for models that reject disabled states.

Closes: #6698
2026-10-17 13:56:34 +08:00
Luis Pater
355fd10e76 feat(pluginhost): add content-addressed shadow copies for dynamic library loading
Closes: #6672
2026-10-16 12:04:22 +08:00
Rat0323
50eaed0d16 feat(pluginapi): expose config field defaults 2026-10-14 20:23:34 +08:00
Luis Pater
fdbc610303 feat(auth): enhance plugin auth handling with multi-auth support and improved state management
- Add support for handling multiple auth records from a single file.
- Preserve plugin-disabled states and prioritize existing auth states when updating.
- Unregister stale auths and associated models to maintain consistency.
- Introduce dynamic auth ID assignment and file-based deduplication for better reliability.
- Improve metadata normalization, priority handling, and file path matching.

Closes: #6551
2026-10-12 20:51:15 +08:00
Luis Pater
dd7b433492 feat(server): support max-request-body-bytes request body limit
Closes: #6550
2026-10-12 20:21:50 +08:00
hkfires
0c7084019b fix(management): resolve v8 plugin quota contract gaps
Expose quota_plugin_id on credential entries using the host's two-pass selection precedence, excluding fused plugins and selecting healthy alternatives.

Stop advertising declarative quota_probe support in v8 while preserving v0 behavior. Add regression tests for selection precedence, plugin fusion, and version-specific quota metadata.

Fixes #6519
2026-10-12 15:50:00 +08:00
Luis Pater
37fe2608ee feat(usage): propagate access provider and native key metadata to usage records
- Inject API key, access provider, and native key flags into the request context during authentication
- Add `IsNativeKey` and `AccessProvider` fields to usage records, plugin API types, and redis queue payloads
- Provide context helper functions and automatic fallback resolution in the usage manager and reporter

Closes: #6509
2026-10-10 22:16:00 +08:00
Luis Pater
67465884ca fix(pluginhost): detach unselected plugins on config apply
- Automatically detach and shut down plugins that are disabled or unselected during configuration reload
- Unload all active plugins when the plugin system is globally disabled

Closes: #6471
2026-10-09 04:04:08 +08:00
이대희
3b69068e6c fix(translator): stop dropping attachments and empty turns
An attachment a translator could not represent was dropped without a word, and
a turn whose only content was that attachment went upstream as an empty
messages, parts, or input array. The model then answered as if nothing was
attached, or the upstream rejected a request that never named the attachment.

A base64 document now reaches OpenAI as a file part. A file the target cannot
receive, such as container_upload, an OpenAI file_id, or input_audio sent to
Claude, is reported by name so the route answers 400 instead of forwarding an
empty turn. Text beside it still travels.

One rule, ErrIfNothingLeft, decides when to refuse, and RegisterCheckedRequest
carries the refusal on the request envelope. Every executor that translates
checks it before calling upstream. The exported converters keep their []byte
signature, so no caller or sibling test had to change.
2026-10-07 19:21:32 +09:00