Skip to main content

Host

Struct Host 

Source
pub struct Host { /* private fields */ }
Expand description

The plugin host. Cheap to clone.

Implementations§

Source§

impl Host

Source

pub fn host_config_summary(&self) -> HostConfigSummary

Go hostConfigSummary.

Source

pub fn auth_provider_identifiers(&self) -> Vec<String>

Go AuthProviderIdentifiers.

Source

pub fn auth_provider_record(&self, provider: &str) -> Option<Record>

Go authProviderRecord: the first active auth provider for provider.

Source

pub fn has_auth_provider(&self, provider: &str) -> bool

Go HasAuthProvider.

Source

pub fn parse_auths(&self, req: AuthParseRequest) -> ParseAuthsResult

Go ParseAuths. With a provider, only that provider’s plugin is asked; otherwise every auth provider in order until one handles the material or fails. Blocking: credential loading is synchronous, as Go’s synthesizer is.

Source

pub async fn start_login( &self, provider: &str, base_url: &str, metadata: Metadata, scope: &RequestScope, ) -> Result<Option<AuthLoginStartResponse>, CallError>

Go StartLogin: Ok(None) when no plugin owns provider.

Source

pub async fn poll_login( &self, provider: &str, state: &str, metadata: Metadata, scope: &RequestScope, ) -> Result<Option<AuthLoginPollResponse>, CallError>

Go PollLogin.

Source

pub async fn refresh_auth( &self, auth: &AuthView, scope: &RequestScope, ) -> Result<Option<PluginAuth>, CallError>

Go RefreshAuth: Ok(None) when no plugin owns the credential’s provider.

Source

pub async fn frontend_auth_providers( &self, ) -> (Vec<(String, String)>, Option<String>)

Go RegisterFrontendAuthProviders: (access provider key, plugin ID) for each active frontend auth provider in order, and the exclusive key (highest priority, then lowest ID) if any. Keys are plugin:<id>:<identifier>; identifiers are asked on every call, as Go does.

Source

pub async fn frontend_auth_identifier(&self, plugin_id: &str) -> Option<String>

Go accessAdapter.Identifier for a plugin: plugin:<id>:<identifier>, asking the plugin each time. None when the plugin is gone or answers empty.

Source

pub async fn frontend_authenticate( &self, plugin_id: &str, req: &FrontendAuthRequest, ) -> Option<FrontendAuthOutcome>

Go accessAdapter.Authenticate: None is “not handled” (unavailable plugin, RPC failure, or not authenticated); the caller tries the next provider.

Source§

impl Host

Source

pub fn auth_parser(&self) -> Arc<dyn PluginAuthParser> ⓘ

This host as Go’s PluginAuthParser for credential loading (RegisterPluginAuthParser(pluginHost)), held weakly. From then on, this host keeps cpa-core’s auth-parser flag current, so without an auth provider loading skips the parser after one atomic load.

Source§

impl Host

Source

pub async fn register_command_line_flags( &self, builtin: &dyn Fn(&str) -> bool, ) -> Vec<CliFlag>

Go RegisterCommandLineFlags: asks every active command-line plugin for its flags and keeps valid ones that clash neither with a built-in flag (builtin) nor with a higher-priority plugin. Returns the flags accepted now.

Source

pub fn command_line_flag(&self, name: &str) -> Option<CliFlag>

A registered plugin flag.

Source

pub fn set_command_line_flag(&self, name: &str, raw: &str) -> Result<(), String>

Go commandLineFlagValue.Set.

Source

pub fn has_triggered_command_line_flags(&self) -> bool

Go HasTriggeredCommandLineFlags.

Source

pub async fn execute_command_line( &self, program: &str, args: &[String], config_path: &str, builtin: &[(String, String)], persist: &dyn Fn(PluginAuth) -> Result<String, String>, ) -> (i32, bool, Vec<Output>)

Go ExecuteCommandLine. builtin lists the host’s own flags as (name, current value); persist saves an auth a command produced and returns its path. Returns the exit code, whether any plugin ran, and the output to write in order.

Source§

impl Host

Source

pub async fn executor_provider(&self, record: &Record) -> Option<String>

Go executorProvider: the provider the plugin registered models for, else its executor.identifier, lowercased.

Source

pub async fn executor_adapter(&self, plugin_id: &str) -> Result<Adapter, String>

Go executorAdapterForPlugin.

Source

pub async fn executor_plugin_ready( &self, plugin_id: &str, source_format: &str, ) -> bool

Go executorPluginReady: an active, unfused executor plugin that serves static models and can take a request in source_format.

Source

pub async fn executor_execute( &self, adapter: &Adapter, req: &ExecutorRequest, scope: &RequestScope, ) -> Result<ExecutorResponse, CallError>

executor.execute with a callback context.

Source

pub async fn executor_count_tokens( &self, adapter: &Adapter, req: &ExecutorRequest, scope: &RequestScope, ) -> Result<ExecutorResponse, CallError>

executor.count_tokens with a callback context.

Source

pub async fn executor_http_request( &self, adapter: &Adapter, req: &ExecutorHttpRequest, scope: &RequestScope, ) -> Result<ExecutorHttpResponse, CallError>

executor.http_request with a callback context.

Source

pub async fn executor_execute_stream( &self, adapter: &Adapter, req: &ExecutorRequest, scope: &RequestScope, ) -> Result<PluginStream, CallError>

Go rpcPluginAdapter.ExecuteStream: opens a host stream and a callback context, sends stream_id and host_callback_id. Inline chunks in the answer are the whole stream; otherwise chunks arrive through host.stream.emit until the plugin closes the stream, and the callback context stays open until then.

Source§

impl Host

Source

pub fn new() -> Self

Source

pub fn with_loader(loader: Arc<dyn Loader>) -> Self

Source

pub fn snapshot(&self) -> Arc<Snapshot> ⓘ

Source

pub fn config(&self) -> Option<Arc<Config>>

The config last applied.

Source

pub fn active_records(&self) -> Vec<Record>

Records still current: a record whose plugin was unloaded or replaced since the snapshot was taken is skipped (Go activeRecordsFromSnapshot).

Source

pub fn current_records(&self, snapshot: &Snapshot) -> Vec<Record>

Go activeRecordsFromSnapshot: the snapshot’s records that are still current.

Source

pub fn live(&self, record: &Record) -> bool

Whether a record may be called right now: not fused and still current. Go checks this at every call, after earlier plugins in the same loop have run.

Source

pub fn record_current(&self, record: &Record) -> bool

Go recordCurrent / pluginIdentityCurrent.

Source

pub fn is_fused(&self, id: &str) -> bool

Source

pub fn fuse(&self, id: &str, what: &str, panic: &str)

Go fusePlugin: a host-side panic while serving the plugin disables it until its file changes.

Source

pub fn plugin_loaded(&self, id: &str) -> bool

Go PluginLoaded: a library for id is still loaded (active or retired).

Source

pub fn plugin_busy(&self, id: &str) -> bool

Go PluginBusy: loaded or still loading.

Source

pub fn plugin_registered(&self, id: &str) -> bool

Go PluginRegistered: active in the current snapshot.

Source

pub fn registered_plugins(&self) -> Vec<RegisteredPluginInfo>

Go RegisteredPlugins.

Source

pub async fn apply_config(&self, cfg: Arc<Config>)

Go ApplyConfig.

ponytail: runs to completion on its own task even if the caller stops waiting, so a dropped future can never strand a half-loaded plugin; Go instead aborts on context cancellation and rolls the load back. Add cancellation with rollback if shutdown latency during a slow plugin.register ever matters.

Source

pub async fn unload_plugin(&self, id: &str, wait: Option<Duration>) -> bool

Go UnloadPluginContext: detach id from the runtime, then close every loaded instance of it, waiting up to wait for running calls.

Source

pub async fn unload_plugin_until( &self, id: &str, cancel: &CancellationToken, ) -> bool

Go UnloadPluginContext with a cancellable context: cancelling cancel stops waiting for the apply lock (false) or for the plugin to shut down, and releases the lock; the shutdown itself still completes on its own thread.

Source

pub async fn shutdown_all(&self, wait: Option<Duration>)

Go ShutdownAllContext.

Source

pub fn record(&self, id: &str) -> Option<Record>

Looks up an active, unfused record by plugin ID.

Source

pub async fn call<T: GoJson, R: GoJson>( &self, record: &Record, method: &str, request: &R, ) -> Result<T, CallError>

One typed RPC to an active plugin, fusing it on a host-side panic.

Source

pub async fn call_with_callback<T: GoJson, R: GoStruct>( &self, record: &Record, method: &str, request: &R, scope: &RequestScope, ) -> Result<T, CallError>

One RPC that lets the plugin call back: opens a callback context for the record’s instance, sends its ID as host_callback_id, and closes it when the call returns (Go openHostCallbackContext around adapter calls).

Source

pub fn call_blocking<T: GoJson, R: GoJson>( &self, record: &Record, method: &str, request: &R, ) -> Result<T, CallError>

Host::call for synchronous callers; see GuardedClient::call_blocking.

Source

pub fn call_with_callback_blocking<T: GoJson, R: GoStruct>( &self, record: &Record, method: &str, request: &R, scope: &RequestScope, ) -> Result<T, CallError>

Host::call_with_callback for synchronous callers.

Source

pub fn open_callback( &self, record: &Record, scope: &RequestScope, ) -> ContextGuard

Opens a callback context for record’s instance.

Source

pub async fn call_raw<T: GoJson>( &self, record: &Record, method: &str, request: Vec<u8>, ) -> Result<T, CallError>

One RPC with a pre-encoded request.

Source§

impl Host

Source

pub fn set_auth_manager(&self, manager: Option<Arc<dyn AuthManager>>)

Go SetAuthManager.

Source§

impl Host

Source

pub fn set_model_executor(&self, executor: Option<Arc<dyn ModelExecutor>>)

Source§

impl Host

Source

pub async fn intercept_request_before_auth( &self, req: RequestInterceptRequest, skip: &str, scope: &RequestScope, ) -> RequestInterceptResponse

Go InterceptRequestBeforeAuth[Except].

Source

pub async fn intercept_request_after_auth( &self, req: RequestInterceptRequest, skip: &str, scope: &RequestScope, ) -> RequestInterceptResponse

Go InterceptRequestAfterAuth[Except].

Source

pub fn complete_request( &self, completion: RequestCompletion, skip: &str, scope: &RequestScope, )

Go CompleteRequest[Except]: one asynchronous request.complete per lifecycle plugin; delivery never blocks the response.

Source

pub async fn intercept_response( &self, req: ResponseInterceptRequest, skip: &str, scope: &RequestScope, ) -> ResponseInterceptResponse

Go InterceptResponse[Except]: successful non-streaming responses.

Source

pub async fn intercept_stream_chunk( &self, req: StreamChunkInterceptRequest, skip: &str, scope: &RequestScope, ) -> StreamChunkInterceptResponse

Go InterceptStreamChunk[Except]. Payload chunks (ChunkIndex >= 0) omit request bodies for schema 3+ and history for schema 5+; the header-init call always carries them. A dropped chunk ends the chain.

Source

pub async fn observe_websocket_response_event( &self, event: WebSocketResponseEvent, skip: &str, scope: &RequestScope, )

Go ObserveWebSocketResponseEvent[Except]: synchronous, in order, errors logged.

Source

pub fn has_request_interceptors(&self) -> bool

Go HasRequestInterceptors.

Source

pub fn has_stream_interceptors(&self) -> bool

Go HasStreamInterceptors.

Source

pub fn has_websocket_response_observers(&self) -> bool

Go HasWebSocketResponseObservers.

Source

pub fn has_response_interceptors(&self) -> bool

Go HasResponseInterceptors equivalent for the handler’s fast path.

Source

pub fn has_request_lifecycle_plugins(&self) -> bool

Go HasRequestLifecyclePlugins equivalent.

Source

pub fn stream_chunk_payload_includes_request_body(&self) -> bool

Go StreamChunkPayloadIncludesRequestBody: some stream interceptor speaks schema < 3.

Source

pub fn stream_chunk_payload_includes_history(&self) -> bool

Go StreamChunkPayloadIncludesHistory: some stream interceptor speaks schema < 5.

Source§

impl Host

Source

pub async fn register_management_routes(&self, reserved: &HashSet<String>)

Go RegisterManagementRoutes: asks every active plugin with the capability for its routes and rebuilds both tables. reserved holds built-in METHOD /path keys.

Source

pub fn management_routes(&self) -> Vec<RouteRecord>

Plugin management routes currently registered, by key.

Source

pub fn resource_routes(&self) -> Vec<ResourceRecord>

Source

pub fn has_management_route(&self, method: &str, path: &str) -> bool

Whether Self::serve_management would call a plugin for this method and decoded path (Go checks this before reading the body).

Source

pub async fn serve_management(&self, req: Inbound) -> Option<Reply>

Go ServeManagementHTTP: None when no plugin route matches.

Source

pub async fn serve_resource(&self, req: Inbound) -> Option<Reply>

Go ServeResourceHTTP: GET only, no body forwarded.

Source§

impl Host

Source

pub async fn register_models(&self)

Go v8.0.35 RegisterModels: collects the static models of every model provider or registrar whose executor scope allows static models. Nothing is published here: catalog-only models reach the registry only through credentials of their provider (Self::models_for_provider), executor plugins’ through Self::register_executors.

Source

pub async fn models_for_auth( &self, auth: &AuthView, scope: &RequestScope, ) -> AuthModelResult

Go ModelsForAuth: the first model provider for the credential’s provider (its auth provider’s identifier, else its registered or executor provider).

Source

pub async fn register_executors( &self, native_provider: &(dyn Fn(&str) -> bool + Sync), model_providers: &(dyn Fn(&str) -> Vec<String> + Sync), ) -> Option<ExecutorChanges>

Go RegisterExecutors. native_provider says whether a built-in executor serves a provider; model_providers lists the providers registered for a model ID. A plugin executor claims its provider only when no built-in executor does, and only models no built-in provider serves; the first plugin (by priority) wins a model and a provider. None when the plugin set changed meanwhile (Go commitExecutorState then keeps the previous state).

Source

pub fn models_for_provider(&self, provider: &str) -> Vec<ModelInfo>

Go ModelsForProvider.

Source

pub fn provider_models(&self) -> BTreeMap<String, Vec<ModelInfo>>

Every provider’s plugin models after the last Self::register_executors.

Source

pub fn executor_providers(&self) -> HashSet<String>

The plugin executing provider after the last Self::register_executors.

Source

pub async fn has_executor_candidate_provider(&self, provider: &str) -> bool

Go HasExecutorCandidateProvider.

Source§

impl Host

Source

pub fn quota_provider_identifiers(&self) -> Vec<String>

Go QuotaProviderIdentifiers.

Source

pub async fn quota_providers(&self) -> Vec<QuotaProviderInfo>

Go QuotaProviders.

Source

pub async fn quota_provider_plugin_ids(&self) -> HashMap<String, String>

Go QuotaProviderPluginIDs: each provider key to the plugin Self::quota_provider_record would select for it, with its two-pass precedence. A plugin fused while describing loses its keys to the next candidate.

Source

pub async fn quota_provider_record(&self, provider: &str) -> Option<Record>

Go quotaProviderRecord.

Source

pub fn quota_provider_record_by_plugin(&self, plugin_id: &str) -> Option<Record>

Go quotaProviderRecordByPlugin.

Source

pub async fn has_quota_provider(&self, provider: &str) -> bool

Go HasQuotaProvider.

Source

pub fn has_quota_provider_for_plugin(&self, plugin_id: &str) -> bool

Go HasQuotaProviderForPlugin.

Source

pub async fn describe_quota( &self, plugin_id: &str, ) -> Result<Option<QuotaDescribeResponse>, CallError>

Go DescribeQuota: by plugin ID, else by provider.

Source

pub async fn fetch_quota( &self, req: QuotaFetchRequest, auth: Option<&AuthView>, scope: &RequestScope, ) -> Result<Option<QuotaFetchResponse>, CallError>

Go FetchQuota: by provider, else by plugin ID. auth is the credential behind req.auth_index when it resolves (Go authPhysicalJSONByIndex).

Source

pub async fn fetch_quota_by_plugin( &self, plugin_id: &str, req: QuotaFetchRequest, auth: Option<&AuthView>, scope: &RequestScope, ) -> Result<Option<QuotaFetchResponse>, CallError>

Go FetchQuotaByPlugin.

Source

pub async fn reset_quota( &self, req: QuotaResetRequest, auth: Option<&AuthView>, scope: &RequestScope, ) -> Result<Option<QuotaResetResponse>, CallError>

Go ResetQuota.

Source

pub async fn reset_quota_by_plugin( &self, plugin_id: &str, req: QuotaResetRequest, auth: Option<&AuthView>, scope: &RequestScope, ) -> Result<Option<QuotaResetResponse>, CallError>

Go ResetQuotaByPlugin.

Source§

impl Host

Source

pub fn has_scheduler(&self) -> bool

Go HasScheduler.

Source

pub fn scheduler_wants_across_priorities(&self) -> bool

Go SchedulerWantsAcrossPriorities.

Source

pub async fn pick_auth( &self, req: SchedulerPickRequest, ) -> Result<Option<SchedulerPickResponse>, CallError>

Go PickAuth: Ok(None) lets the built-in scheduler choose (no scheduler, not handled, or an invalid answer); Err is the plugin’s RPC failure, which Go surfaces as a selection error.

Source

pub fn has_model_routers(&self, skip: &str) -> bool

Go HasModelRouters[Except].

Source

pub async fn route_model( &self, req: ModelRouteRequest, skip: &str, available_providers: &[String], scope: &RequestScope, ) -> Option<ModelRouteResponse>

Go RouteModel[Except]: the first router (by priority) that handles the request with a usable target. available_providers is the providers that currently have credentials (Go AuthManager.AvailableProviders); a provider target must be one of them. executor_ready reports whether a plugin executor can take the request (format negotiation, see crate::executor).

Source§

impl Host

Source

pub fn normalize_request( &self, from: &str, to: &str, model: &str, body: Bytes, stream: bool, ) -> Bytes

Go NormalizeRequest: every request normalizer, chained.

Source

pub fn translate_request( &self, from: &str, to: &str, model: &str, body: &Bytes, stream: bool, ) -> Option<Bytes>

Go TranslateRequest: the first translator that answers wins.

Source

pub fn normalize_response_before( &self, t: &ResponseTransform<'_>, body: Bytes, ) -> Bytes

Go NormalizeResponseBefore: chained, before native translation.

Source

pub fn translate_response( &self, t: &ResponseTransform<'_>, body: &Bytes, ) -> Option<Bytes>

Go TranslateResponse: the first translator that answers wins.

Source

pub fn normalize_response_after( &self, t: &ResponseTransform<'_>, body: Bytes, ) -> Bytes

Go NormalizeResponseAfter: chained, after translation.

Source

pub fn has_response_translator(&self) -> bool

Go hasResponseTranslator.

Source

pub fn thinking_provider(&self, provider: &str) -> Option<String>

The plugin that applies thinking for provider, if any.

Source

pub fn apply_thinking( &self, provider: &str, model: ModelInfo, config: ThinkingConfig, body: Bytes, scope: &RequestScope, ) -> Bytes

Go thinkingAdapter.Apply: the plugin’s body, or body unchanged on any failure.

Source

pub fn publish_usage(&self, record: UsageRecord)

Go usageAdapter.HandleUsage for every usage plugin, in the background. The caller resolves session fields the way the adapter does (see usage_session_ids); failures are logged at debug level.

Source

pub fn has_usage_plugins(&self) -> bool

Whether any usage plugin is active.

Source§

impl Host

Source

pub fn translator_hooks(&self) -> Arc<dyn Hooks> ⓘ

This host as Go’s translator.PluginHooks (sdktranslator.SetPluginHooks(host)). It holds the host weakly, so installing it process-wide keeps nothing alive. From then on, this host keeps cpa-translate’s hook flag current, so with no translator plugin the registry skips the hooks after one atomic load.

Trait Implementations§

Source§

impl Clone for Host

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Host

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PluginRuntime for Host

Source§

fn plugin_busy(&self, id: &str) -> bool

Loaded or still loading.
Source§

fn unload_plugin<'a>( &'a self, id: &'a str, cancel: &'a CancellationToken, ) -> BoxFuture<'a, bool>

Detaches and closes the plugin; false when nothing was unloaded. Cancelling cancel stops waiting for it (Go UnloadPluginContext).
Source§

fn plugin_registered(&self, id: &str) -> bool

Active in the current snapshot.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Host

§

impl !UnwindSafe for Host

§

impl Freeze for Host

§

impl Send for Host

§

impl Sync for Host

§

impl Unpin for Host

§

impl UnsafeUnpin for Host

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more