@agentjido/llmdb 2026.11.5 → 2026.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,3 +139,31 @@ imports and common bundlers need no file-system access or decompression.
139
139
 
140
140
  The NPM version is downstream from the `@version` value in `mix.exs`. Run
141
141
  `npm run npm:sync` at the repository root after the Elixir version changes.
142
+
143
+
144
+ ## Explicit metadata lookup and full downloads
145
+
146
+ Use the existing lookup APIs for local data. Use the online entry point to
147
+ query LLMCatalog for display, pricing, and lifecycle metadata for one exact offer.
148
+
149
+ ```ts
150
+ import { fetchModel } from "@agentjido/llmdb/online";
151
+
152
+ const model = await fetchModel("openrouter:openai/gpt-3.5-turbo-0613", {
153
+ timeoutMs: 5_000,
154
+ });
155
+ ```
156
+
157
+ For the complete offline catalog, get `catalog-full.json` and
158
+ `catalog-manifest.json` from the GitHub release that matches your package
159
+ version. Verify the release version, snapshot ID, byte count, and SHA-256 before
160
+ loading the trusted file. This example loads the verified file in Node.
161
+
162
+ ```ts
163
+ import { readFile } from "node:fs/promises";
164
+ import { createCatalogFromSnapshot, type Snapshot } from "@agentjido/llmdb";
165
+
166
+ const snapshot: Snapshot = JSON.parse(await readFile("catalog-full.json", "utf8"));
167
+ const catalog = createCatalogFromSnapshot(snapshot);
168
+ const model = catalog.get("openrouter:openai/gpt-3.5-turbo-0613");
169
+ ```
package/dist/catalog.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- import type { FullCatalog, Manifest, ProviderCatalog } from "./types.js";
1
+ import type { FullCatalog, Manifest, ProviderCatalog, Snapshot } from "./types.js";
2
2
  export declare function createCatalog(providers: readonly ProviderCatalog[], manifest: Manifest): FullCatalog;
3
+ /** Creates an offline catalog from a verified release snapshot. */
4
+ export declare function createCatalogFromSnapshot(snapshot: Snapshot): FullCatalog;
package/dist/catalog.js CHANGED
@@ -1,8 +1,39 @@
1
1
  import { ModelNotFoundError, ProviderNotFoundError, } from "./errors.js";
2
+ import { createProviderCatalog } from "./provider.js";
2
3
  import { normalizeProviderId, parseModelSpec } from "./spec.js";
3
4
  export function createCatalog(providers, manifest) {
4
5
  return new CompleteCatalog(providers, manifest);
5
6
  }
7
+ /** Creates an offline catalog from a verified release snapshot. */
8
+ export function createCatalogFromSnapshot(snapshot) {
9
+ if (snapshot.schema_version !== 1 || snapshot.version !== 2 ||
10
+ !/^[0-9a-f]{64}$/.test(snapshot.snapshot_id) || !snapshot.providers) {
11
+ throw new Error("Unsupported full catalog snapshot");
12
+ }
13
+ const providers = Object.values(snapshot.providers).map(provider => createProviderCatalog(provider));
14
+ const manifest = {
15
+ format_version: 1,
16
+ snapshot_schema_version: 1,
17
+ catalog_version: snapshot.version,
18
+ generated_at: snapshot.generated_at,
19
+ snapshot_id: snapshot.snapshot_id,
20
+ provider_count: providers.length,
21
+ model_count: providers.reduce((count, provider) => count + provider.modelIds.length, 0),
22
+ providers: Object.fromEntries(providers.map(provider => [
23
+ provider.id,
24
+ {
25
+ id: provider.id,
26
+ name: provider.data.name ?? null,
27
+ base_url: provider.data.base_url ?? null,
28
+ doc: provider.data.doc ?? null,
29
+ alias_of: provider.data.alias_of ?? null,
30
+ catalog_only: provider.data.catalog_only ?? false,
31
+ model_count: provider.modelIds.length,
32
+ },
33
+ ])),
34
+ };
35
+ return createCatalog(providers, manifest);
36
+ }
6
37
  class CompleteCatalog {
7
38
  manifest;
8
39
  #providers;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type * from "./types.js";
2
2
  export * from "./errors.js";
3
- export { createCatalog } from "./catalog.js";
3
+ export { createCatalog, createCatalogFromSnapshot } from "./catalog.js";
4
4
  export { createLLMDB, type CreateLLMDBOptions, type KnownProviderId, } from "./lazy.js";
5
5
  export { createProviderCatalog } from "./provider.js";
6
6
  export { formatModelSpec, parseModelSpec } from "./spec.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./errors.js";
2
- export { createCatalog } from "./catalog.js";
2
+ export { createCatalog, createCatalogFromSnapshot } from "./catalog.js";
3
3
  export { createLLMDB, } from "./lazy.js";
4
4
  export { createProviderCatalog } from "./provider.js";
5
5
  export { formatModelSpec, parseModelSpec } from "./spec.js";
@@ -0,0 +1,13 @@
1
+ /// <reference lib="dom" preserve="true" />
2
+ import type { JsonValue, ModelSpec } from "./types.js";
3
+ export interface ModelMetadata {
4
+ readonly id: string;
5
+ readonly provider: string;
6
+ readonly [field: string]: JsonValue | undefined;
7
+ }
8
+ export interface FetchModelOptions {
9
+ readonly timeoutMs?: number;
10
+ readonly fetch?: typeof globalThis.fetch;
11
+ }
12
+ /** Fetches display metadata for an exact provider-model ID. */
13
+ export declare function fetchModel(spec: ModelSpec, options?: FetchModelOptions): Promise<ModelMetadata>;
package/dist/online.js ADDED
@@ -0,0 +1,107 @@
1
+ /// <reference lib="dom" preserve="true" />
2
+ import { parseModelSpec } from "./spec.js";
3
+ const origin = "https://llmcatalog.dev/api/v1/models";
4
+ const maxBytes = 65_536;
5
+ const displayFields = {
6
+ name: nullableString,
7
+ release_date: nullableString,
8
+ last_updated: nullableString,
9
+ knowledge: nullableString,
10
+ limits: nullableNumbers,
11
+ cost: nullableNumbers,
12
+ pricing: (value) => value === null || (isObject(value) &&
13
+ nullableString(value.currency) && Array.isArray(value.components) &&
14
+ value.components.every(isObject)),
15
+ modalities: (value) => value === null || (isObject(value) &&
16
+ nullableStringList(value.input ?? null) && nullableStringList(value.output ?? null)),
17
+ capabilities: (value) => value === null || isObject(value),
18
+ tags: nullableStringList,
19
+ deprecated: isBoolean,
20
+ retired: isBoolean,
21
+ lifecycle: (value) => value === null || (isObject(value) &&
22
+ Object.values(value).every(nullableString)),
23
+ catalog_only: isBoolean,
24
+ aliases: isStringList,
25
+ };
26
+ /** Fetches display metadata for an exact provider-model ID. */
27
+ export async function fetchModel(spec, options = {}) {
28
+ const { providerId, modelId } = typeof spec === "string" ? parseModelSpec(spec) : spec;
29
+ if (typeof providerId !== "string" || !/^[a-z0-9][a-z0-9_.-]{0,63}$/.test(providerId)) {
30
+ throw new RangeError("Invalid provider ID");
31
+ }
32
+ if (typeof modelId !== "string")
33
+ throw new RangeError("Invalid model ID");
34
+ const pieces = modelId.split("/");
35
+ const timeout = options.timeoutMs ?? 5_000;
36
+ if (new TextEncoder().encode(modelId).length > 512 ||
37
+ pieces.some(piece => piece === "" || piece === "." || piece === "..")) {
38
+ throw new RangeError("Invalid model ID");
39
+ }
40
+ if (!Number.isInteger(timeout) || timeout < 1 || timeout > 30_000) {
41
+ throw new RangeError("Invalid request timeout");
42
+ }
43
+ const response = await (options.fetch ?? globalThis.fetch)(`${origin}/${encodeURIComponent(providerId)}/${pieces.map(encodeURIComponent).join("/")}`, { headers: { accept: "application/json" }, redirect: "error", signal: AbortSignal.timeout(timeout) });
44
+ if (response.status !== 200) {
45
+ await response.body?.cancel();
46
+ throw new Error(`LLMCatalog returned HTTP ${response.status}`);
47
+ }
48
+ const payload = JSON.parse(await readBounded(response));
49
+ if (!isObject(payload) || payload.schema_version !== 1 ||
50
+ typeof payload.snapshot_id !== "string" || !/^[0-9a-f]{64}$/.test(payload.snapshot_id) ||
51
+ !isObject(payload.model) || payload.model.id !== modelId || payload.model.provider !== providerId) {
52
+ throw new Error("Invalid model metadata");
53
+ }
54
+ const result = { id: modelId, provider: providerId };
55
+ for (const [field, validate] of Object.entries(displayFields)) {
56
+ if (!Object.hasOwn(payload.model, field))
57
+ continue;
58
+ const value = payload.model[field];
59
+ if (!validate(value))
60
+ throw new Error(`Invalid model metadata field: ${field}`);
61
+ result[field] = value;
62
+ }
63
+ return result;
64
+ }
65
+ async function readBounded(response) {
66
+ const reader = response.body?.getReader();
67
+ if (!reader)
68
+ throw new Error("Empty metadata response");
69
+ const decoder = new TextDecoder("utf-8", { fatal: true });
70
+ let bytes = 0;
71
+ let body = "";
72
+ try {
73
+ for (;;) {
74
+ const chunk = await reader.read();
75
+ if (chunk.done)
76
+ return body + decoder.decode();
77
+ bytes += chunk.value.byteLength;
78
+ if (bytes > maxBytes) {
79
+ await reader.cancel();
80
+ throw new Error("Metadata response exceeds the byte limit");
81
+ }
82
+ body += decoder.decode(chunk.value, { stream: true });
83
+ }
84
+ }
85
+ finally {
86
+ reader.releaseLock();
87
+ }
88
+ }
89
+ function isObject(value) {
90
+ return typeof value === "object" && value !== null && !Array.isArray(value);
91
+ }
92
+ function nullableString(value) {
93
+ return value === null || typeof value === "string";
94
+ }
95
+ function isBoolean(value) {
96
+ return typeof value === "boolean";
97
+ }
98
+ function isStringList(value) {
99
+ return Array.isArray(value) && value.every(item => typeof item === "string");
100
+ }
101
+ function nullableStringList(value) {
102
+ return value === null || isStringList(value);
103
+ }
104
+ function nullableNumbers(value) {
105
+ return value === null || (isObject(value) &&
106
+ Object.values(value).every(item => item === null || (typeof item === "number" && Number.isFinite(item))));
107
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentjido/llmdb",
3
- "version": "2026.11.5",
3
+ "version": "2026.11.6",
4
4
  "description": "Offline-first, provider-sharded LLM model metadata catalog.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Mike Hostetler",
@@ -58,6 +58,11 @@
58
58
  "import": "./dist/providers/*.js",
59
59
  "default": "./dist/providers/*.js"
60
60
  },
61
+ "./online": {
62
+ "types": "./dist/online.d.ts",
63
+ "import": "./dist/online.js",
64
+ "default": "./dist/online.js"
65
+ },
61
66
  "./package.json": "./package.json"
62
67
  },
63
68
  "publishConfig": {