import { type ConfigTarget } from "../config/target.js"; import { type DownloadOptions } from "./hubDownload.js"; import { type HubFile } from "./hubClient.js"; export { fileSha256, verifyModelFile } from "./modelVerify.js"; import { type Backend, type ServedBackend } from "./modelBackend.js"; export { type Backend, type ServedBackend, isMlxUri, parseMlxUri, isServedUri, parseServedUri, isModelDir, isDiffusersDir, modelDirEntries, backendOfTarget, hubRepoOfDirName, hubSnapshotDir, } from "./modelBackend.js"; import { type ModelCategory, type ModelTag } from "./modelCatalog.js"; export { CURATED_LOCAL_MODELS, type ModelCategory, type ModelInfo, type ModelTag, } from "./modelCatalog.js"; import { type ModelKind } from "./modelKind.js"; export { MODEL_KINDS, isModelKind, type ModelKind } from "./modelKind.js"; /** The folder LoRA adapters come from, `client.adaptersDir`. */ export declare function configuredAdaptersDir(startDir?: string): string | null; /** The folder ControlNets come from, `client.controlnetsDir`. */ export declare function configuredControlnetsDir(startDir?: string): string | null; /** Where downloaded models live, in precedence order: * 1. `AGENCY_MODELS_DIR` env var (per-machine override). * 2. `client.modelsDir` in the nearest `agency.json` (read at runtime, like * `modelAliases`), so the CLI and the agent share one configurable dir. * 3. `~/.agency-agent/models` (the default; shared with the agent so a CLI * `agency local download` pre-populates what `agency agent --local-model` * reuses). */ export declare function defaultCacheDir(): string; /** The resolved models cache dir (AGENCY_MODELS_DIR env → agency.json * client.modelsDir → ~/.agency-agent/models). Exported so `agency local * list` can name where downloads land. */ export declare function _modelsCacheDir(cacheDir?: string): string; /** Where alias reads and writes go when the caller names no file: the nearest * project at or above `startDir`, or `~/agency.json` alone. */ export declare function defaultAliasTarget(startDir?: string): ConfigTarget; /** The file alias writes go to. Exported so the CLI can echo it. */ export declare function resolveAliasConfigPath(startDir?: string): string; /** Read a JSON file as a plain object. A missing file reads as `{}`. */ /** The merged `client` object of the default target, or `{}`. For settings * read at runtime rather than compiled in: the models directory, the MLX * Python, the MLX base URL. */ export declare function readClientConfig(): Record; /** A model alias value: either the bare URI (hand-edit shorthand) or an * object carrying the URI plus optional display metadata. `source: "remote"` * marks an entry written by `agency local refresh` (see `_refreshCatalog`); * hand-added aliases have no `source`. */ export type AliasObject = { backend: Backend; uri: string; source?: "remote"; params?: string; sizeBytes?: number; kind?: ModelKind; tags?: ModelTag[]; /** An alias written before kinds and tags. Read as both. */ category?: ModelCategory; contextWindow?: number; license?: string; description?: string; sha256?: string; /** Repos this model loads by name at runtime, as mlx: URIs. */ companions?: string[]; }; export type AliasValue = string | AliasObject; /** The URI an alias points at, regardless of string/object form. */ export declare function aliasUri(value: AliasValue): string; /** Read `client.modelAliases`. An object alias must carry a `backend` that * agrees with its uri; a string alias reads its backend from its prefix. */ export declare function readModelAliases(target?: ConfigTarget): Record; /** Entry returned by `_listModelNames`. */ export type ModelNameEntry = { name: string; backend: Backend; target: string; source: "curated" | "alias"; params?: string; sizeBytes?: number; kind?: ModelKind; tags?: ModelTag[]; description?: string; contextWindow?: number; license?: string; sha256?: string; }; /** A model name resolved to the engine that runs it and the target that * engine takes: an `hf:` URI or `.gguf` path for llama-cpp, an `mlx:` URI * or a model directory for mlx. */ export type ResolvedModel = { backend: Backend; target: string; }; export declare function _resolveModel(value: string, configTarget?: ConfigTarget): ResolvedModel; export declare function _resolveModelName(value: string, target?: ConfigTarget): string; /** The model name to send to the server `agency local serve` runs. `serve` * gives the server the same string, so a run against your own server never * names a model it is not serving. A repo id for an `mlx:` or `diffusers:` * URI; the absolute directory path for a model directory. */ export declare function _mlxServedName(resolved: ResolvedModel): string; export declare function _listModelNames(target?: ConfigTarget): ModelNameEntry[]; export declare function _aliasModel(name: string, uri: string, target?: ConfigTarget): string; /** Outcome of `_unaliasModel`. `removed` distinguishes the actual mutation * (true) from the "alias / file wasn't there, file untouched" no-op (false), * so the CLI can print an accurate message instead of always saying * "Removed alias …" even when nothing changed. */ export type UnaliasResult = { file: string; removed: boolean; }; /** Remove an alias. Bails early (no write) if file or alias missing. */ export declare function _unaliasModel(name: string, target?: ConfigTarget): UnaliasResult; /** One model on disk. For a GGUF file, `name` is the file name. For an MLX * model, `name` is the repo id and `path` is its directory. */ export type DownloadedModel = { name: string; path: string; sizeBytes: number; backend: Backend; /** False for an MLX model whose download was interrupted. */ complete: boolean; /** The commit an MLX model was downloaded from. Absent for GGUF. */ revision?: string; /** Which directory shape holds the files. `agency` is our own * `/mlx/--` or `/diffusers/--` * with a record. `hub` is a Hugging Face cache written by another tool, * which we read but never write. `directory` is any other model * directory, such as the target of an alias. */ layout: "gguf" | "agency" | "hub" | "directory"; /** What the model is, when the record, the catalog, or the files say. */ kind?: ModelKind; }; export declare function _listDownloadedModels(cacheDir?: string): DownloadedModel[]; /** The downloaded model with this backend and repo id, in whichever layout * holds it. This is what makes `mlx:org/repo` or `diffusers:org/repo` mean * the model rather than one place it might live. * * With a `revision`, only a copy at that commit counts. The prefix is * matched, the way a pin in an `mlx:` URI is written. A cache keeps every * revision it has fetched, and lists only the one `refs/main` names, so a * pinned revision is looked for among the others too. */ export declare function _findDownloadedServedModel(backend: ServedBackend, repo: string, cacheDir?: string, revision?: string): DownloadedModel | null; /** Delete one model file from the cache dir. `name` must be a plain file * name inside it: `resolveUnder` refuses `..` and symlinks, and a missing * file or a non-file returns false. */ export declare function _removeModel(name: string, cacheDir?: string): boolean; /** Delete a served model's directory from the cache. Only a directory under * `/mlx` or `/diffusers` is ever removed; `remove` * refuses symlinks. */ export declare function _removeServedModel(backend: ServedBackend, repo: string, cacheDir?: string): boolean; /** Where a resolved model's files are on disk, or null when nothing is * there. A GGUF model is found through the download manifest; an MLX model * through its record under the cache, or the directory it points at. * `insideCache` is false for a ControlNet, whose files are listed with the * models but live in `client.controlnetsDir`, where remove cannot reach. */ export declare function _modelFilesOnDisk(resolved: ResolvedModel, cacheDir?: string): { path: string; sizeBytes: number; insideCache: boolean; layout: DownloadedModel["layout"]; } | null; export declare const DEFAULT_CATALOG_URL = "https://raw.githubusercontent.com/egonSchiele/agency-lang/main/packages/agency-lang/data/model-catalog.json"; /** A validated entry from the remote catalog. Mirrors `AliasObject` minus the * `source` tag (which `_refreshCatalog` adds on write). */ export type CatalogModel = { backend: Backend; uri: string; params?: string; sizeBytes?: number; kind?: ModelKind; tags?: ModelTag[]; contextWindow?: number; license?: string; description?: string; sha256?: string; /** Repos this model loads by name at runtime, as mlx: URIs. Carried into * the alias `agency local refresh` writes, so a refreshed model can * download them too. */ companions?: string[]; }; /** Resolve the catalog URL: explicit arg → env → config → built-in default. */ export declare function resolveCatalogUrl(explicit?: string, target?: ConfigTarget): string; /** Parse + validate the catalog JSON. Throws on blob-level problems (bad JSON, * unsupported version, `models` not an object) so refresh aborts without * touching agency.json. Skips an individual entry (with a warning) when its * `uri` is missing/invalid; metadata fields with the wrong type are dropped * but the entry is kept. */ export declare function parseCatalog(text: string): Record; /** Default fetcher: a local file path / `file://` URL is read from disk; * otherwise an HTTPS-only GET with a bounded timeout and a streamed byte cap. * `http:` (and other non-https URL schemes) are rejected. */ export declare function fetchCatalog(url: string): Promise; export type SkippedAlias = { name: string; keptUri: string; remoteUri: string; }; export type RefreshResult = { url: string; file: string; added: string[]; updated: string[]; unchanged: string[]; removed: string[]; skipped: SkippedAlias[]; modelCount: number; }; /** Fetch + validate the catalog, then rewrite the `source:"remote"` aliases in * agency.json from it. User-owned aliases are preserved and win on name * collisions (the remote entry is skipped). Throws (leaving the file * untouched) on fetch/parse/validation failure. */ export declare function _refreshCatalog(opts?: { url?: string; fetcher?: (url: string) => Promise; target?: ConfigTarget; }): Promise; /** True if smoltalk-llama-cpp is reachable from the local require paths OR * from a global node_modules root (npm or pnpm). */ export declare function _localModelsSupported(): boolean; /** Whether the local-model commands should be allowed to run. True when * smoltalk-llama-cpp is installed OR the caller has supplied their own * provider module via AGENCY_LLAMA_PROVIDER_MODULE. Mirrors the gate inside * `requireSupport()`; used by the CLI so `agency local download/list/remove` * works in the override scenario (otherwise the CLI would exit 1 even though * the underlying TS functions would happily run). */ export declare function hasLocalModelSupport(): boolean; /** Register the llama-cpp provider into agency's own smoltalk. Inside a run * (the agent's --local path), emit the `localModelLoaded` statelog event * saying where the provider package came from. The plain CLI has no runtime * frame, so there is no run logger there and nothing is emitted. */ export declare function _registerLocalProvider(): Promise; /** The pinned SHA-256 for a model name/alias, or undefined when none is known * (raw uri/path, string alias, alias/curated without a hash, or a sharded * model). An alias entry governs the name entirely — a user alias shadowing a * curated name must NOT borrow the curated hash, but a user MAY opt in by * setting their own `sha256` on the alias object. */ export declare function pinnedSha256(value: string, target?: ConfigTarget): string | undefined; /** Was the resolved file freshly downloaded (not already cached)? */ export type FreshnessProbe = (resolved: string) => boolean; /** Snapshot the cache dir, returning a probe that reports whether a resolved * path is newly downloaded. node-llama-cpp stores models FLAT in `dir` with a * prefixed filename — no per-repo subdirs (verified against its * `buildHuggingFaceFilePrefix`) — so matching by basename is correct. */ export declare function snapshotFreshness(dir: string): FreshnessProbe; /** `client.mlx.downloadConcurrency` from the project config, else 8. The * config schema requires a positive integer. */ export declare function configuredDownloadConcurrency(): number; /** The files a ControlNet directory needs: its config and its * `.safetensors` weights. A repo also ships sample images and, for * some, a second copy of the weights under another name. */ export declare function controlnetFiles(files: HubFile[]): HubFile[]; /** The download options, plus the kind to record when the user says what * the model is. Without it, the catalog or the files decide. */ export type ModelDownloadOptions = DownloadOptions & { kind?: ModelKind; }; /** Download a model and return where it is: the `.gguf` path, or the MLX * model directory. `hubOptions` lets the CLI watch progress and lets tests * point at a fake hub. */ export declare function _downloadModel(value: string, cacheDir?: string, hubOptions?: ModelDownloadOptions): Promise; /** The kind a category from before the split implies. The categories that * say what a model returns map to themselves; the rest describe a chat * model. */ export declare function kindOfCategory(category: ModelCategory | undefined): ModelKind | undefined; /** The tags a category from before the split implies: the category itself * when it says what a chat model is good for, none otherwise. */ export declare function tagsOfCategory(category: ModelCategory | undefined): ModelTag[] | undefined; /** What kind of model `value` is, given the directory it resolved to. The * catalog's word comes first, because it knows the models whose files are * ambiguous (an Orpheus speech model has a Llama config). Then the record * the download wrote. Then the files. Null when none of the three knows, * which also covers a directory that is not there. */ export declare function _modelKind(value: string, dir: string): ModelKind | null; /** The kind of the model `value` names, from the catalog, its record, or * its files, or null when it is not downloaded or nothing knows. For a * stdlib function refusing a model of the wrong kind before any request. */ export declare function _localModelKindOf(value: string, cacheDir?: string): ModelKind | null; /** The kind the catalog or an alias entry gives `value`, before any file is * looked at. The value may be the entry's name or the URI it points at; a * plain string alias, a directory, or a URI no entry names has none. */ export declare function _catalogKind(value: string, target?: ConfigTarget): ModelKind | undefined; /** Convenience: register the provider + ensure the model is downloaded. */ export declare function _registerLocalModel(value: string, cacheDir?: string): Promise; /** What to send smoltalk for a local embedding model. For llama-cpp, a * .gguf path (the provider registered) or a name the catalog knows * (downloaded and verified if needed). For mlx, the served name; a name * the catalog does not know passes through, because it may be a repo id * the server was started with. */ export declare function _resolveLocalEmbeddingModel(provider: string, model: string): Promise; export declare function formatGB(bytes: number): string; /** Context window in compact units: 8192 → "8K", 131072 → "128K", 1e7 → "10M". */ export declare function formatCtx(tokens: number): string;