Provider registry and model resolution. Loads provider definitions, merges config/auth/env overrides, and exposes helpers — including the locality checks that enforce closedcode's local-only egress policy — used to instantiate models.

Classes

Service

Members

(static, constant) ConfigProvidersResult

Schema for the config-providers response: the config-defined providers and their default models.

(static, constant) Info

Schema for a resolved provider, including its source, env var names, key, and models.

(static, constant) InitError

Error: the provider SDK could not be constructed (wraps the underlying cause).

(static, constant) ListResult

Schema for the /provider list response: all providers, default model per provider, and connected ids.

(static, constant) Model

Schema for a fully-resolved model (merged from models.dev, config, env, and auth).

(static, constant) ModelNotFoundError

Error: the requested provider or model id was not found (carries fuzzy suggestions).

(static, constant) defaultLayer

The Provider layer with all its service dependencies provided.

(inner, constant) layer

Layer building the Provider service. Resolves the full provider/model database by merging the models.dev snapshot with plugin hooks, config, environment variables, and stored auth — enforcing the local-only policy by dropping any non-local provider — and exposes the lookup/SDK-resolution operations.

Methods

(static) defaultModelIDs(providers) → {Object}

Pick a default model id for each provider — the top of sort's ordering. Providers with no models are skipped (rather than crashing) so they still list.

Parameters:
NameTypeDescription
providersObject

Map from provider id to a provider object with a models record.

Returns:

Map from provider id to its chosen default model id.

Type: 
Object

(static) fromModelsDevProvider(provider) → {Object}

Build an internal provider record from a models.dev provider, expanding each model and adding synthetic <id>-<mode> entries for any experimental modes (merging their cost/body/header overrides on top of the base model).

Parameters:
NameTypeDescription
providerObject

The models.dev provider record.

Returns:

The internal provider object with id, name, env, and models.

Type: 
Object

(static) isLocalProvider(provider) → {boolean}

Determine whether a provider talks only to local endpoints, checking its base URL and every model's API URL via isLocalURL.

Parameters:
NameTypeDescription
providerObject

The provider definition (options.baseURL and models[id].api.url are read).

Returns:

True when the provider's base URL or any model URL is local.

Type: 
boolean

(static) isLocalURL(url) → {boolean}

Determine whether a URL points at the local machine or a private network. Treats localhost, loopback, RFC 1918 / link-local IPv4, ULA / loopback / link-local IPv6, and .local / .lan / .internal hostnames as local.

Parameters:
NameTypeDescription
urlstring

The URL to inspect.

Returns:

True when the URL host is local or private; false otherwise or when the URL is unparseable.

Type: 
boolean

(static) parseModel(model) → {Object}

Split a "provider/model" string into branded provider and model ids (the model portion may itself contain slashes, which are rejoined).

Parameters:
NameTypeDescription
modelstring

A "providerID/modelID" string.

Returns:

{providerID, modelID} with branded ids.

Type: 
Object

(static) sort(models) → {Array}

Sort models into a preferred display order: by priority family (qwen/llama/gpt-oss) first, then "latest"-tagged ids, then id descending.

Parameters:
NameTypeDescription
modelsArray

The models to sort.

Returns:

The sorted models.

Type: 
Array

(inner) cost(c) → {Object}

Convert a models.dev cost record into the internal cost shape, defaulting missing fields to 0 and carrying over the optional >200k-context override.

Parameters:
NameTypeDescription
cObject

The models.dev cost record (may be undefined).

Returns:

The internal cost object {input, output, cache: {read, write}, ...}.

Type: 
Object

(inner) fromModelsDevModel(provider, model) → {Object}

Build an internal Model from a models.dev provider+model pair, deriving API info, capabilities/modalities, cost, limits, and reasoning-effort variants.

Parameters:
NameTypeDescription
providerObject

The models.dev provider record.

modelObject

The models.dev model record.

Returns:

The internal Model object (with variants populated).

Type: 
Object

(inner) isPrivateIPv4(host) → {boolean}

Determine whether a host string is a private/loopback/link-local IPv4 address (loopback 127/8, RFC 1918 10/8, 172.16/12, 192.168/16, and link-local 169.254/16).

Parameters:
NameTypeDescription
hoststring

The host string to test.

Returns:

True for a private/loopback IPv4 address; false otherwise or when not an IPv4 literal.

Type: 
boolean

(inner) isPrivateIPv6(host) → {boolean}

Determine whether a host string is a loopback/private/link-local IPv6 address (::1 loopback, fc00::/7 unique-local, fe80::/10 link-local).

Parameters:
NameTypeDescription
hoststring

The host string to test.

Returns:

True for a loopback/private/link-local IPv6 address; false otherwise.

Type: 
boolean

(inner) wrapSSE(res, ms, ctl) → {Response}

Wrap a Server-Sent-Events Response so that a stalled stream is aborted if no chunk arrives within ms. Returns the response unchanged for non-positive timeouts, bodyless responses, or non-SSE content types.

Parameters:
NameTypeDescription
resResponse

The fetch Response to wrap.

msnumber

The per-chunk read timeout in milliseconds.

ctlAbortController

The controller aborted when a read times out.

Returns:

The original or a timeout-guarded Response.

Type: 
Response