docs/internal/provider-exports.md
Provider-owned host exports
pkg/service/agent/provider_host*.go owns provider export eligibility, catalog
serialization, admission and upstream policy. The daemon publishes user-config
snapshots, lists the resulting macros and dispatches calls to pinned export
routes. It does not select upstream URLs or inject provider credentials.
Minimal Muse setup
Keep the existing native Muse login on the trusted host. Add an external provider to the host's ordinary user config, using the installed bridge and launcher:
| 1 | providers: |
| 2 | muse: |
| 3 | type: external |
| 4 | remote_eligible: true |
| 5 | command: /absolute/path/to/ezagent-muse-code-bridge |
| 6 | options: |
| 7 | muse_command: /home/developer/.local/bin/muse |
| 8 | models: |
| 9 | - name: muse-spark-1.3 |
On a consumer with access to that daemon's socket, save just the remote connection and the model you want. No LLM login or auth copy belongs on the consumer:
| 1 | providers: |
| 2 | host: |
| 3 | type: remote |
| 4 | socket: /absolute/path/to/host-runtime/ez-agent/ez-agent.sock |
| 5 | models: |
| 6 | - name: muse/muse-spark-1.3 |
| 7 | default_model: host/muse/muse-spark-1.3 |
The configurator's remote-provider model checklist can save the same selection. Keep each daemon's XDG config, state and runtime separate when testing on one machine. If Muse needs its normal native config location for login, restore only that location in a host-side native launcher wrapper, not the daemon's runtime. Use live Muse acceptance for the recurring two-response check, prerequisites and failure diagnosis. For a different machine, use the owned SSH forward instead of manually copying auth or arranging a second provider service.
Registration and lifetime
Each locally owned remote_eligible provider has one visible macro named
tunnel.llmprovider.<provider>, with MacroInfo.Internal: true. There is no
singleton and no per-model export ACL. Private providers and remote connection
descriptors have no export macro. Provider changes create a new generation;
withdrawal cancels and joins active tunnel owners, including upgraded sockets.
Old admitted routes cannot bind to a replacement generation.
The namespace includes the bare tunnel.llmprovider name and every dotted
descendant. Config rejects supplied names in services and default triggers.
Runtime announce, launched-service registration, registry config sync, metadata
updates and metadata fetching filter reserved macro claims without dropping
unrelated capabilities. Internal is a visibility hint, not authorization.
Socket reachability remains the trust boundary. Anyone with access to the host socket has the full daemon API, not a provider-only API. Do not forward this socket into an environment that should not have full daemon access.
Application payload contract, version 1
These are strings inside existing macro parameter/result fields. They do not add JSONL envelopes, fields, or lifecycle events.
| Parameter | Result |
|---|---|
IFO | IFO,Remote LLM provider tunnel,llmprovider,1 |
LIST | One bounded JSON catalog for the macro's provider |
INIT,<id>,llmprovider,<provider>,<type> | START,<id> |
Control rows use canonical EzAgent CSV, not RFC CSV. INIT must match both the provider name bound to the macro and its host-configured type. Unknown or withdrawn routes, mismatched types, noncanonical rows and exhausted admission fail before START. After START, the existing tunnelpipe rows and drain rules apply unchanged. The caller connection owns its own stream IDs; identical IDs on different connections cannot attach to one another. All providers and connections share a host-wide 128-stream budget. A full budget rejects new work without evicting other work.
LIST contains RemoteProviderMetadata from pkg/service/config/remote.go:
name, type, models, first_output_timeout and stream_idle_timeout.
Models carry configured names, literal alias targets, effective context/token
limits, thinking levels, ZDR support, access-program selections and Responses
capabilities. WebSocket and prompt-cache defaults are resolved on the host.
HTTP provider timeouts are effective positive Go duration strings. External
provider timeouts preserve the host's sparse configuration: an empty or omitted
phase is unspecified, while an explicit value must be positive. Consumers defer
external default selection until the bridge hello identifies the provider. The
exact name ezagent-muse-code-bridge leaves unspecified semantic-output phases
disabled; other external providers keep the ten-minute first-output and
five-minute idle defaults. Each explicit Muse phase override applies independently.
Startup remains host-owned. No extra identity or policy field is exported.
There is no base URL, arbitrary header map, command, process option or credential
field. Empty model lists are valid. The maximum catalog is 256 KiB of UTF-8 JSON
before JSONL escaping;
oversized catalogs fail rather than truncate. Identity, type, duplicate model
names, timeouts and usable model metadata are validated; unknown optional fields are ignored
by DecodeProviderCatalog.
Discovery and consumer selection
The configurator and daemon share RemoteProviders.Refresh. A private client
sends hello with empty leaf and cwd, awaits hello_ack, and requests
list_macros with empty leaf and filter. That filter matches triggers, not
names. Discovery validates each reserved macro suffix, calls its exact name
with IFO then LIST, and binds the returned catalog identity to that suffix.
No INIT, inference, auth lookup or leaf is needed. Discovery has a ten-second
budget and bounds the complete inventory to 128 providers and 4 MiB of LIST
data. Failed access, hello, incompatible catalogs and empty exports are not
interchangeable outcomes. Discovery RPC failures and error-valued IFO/LIST
replies retain the operation and up to 4096 characters of diagnostic text under
ErrUnavailable, without wrapping peer error classifications. An error-valued
IFO reply is unavailable discovery, not an incompatible protocol value.
Failed discovery is cached for one second; it does not latch credential failure.
Catalogs are availability and adapter metadata, never configuration imports.
Only user-selected provider/model names enter a consumer's ordinary remote
provider config. Opening remote setup or a daemon model browser refreshes
inventory and catalogs. The latter lists saved refs only, using existing model
flags not-found for absent exports/models after successful refresh and
unavailable for discovery failure. Selections remain saved in either case.
An empty selection selects none. Further slashes in a model ID are preserved.
Setup closes its temporary connection and any owned SSH helper after probing. The daemon owns independent lazy/reconnecting destinations. See remote destinations for noninteractive SSH prerequisites and the full-daemon-API trust boundary, and the configurator for selection.
HTTP and WebSocket channels
One tunnel stream carries one HTTP/1.1 request. The consumer uses the synthetic
channel path returned by ProviderHostPath; its URL host is ignored. The host
appends the endpoint to its own configured base path. Query strings, escaped
alternate paths and other methods/endpoints are rejected.
| Host type | Channel path and method | Host policy |
|---|---|---|
openai | POST /responses, GET WebSocket upgrade | Host API key, configured headers, OpenAI identity |
openai_oauth | POST /responses, GET WebSocket upgrade | Canonical https://api.openai.com/v1/responses, shared subscription admission/refresh and authorization watcher |
openai_compatible | POST /chat/completions | Optional host key and configured headers, OpenAI identity |
ollama | POST /chat/completions | Optional host key and configured headers, provider identity |
wafer | POST /chat/completions | Host key; configured headers cannot weaken consumer Wafer-ZDR: required |
anthropic | POST /messages | Host API key, version and shared thinking-binding beta policy |
The consumer and host are trusted machines. The relay keeps credential ownership on the host by construction, rather than trying to detect covert secret echoes in model output. Catalogs and connection descriptors are serialized from explicit non-secret fields. Consumers never resolve credentials for a remote provider.
HTTP forwards ordinary request and response headers, including vendor extensions. It removes hop-by-hop fields, authentication, cookies and account identity, then applies host credentials and provider-specific headers on the final upstream request. The host selects the endpoint and command. Credential-bearing upstream connections require HTTPS; redirects are returned, never followed. Anthropic's thinking-binding beta and Wafer's required ZDR behavior remain unchanged.
Successful bodies stream without JSON decoding or rewriting. Error bodies retain plain text or structured provider details, bounded to 64 KiB with a truncation notice when needed. Only diagnostics get literal replacement of known host credentials, private configured header values and the configured base URL. This is not recursive payload or JSON-key sanitization and does not try to defend against a trusted provider deliberately encoding secrets in its output.
Local connection failures return bounded 502 details. Missing host API keys and OAuth-owner requests to reconnect return 401. Changed admission, temporary discovery failures and watcher infrastructure failures return 503. Ambiguous refresh or unclassified resolver failures return a diagnostic 409, stopping this request without inviting an automatic rotating-token replay or claiming auth was rejected. A later deliberate request can resolve admission again. No relay error latches the destination or requires re-login unless the OAuth owner says so. Only the existing subscription usage-limit code pauses already admitted subscription runs; fresh idle admission gets a clean scope.
On a 101, the host forwards the handshake and splices raw bytes. Both directions retain bytes buffered during HTTP parsing. The host does not inspect WebSocket frames or model IDs inside them. Cancellation, export withdrawal or watched subscription authorization withdrawal closes both the tunnel and upstream, including while the host is writing the handshake response. Non-101 responses retain status, ordinary headers and bounded diagnostic bodies for the consumer's existing fallback handling. Unstructured unsupported-upgrade errors stay unstructured, so they do not turn into fabricated terminal provider errors.
Integration APIs
NewProviderExports(ProviderHostOptions)owns the host-wide budget.Publish(*config.Config)reconciles immutable user snapshots, including credential-only snapshots. It must not receive project-localized config.Inventory()provides macro metadata for registry publication.Route(name)returns a generation-pinned*ProviderExportRoute.route.Call(ctx, connectionID, connectionClosed, row)dispatches one macro operation. Pass the exact inbound connection lifetime signal, not the RPC lifetime.DropConnectionretires all its current stream owners.Close()withdraws exports and stops authorization watchers.EncodeProviderCatalog,DecodeProviderCatalog,ProviderTunnelInfo,MaxProviderCatalogBytesandProviderHostPathare shared construction and discovery contracts for consumer integration.
External protocol-1 channel
The default ExternalHostChannel launches one host-configured bridge per
execution stream through externalprovider.StartRawProcess. It uses the same
command resolution, --stdio argument, filtered environment, private scratch
and exact-child shutdown policy as local external providers. IFO and LIST never
launch a bridge. ProviderHostOptions.External can override this handler for
embedding and controlled tests.
externalprovider.ServeBridge requires a protocol-1 hello before launch. It
ignores consumer auth and replaces options and auth with host configuration,
including case variants accepted by the decoder. Muse native login still omits
supplied auth. Unknown optional hello fields pass through. Every complete names
a published model or a published alias's request-model target. Macro admission
already binds the provider identity, and no tunneled row selects a command or
upstream destination.
The consumer's existing externalprovider.Client owns event validation, accepted
revisions, context comparison and its pre-acceptance context-mismatch retry. The
host does not run a second protocol state machine. It forwards complete/cancel
frames and provider responses without reconstructing content, tool arguments,
property names or numeric values. Optional future fields survive. The single
child remains alive across tool steps, including Muse's held native session.
Tools, finalization and durable results belong to the consumer Agent.
Bridge error messages retain bounded useful diagnostics, with literal supplied
auth values replaced only in those messages. Normal output is not scanned for
auth or pass_env values. Hello identity remains unchanged, preserving the
shared local/remote watchdog and Muse diagnostics policy. The host alone enforces
its configured bridge startup timeout; the consumer waits under execution
cancellation without imposing a second, shorter process-startup deadline.
Cancellation, disconnect, destination retirement and export withdrawal close the stream. The host joins its relay readers and interrupts, then if necessary kills and reaps only that stream's child before releasing the admission slot. As with local process ownership, bridge-owned descendants remain the bridge's responsibility.
The existing protocol client gives cancel a bounded best-effort send before
closing its streams. Stream closure can overtake that final row in the shared
tunnel transport; delivery of cancel or its reply is not guaranteed during
abort. Child retirement and reaping do not depend on receiving that row. The
same shared close-drain limitation affects WebSocket close replies.