@hashbrownai/core
Version:
Runtime helpers for Hashbrown AI
128 lines • 3.31 kB
TypeScript
import { Chat } from '../models';
import { KnownModelIds } from '../utils';
import { type Transport, type TransportFactory, type TransportOrFactory } from './transport';
/**
* Capability flags describing what a model/transport can satisfy.
*
* @public
*/
export interface ModelCapabilities {
tools?: boolean;
structured?: boolean;
ui?: boolean;
threads?: boolean;
}
/**
* Result of a platform/environment detection probe.
*
* @public
*/
export type DetectionResult = {
ok: true;
} | {
ok: false;
code: 'PLATFORM_UNSUPPORTED' | 'MODEL_UNAVAILABLE';
reason?: string;
};
/**
* Model specification consumed by the resolver.
*
* @public
*/
export interface ModelSpec {
name: string;
transport: Transport | TransportFactory;
options?: Record<string, unknown>;
capabilities?: ModelCapabilities;
detect?: () => Promise<DetectionResult>;
}
/**
* Factory variant that allows config injection.
*
* @public
*/
export type ModelSpecFactory = (config?: ModelSpecConfig) => ModelSpec;
/**
* Accepted input when selecting a model.
*
* @public
*/
export type ModelInput = KnownModelIds | ModelSpec | ModelSpecFactory | Array<KnownModelIds | ModelSpec | ModelSpecFactory | string> | string;
/**
* Configuration injected into model spec factories.
*
* @public
*/
export interface ModelSpecConfig {
url?: string;
middleware?: Chat.Middleware[];
transport?: TransportOrFactory;
[key: string]: unknown;
}
/**
* Features required by the current request.
*
* @public
*/
export interface RequestedFeatures {
tools: boolean;
structured: boolean;
ui: boolean;
threads: boolean;
}
/**
* Reasons a spec was skipped during resolution.
*
* @public
*/
export interface SkippedSpec {
name: string;
reason: 'FEATURE_UNSUPPORTED' | 'PLATFORM_UNSUPPORTED';
details?: string;
}
/**
* Metadata describing the chosen spec and any skipped candidates.
*
* @public
*/
export interface ModelSelectionMetadata {
chosenSpec?: string;
skippedSpecs: SkippedSpec[];
}
/**
* Resolved model spec paired with the chosen transport.
* @public
*/
export interface ResolvedModelSpec {
spec: ModelSpec;
transport: Transport;
metadata: ModelSelectionMetadata;
}
/**
* Resolver that selects a transport based on model specs, capability gating,
* and optional platform detection.
*
* @public
*/
export declare class ModelResolver {
private readonly candidates;
private readonly skipped;
private readonly config;
constructor(model: ModelInput | undefined, config: ModelSpecConfig);
/**
* Attempts to select the next compatible spec. Specs that previously failed
* capability checks or platform detection are skipped. A TransportError
* with FEATURE_UNSUPPORTED or PLATFORM_UNSUPPORTED can be fed back into
* {@link ModelResolver.skipFromError} to advance the resolver.
*/
select(features: RequestedFeatures): Promise<ResolvedModelSpec | undefined>;
/**
* Mark the provided spec as skipped after a send failure.
*/
skipFromError(spec: ModelSpec, error: unknown): void;
getMetadata(): ModelSelectionMetadata;
private resolveTransport;
private materializeSpec;
private buildDefaultTransport;
}
//# sourceMappingURL=model-spec.d.ts.map