Skip to content
WIP

This guide is a work in progress. Barry is also a work in progress.

@barry-rocks/sdk/adapters/models

The contract for model adapters: completion, embedding, and decision models, their requests, availability and compatibility checks, and the errors a model route raises.

import { … } from "@barry-rocks/sdk/adapters/models";
  • Error

new ModelsNotInstalled(): ModelsNotInstalled

ModelsNotInstalled

Error.constructor


The model cannot serve requests at all: unreachable, unauthenticated, or not installed. Distinct from an ordinary failure so a caller sweeping many items stops once instead of recording one outage as N per-item failures.

  • Error

new ModelUnavailableError(message, cause?): ModelUnavailableError

Parameter Type
message string
cause? unknown

ModelUnavailableError

Error.constructor

Property Modifier Type Overrides
cause? readonly unknown Error.cause

A model or vendor this harness cannot run, phrased for whoever chose it.

  • Error

new RouteRefused(message): RouteRefused

Parameter Type
message string

RouteRefused

Error.constructor

Property Type Description
models Model[] -
source "discovered" | "catalog" discovered came from the endpoint; catalog is Barry’s curated list.
stale boolean True when discovery was possible and failed, so the catalog stands in. A silently shortened list reads as a complete one; this is what says it is not.

Property Type Description
fix? string Printed for the human to run — never run on their behalf.
name string A short label for the report line: “binary”, “version”, “context window”.
observed string -
status "unknown" | "failed" | "ok" unknown means not checked, which is different from checked and broken.

Property Type Description
baseUrl BaseUrl -
egressSandbox? boolean Whether Barry’s egress proxy has been shown to hold for requests here.
structuredOutput? "native" | "prompted" Measured per endpoint, not inherited from the API it imitates: a compatible API can accept a schema field and ignore it. Absent means “prompted” — the safe reading until someone verifies otherwise.
with string -

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
servedModel string | null The model that actually served the request, for the audit trail.
structured? unknown Present when schema was set and the reply validated against it.
text string -
usage? TokenUsage -

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
ref `${string}/${string}` -
structuredOutput "native" | "prompted" How a schema is honoured. “prompted” keeps the validate-and-retry fallback on; flipping a model to “native” switches it off, so it takes a dated live verification against the real endpoint, not a reading of docs.

complete(request): Promise<Completion>

Parameter Type
request CompletionRequest

Promise<Completion>


The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
keepAliveMs? number How long a local model stays loaded after this call. For a caller on a timer longer than the vendor’s default, which would otherwise cold-start every call. Vendors with no such notion ignore it.
maxTokens? number -
prompt string -
schema? JsonSchema -
system? string -
temperature? number -
timeoutMs? number -

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
answers Record<string, Answer> Keyed by the names the questions were given.
servedModel string | null The model that actually served the request, for the audit trail.
usage? TokenUsage -

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type
ref `${string}/${string}`

decide(request): Promise<Decision>

Parameter Type
request DecisionRequest

Promise<Decision>


The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
questions Record<string, Question> -
state string | Record<string, unknown> | string[] What the questions are about.
timeoutMs? number -

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type
dimensions? number
ref `${string}/${string}`

embed(request): Promise<Embeddings>

Parameter Type
request EmbeddingRequest

Promise<Embeddings>


The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
input readonly string[] Batched because batching is the whole performance story: 128 texts in one call to nomic-embed-text take ~976ms, one per call pays the round trip every time. The caller picks the batch size — only it knows how much text each item holds.
timeoutMs? number -

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
servedModel string | null -
vectors number[][] One vector per input, in the order given.

A resolved address and credential, ready to send a request to.

Property Type
apiKey? string
baseUrl string
egressSandbox? boolean
structuredOutput? "native" | "prompted"

What the checks need from the host, passed in so they can be tested.

Property Type
platform Platform

run(command, args): { code: number; stdout: string; } | null

Parameter Type
command string
args readonly string[]

{ code: number; stdout: string; } | null

which(command): string | null

Absolute path of a command on PATH, or null.

Parameter Type
command string

string | null


Property Type
id string
parameterSize? string
sizeBytes? number

Property Type Description
dimensions? number -
id string -
kind ModelKind -
label string -
local? boolean -
note? string A caveat shown in pickers — e.g. a measured failure at tool calling.
roles? ("default" | "small")[] default is used when nothing names a model; small for Barry’s own cheap internal calls.
structuredOutput? "native" | "prompted" -

Property Type Description
refused Map<string, string[]> Refusals from the most recent load; selections remain recorded for repair.

add(path, options?): Promise<{ contractVersion: 1; factoryExport: string; packageName: string; path: string; shipped?: true; version: string; }>

Parameter Type
path string
options? { shipped?: true; }
options.shipped? true

Promise<{ contractVersion: 1; factoryExport: string; packageName: string; path: string; shipped?: true; version: string; }>

installed(): object[]

object[]

load(packageNames?): Promise<VendorFactories>

Omitted names load registered selections. A named missing selection fails explicitly.

Parameter Type
packageNames? readonly string[]

Promise<VendorFactories>

remove(packageName): boolean

Parameter Type
packageName string

boolean


Property Type Description
file string -
importModule? (entry) => Promise<unknown> Absolute module entry point; tests may inject imports without contacting a provider.

available(vendor, at?): Promise<AvailableModels>

Parameter Type
vendor string
at? Partial<Endpoint>

Promise<AvailableModels>

byRole(vendor, role, kind?): `${string}/${string}` | undefined

Parameter Type
vendor string
role "default" | "small"
kind? ModelKind

`${string}/${string}` | undefined

check(ref, at?): Promise<Check[]>

Parameter Type
ref `${string}/${string}`
at? Partial<Endpoint>

Promise<Check[]>

completion(ref, at?): CompletionModel

Parameter Type
ref `${string}/${string}`
at? Partial<Endpoint>

CompletionModel

decision(ref, at?): DecisionModel

Parameter Type
ref `${string}/${string}`
at? Partial<Endpoint>

DecisionModel

embedding(ref, at?): EmbeddingModel

Parameter Type
ref `${string}/${string}`
at? Partial<Endpoint>

EmbeddingModel

endpoint(vendor, compatibleWith?): Endpoint | undefined

Where to send a request, with its credential. compatibleWith asks for the vendor’s imitation of another vendor’s API — how a harness reaches a model its own vendor does not serve. undefined when there is no such door.

Parameter Type
vendor string
compatibleWith? string

Endpoint | undefined

get(ref): Model | undefined

The catalog entry, when there is one. Unknown ids still resolve everywhere else.

Parameter Type
ref `${string}/${string}`

Model | undefined

vendors(): Vendor[]

Vendor[]


Property Type Description
env? Record<string, string | undefined> Where credentials and address overrides are read. Defaults to process.env.

Property Type Description
id string -
label string -
note? string A caveat worth showing where the model is picked, such as a measured weakness.

Property Type Description Inherited from
aliases? readonly string[] Former ids it still answers to: an identity’s default may name one. RoutingHarness.aliases
capabilities Pick<HarnessCapabilities, "endpoint" | "withoutKey"> - RoutingHarness.capabilities
id string - RoutingHarness.id
offeredModels? readonly OfferedModel[] - -
vendor? string - RoutingHarness.vendor

Property Type Description
model string | undefined As the harness names it. Absent means no model flag: the harness decides.
vendor string | undefined The vendor serving it, when that is not the harness’s own.

Property Type Description
identity? object The identity’s model for the running harness.
identity.model? string -
model? string From the session or -m: a model id.
vendor? string The vendor to serve it, when the session names one (--model-provider).

Property Type Description
aliases? readonly string[] Former ids it still answers to: an identity’s default may name one.
capabilities Pick<HarnessCapabilities, "endpoint" | "withoutKey"> -
id string -
vendor? string -

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

Property Type Description
cacheReadTokens? number With heavy tool use cache reads are usually the majority of input and are priced far below it, so a cost computed without them is wrong by a large factor, not a small one.
cacheWriteTokens? number -
costUsd? number -
inputTokens number -
outputTokens number -
totalTokens? number -

Property Type Description
baseUrl? BaseUrl Absent for a vendor Barry never calls directly (cursor serves only through its harness).
compatible? Compatibility[] Other vendors’ APIs this vendor also serves — z.ai and Ollama speak Anthropic’s Messages API, Ollama speaks OpenAI’s too. A harness reaches a model of this vendor only through one of these.
credential { env: string; field?: "username" | "password" | "notes" | "uri"; item?: string; } | { placeholder: string; } | null null for a vendor that needs none. A placeholder is always sent and is not authentication: without one, a harness falls back to the user’s own login and sends a real token to whatever endpoint it was pointed at. The env form carries an optional default vault item: when the identity does not define the variable, the gate reads item.field from the identity’s vault. Env-only keeps working — the identity must define the variable — and the checker warns on it.
id string -
label string -
models Model[] -

optional check(endpoint, model?): Promise<Check[]>

Parameter Type
endpoint Endpoint
model? string

Promise<Check[]>

optional completion(model, endpoint): CompletionModel

Parameter Type
model string
endpoint Endpoint

CompletionModel

optional decision(model, endpoint): DecisionModel

Parameter Type
model string
endpoint Endpoint

DecisionModel

optional embedding(model, endpoint): EmbeddingModel

Parameter Type
model string
endpoint Endpoint

EmbeddingModel

optional listModels(endpoint): Promise<ListedModel[]>

What this endpoint actually serves right now, where the vendor can say.

Parameter Type
endpoint Endpoint

Promise<ListedModel[]>


The vendor call code an adapter package may ship beside its adapter.

A harness adapter owns a session model; a vendor-carrying adapter also owns call code for vendors Barry does not ship — its own rows and the factories that serve them, installed and recorded like the adapter itself. The rows are snapshotted into the installed record, so the catalog a picker reads costs no imports; the factories load when the process that hosts models asks for them.

Property Type
factories VendorFactories
vendors Vendor[]

The per-kind call code, keyed by the vendor id it serves. What a kind directory exports; what turns parsed catalog data into callable vendors.

Property Type
check? Partial<Record<string, (endpoint, model?) => Promise<Check[]>>>
completion? Partial<Record<string, (model, endpoint) => CompletionModel>>
decision? Partial<Record<string, (model, endpoint) => DecisionModel>>
embedding? Partial<Record<string, (model, endpoint) => EmbeddingModel>>
listModels? Partial<Record<string, (endpoint) => Promise<ListedModel[]>>>

Answer = { confidence?: number; probability: number; type: "boolean"; value: boolean; } | { confidence?: number; probabilities?: Record<string, number>; type: "choice"; value: string; } | { confidence?: number; legend?: string; type: "score"; value: number; }

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.


BaseUrl = string | { env?: string; fallback?: string; path?: string; }

Where a vendor listens: a fixed URL, or an env override with the vendor’s own default behind it. A local daemon’s default is its vendor’s documented port (Ollama’s 11434); Barry keeps no port table of other people’s software.


InstalledModelProvider = z.infer<typeof registration>


Platform = "aix" | "android" | "darwin" | "freebsd" | "haiku" | "linux" | "openbsd" | "sunos" | "win32" | "cygwin" | "netbsd"

Platform names are wire data and must also be usable without Node declarations.


Question = { instructions: string; type: "boolean"; } | { instructions: string; options: string[]; type: "choice"; } | { instructions: string; levels: string[]; type: "score"; }

The model contracts: what a model can be asked, and the Models door every caller reaches one through.

Everything needed to WRITE a vendor or call a model, and nothing that implements one. The vendors Barry ships live in registered bags’ vendor declarations with the call code attached by the installation composition root; a composition root hands them to createModels and installs the result.

{ instructions: string; type: "boolean"; }


{ instructions: string; options: string[]; type: "choice"; }


{ instructions: string; levels: string[]; type: "score"; }

2–10 labelled levels.


ShippedModelProvider = Pick<InstalledModelProvider, "packageName" | "version" | "path"> & object

Name Type
contractVersion unknown
factoryExport unknown

const registration: ZodObject<{ contractVersion: ZodLiteral<1>; factoryExport: ZodString; packageName: ZodString; path: ZodString; shipped: ZodOptional<ZodLiteral<true>>; version: ZodString; }, $strict>


const SHIPPED_VENDORS: Vendor[]


const SHIPPED_VENDORS_YAML: string


const VendorCatalogSchema: ZodArray<ZodObject<{ baseUrl: ZodOptional<ZodUnion<readonly [ZodString, ZodObject<{ env: ZodOptional<ZodString>; fallback: ZodOptional<ZodString>; path: ZodOptional<ZodString>; }, $strict>]>>; compatible: ZodOptional<ZodArray<ZodObject<{ baseUrl: ZodUnion<readonly [ZodString, ZodObject<{ env: …; fallback: …; path: …; }, $strict>]>; egressSandbox: ZodOptional<ZodBoolean>; structuredOutput: ZodOptional<ZodEnum<{ native: "native"; prompted: "prompted"; }>>; with: ZodString; }, $strict>>>; credential: ZodUnion<readonly [ZodObject<{ env: ZodString; field: ZodOptional<ZodEnum<{ notes: "notes"; password: "password"; uri: "uri"; username: "username"; }>>; item: ZodOptional<ZodString>; }, $strict>, ZodObject<{ placeholder: ZodString; }, $strict>, ZodNull]>; id: ZodString; label: ZodString; models: ZodArray<ZodObject<{ dimensions: ZodOptional<ZodNumber>; id: ZodString; kind: ZodEnum<{ completion: "completion"; decision: "decision"; embedding: "embedding"; }>; label: ZodString; local: ZodOptional<ZodBoolean>; note: ZodOptional<ZodString>; roles: ZodOptional<ZodArray<ZodEnum<{ default: "default"; small: "small"; }>>>; structuredOutput: ZodOptional<ZodEnum<{ native: "native"; prompted: "prompted"; }>>; }, $strict>>; }, $strict>>

answerViaJson(questions, raw): Record<string, Answer>

Validate a model’s JSON into answers, failing loudly on anything unusable.

A missing key, a choice outside the offered set, or a score outside the level range all throw naming the question — the caller can retry or fall back, but it is never handed a value the model invented.

Parameter Type
questions Record<string, Question>
raw string

Record<string, Answer>


assembleVendors(specs, factories): Vendor[]

Attach the call code to the catalog data.

A factory keyed by a vendor the catalog does not list is refused rather than silently dropped: a misspelled id would otherwise leave that vendor’s models unpickable-at and the failure would surface frames away from the typo that caused it.

Parameter Type
specs readonly Vendor[]
factories VendorFactories

Vendor[]


checkRequirements(requirements, probes): Check[]

binary, version and pin — in that order, always all three. Credentials are not a host requirement: they are declared per harness bag and enforced by the session gate against the identity’s sources.

Parameter Type
requirements Requirements
probes HostProbes

Check[]


createModels(vendors, options?): Models

Parameter Type
vendors readonly Vendor[]
options ModelsOptions

Models


defineVendor(vendor): Vendor

Checks what no type can: each model id appears once, and at most one model of a kind claims each role — two default completion models would make the choice depend on file order.

Parameter Type
vendor Vendor

Vendor


defineVendorCode(code): VendorCode

Give a vendor-code literal its type, and refuse incoherence by name: a factory keyed by a vendor this code does not declare would dangle forever — no row, so no ref can ever reach it — and the moment to learn that is the install, not the first call.

Parameter Type
code VendorCode

VendorCode


describeQuestions(questions): string

Describe the questions as a system prompt.

Says the shape once, per question, in the model’s own terms — an enum lists its options, a score lists its levels with their indices. Vaguer phrasing (“answer as JSON”) produces keys that do not match and values out of range.

Parameter Type
questions Record<string, Question>

string


formatChecks(title, checks): string[]

One line per check, passes included, then the fixes for what failed.

Parameter Type
title string
checks readonly Check[]

string[]


installedModels(): Models

The models this process was started with.

Throws ModelsNotInstalled — never a “model unavailable” — when nothing was installed: the two need different fixes, and reading a wiring mistake as an unavailable model is how a sweep once skipped every run while the daemon was up with the model pulled.

Models


installModels(models): void

Called once by whatever process starts — the API, the engine, the CLI, a job.

Parameter Type
models Models

void


isOfferedModel(harness, vendors, id): boolean

Parameter Type
harness OfferingHarness
vendors readonly Vendor[]
id string

boolean


keylessRouteRefusal(harness, route, vendors, env): string | null

Why routing this session to its endpoint would hand the user’s own login to another vendor, or null when it would not.

A harness whose fallback without a key is the user’s subscription login sends that login wherever it is pointed. So an endpoint that needs a key, reached without one, is refused rather than warned about: the request would fail at the vendor anyway, having carried the credential there.

Parameter Type
harness RoutingHarness
route Route
vendors readonly Vendor[]
env Record<string, string | undefined>

string | null


loadModelProviders(options): ModelProviders

No discovery of siblings and no implicit defaults: add is the installation’s selection.

Parameter Type
options ModelProviderStoreOptions

ModelProviders


mergeVendorFactories(…sources): VendorFactories

Compose independently installed providers without silently replacing one.

Parameter Type
…sources VendorFactories[]

VendorFactories


offeredModels(harness, vendors): OfferedModelInfo[]

A harness’s own vendor’s completion models, then those of each vendor it can be routed to; a harness with no vendor offers the list it declares.

Parameter Type
harness OfferingHarness
vendors readonly Vendor[]

OfferedModelInfo[]


parseVendorCatalog(text): Vendor[]

Parse a legacy standalone catalog. Refuses, by name: an unknown or misspelled key (the schema is strict — a typo’d field must not parse as absence), a model id twice in one vendor, two default models of a kind, and a compatibility door naming a vendor the file does not list.

Parameter Type
text string

Vendor[]


parseVersion(requirements, output): string | null

The version a binary’s output reports, by the requirement’s pattern. null when the pattern finds nothing — Barry’s declaration is out of date, which is not the same as the harness being missing.

Parameter Type
requirements Requirements
output string

string | null


preflightLine(subject, checks): string

The one line barry start prints before launching — always a line, success included.

Parameter Type
subject string
checks readonly Check[]

string


reachableVendors(harness, vendors): Vendor[]

Other vendors serving this harness vendor’s API, on a harness Barry can point at them.

Parameter Type
harness RoutingHarness
vendors readonly Vendor[]

Vendor[]


registeredVendorRows(registry?, includeShipped?): Vendor[]

Catalogs are installed declarations, independent of identity packing.

Parameter Type
registry? BagRegistry
includeShipped? boolean

Vendor[]


routedEndpoint(harness, model, vendors, env, override?): Endpoint | undefined

Where a harness reaches a model another vendor serves: that vendor’s door for the harness vendor’s API, with its key, resolved against the session’s env — which is where an identity’s keys and a session’s BARRY_OLLAMA_URL live, not the process’s.

Undefined for the harness’s own vendor’s model, for a model named without its vendor, and for a harness Barry cannot point anywhere: the harness then uses its own settings, which Barry never overrides.

override moves only an address resolved at runtime (a local daemon’s); a vendor’s fixed address is its own.

Parameter Type
harness RoutingHarness
model string | undefined
vendors readonly Vendor[]
env Record<string, string | undefined>
override { baseUrl?: string; }
override.baseUrl? string

Endpoint | undefined


routedVendorOf(harness, model, vendors): Vendor | undefined

The vendor serving model that this harness can be pointed at, if any.

Parameter Type
harness RoutingHarness
model string
vendors readonly Vendor[]

Vendor | undefined


routeModel(harness, given, vendors): Route

Parameter Type
harness RoutingHarness
given RouteRequest
vendors readonly Vendor[]

Route


shippedModelProviders(root): ShippedModelProvider[]

Discover declarations without importing code or requiring a built package.

Parameter Type
root string

ShippedModelProvider[]


suggestOfferedModels(harness, vendors, partial): string[]

Offered models close to a (possibly misspelled) id. Substring matches win; otherwise a fuzzy subsequence match, so “claude-huiku” still suggests “claude-haiku-4-5”.

Parameter Type
harness OfferingHarness
vendors readonly Vendor[]
partial string

string[]


validateVendorCatalog(vendors, checkCompatibility?): Vendor[]

Validate catalog relationships independently of its containing file.

Parameter Type Default value
vendors Vendor[] undefined
checkCompatibility boolean true

Vendor[]