@dbx-tools/dbx-model-catalog 0.2.0 → 0.3.0

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.
Files changed (54) hide show
  1. package/README.md +294 -57
  2. package/dist/_generated/channels.d.ts +4 -3
  3. package/dist/_generated/json-schema.d.ts +6527 -175
  4. package/dist/_generated/schemas.d.ts +154 -0
  5. package/dist/_generated/workspace-rules.d.ts +133 -0
  6. package/dist/browser.d.ts +34 -17
  7. package/dist/browser.js +1192 -149
  8. package/dist/catalog-index.d.ts +15 -2
  9. package/dist/chunk-engbh7tj.js +39 -0
  10. package/dist/chunk-gzjer0mc.js +1797 -0
  11. package/dist/chunk-pp7fw379.js +51 -0
  12. package/dist/chunk-pwssxaq0.js +39 -0
  13. package/dist/cli.js +9 -654
  14. package/dist/effective.d.ts +31 -0
  15. package/dist/index.d.ts +33 -16
  16. package/dist/index.js +60 -660
  17. package/dist/local-client.d.ts +16 -3
  18. package/dist/pynect.d.ts +6 -3
  19. package/dist/search.d.ts +7 -1
  20. package/dist/serving-endpoints.d.ts +15 -0
  21. package/dist/sources.d.ts +30 -0
  22. package/dist/types.d.ts +31 -3
  23. package/dist/validation.d.ts +15 -1
  24. package/dist/workspace-cache.d.ts +68 -0
  25. package/dist/workspace-client.d.ts +49 -0
  26. package/dist/workspace-connection.d.ts +67 -0
  27. package/dist/workspace-file-cache.d.ts +11 -0
  28. package/dist/workspace-identity.d.ts +27 -0
  29. package/dist/workspace-overlay.d.ts +71 -0
  30. package/package.json +5 -6
  31. package/src/_generated/channels.ts +5 -2
  32. package/src/_generated/json-schema.ts +4 -2
  33. package/src/_generated/schemas.ts +177 -0
  34. package/src/_generated/workspace-rules.ts +285 -0
  35. package/src/browser.ts +105 -54
  36. package/src/catalog-index.ts +46 -19
  37. package/src/cli.ts +8 -11
  38. package/src/effective.ts +200 -0
  39. package/src/identity.ts +3 -26
  40. package/src/index.ts +155 -82
  41. package/src/local-client.ts +94 -18
  42. package/src/pynect.ts +28 -65
  43. package/src/search.ts +48 -0
  44. package/src/serving-endpoints.ts +157 -0
  45. package/src/sources.ts +107 -0
  46. package/src/types.ts +32 -2
  47. package/src/validation.ts +33 -0
  48. package/src/workspace-cache.ts +234 -0
  49. package/src/workspace-client.ts +134 -0
  50. package/src/workspace-connection.ts +160 -0
  51. package/src/workspace-file-cache.ts +45 -0
  52. package/src/workspace-identity.ts +77 -0
  53. package/src/workspace-overlay.ts +200 -0
  54. package/dist/pynect.js +0 -557
package/README.md CHANGED
@@ -1,94 +1,331 @@
1
1
  # @dbx-tools/dbx-model-catalog
2
2
 
3
- The default Node client loads the JSON catalog and search index directly. It
4
- does not install or start Python, uv, Pynect, or Pyfig.
5
- The package contains public catalog data only. It does not authenticate to a
6
- Databricks workspace or discover customer endpoints.
3
+ Node and browser client for the published Databricks model catalog. By default
4
+ it loads the public catalog JSON and search index and never contacts a
5
+ Databricks workspace. Give it a workspace connection and it also lists your
6
+ Serving Endpoints, merges them over the public records, and serves that
7
+ effective catalog through the same `list`, `get`, `resolve`, `search`, and
8
+ `stream` calls, including private models the public catalog does not know.
9
+
10
+ The Python package `dbx-model-catalog` has the same client. Each example below
11
+ has a line-for-line Python counterpart in
12
+ [its README](../../py/core/README.md), differing only in casing and async
13
+ style. The default client does not install or start Python, uv, or Pyfig, and
14
+ the package has no Databricks SDK runtime dependency.
15
+
16
+ ## Create a client
17
+
18
+ `createModelCatalogClient(source?, options?)` is the one entry point, exported
19
+ from both `@dbx-tools/dbx-model-catalog` (Node) and
20
+ `@dbx-tools/dbx-model-catalog/browser`:
7
21
 
8
22
  ```ts
9
- import { connectModelCatalog } from "@dbx-tools/dbx-model-catalog";
23
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
24
+
25
+ await using client = await createModelCatalogClient();
26
+ const matches = await client.list({ query: "gpt", limit: 10 });
27
+ const model = await client.get("system.ai.gpt-6-1-sol");
28
+ const ranked = await client.search("claude reasoning", 5);
29
+ ```
10
30
 
11
- await using local = await connectModelCatalog();
12
- const matches = await local.client.list({ query: "gpt", limit: 10 });
31
+ The first argument selects where the public catalog comes from, and every
32
+ source builds the same client:
13
33
 
14
- await using remote = await connectModelCatalog("https://example.com/catalog.json");
15
- const catalog = await remote.client.catalog();
34
+ | Source | Loads |
35
+ | --- | --- |
36
+ | none | The published catalog, or the files named by `DBX_MODEL_CATALOG_PATH` (Node) |
37
+ | `https://.../catalog.json` | That catalog and the `search-index.json` beside it |
38
+ | `ws://` or `wss://` server URL | The catalog and search index from the Python catalog server |
39
+ | file path or `file:` URL (Node) | That file and the `search-index.json` beside it |
40
+ | a `ModelCatalog` value | That catalog, with its index as `options.searchIndex` |
41
+
42
+ `options.searchIndex` overrides the search index with a payload, a URL, or (in
43
+ Node) a file path. `client.source` reports `{ kind, location }`. Without
44
+ workspace options the client makes no workspace request and
45
+ `workspaceStatus()` reports `{ status: "disabled" }`.
46
+
47
+ ```ts
48
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
49
+
50
+ await using local = await createModelCatalogClient("catalog.json");
51
+ await using remote = await createModelCatalogClient("https://example.com/catalog.json");
52
+ console.log(local.source.kind, remote.source.location);
16
53
  ```
17
54
 
18
- Set `DBX_MODEL_CATALOG_PATH` to load a local catalog. The client loads
19
- `search-index.json` from the same directory unless `searchIndexPath` is set.
20
- Generated catalog types are re-exported from the package.
55
+ `close()` waits for in-flight workspace refreshes; `await using` calls it.
56
+
57
+ ### The Python catalog server
21
58
 
22
- The browser-safe entry point also exports the catalog-owned Zod schemas. Use
23
- these schemas directly in downstream wire contracts instead of recreating the
24
- catalog fields:
59
+ A `ws://` or `wss://` URL downloads the catalog and search index from the
60
+ Python catalog server once, then serves them from the same local client, so
61
+ `modelServingClient` enrichment works the same way. This transport needs the
62
+ optional peers `pynect` and `@chanx-js/client`; without them the client fails
63
+ with an error telling you to install them. They are not runtime dependencies
64
+ of the default client.
25
65
 
26
66
  ```ts
27
- import {
28
- CatalogModelRecordSchema,
29
- CatalogStatusSchema,
30
- type CatalogModelRecord,
31
- } from "@dbx-tools/dbx-model-catalog/browser";
67
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
32
68
 
33
- const model: CatalogModelRecord = CatalogModelRecordSchema.parse(value);
34
- const status = CatalogStatusSchema.parse(model.status);
69
+ await using client = await createModelCatalogClient("ws://127.0.0.1:8787");
70
+ const matches = await client.list({ query: "gpt", limit: 10 });
71
+ ```
72
+
73
+ ## Workspace-enriched catalog
74
+
75
+ Pass one `modelServingClient`. Its type, `ModelServingClientOption`, is a
76
+ union of these forms, and the client normalizes it once internally:
77
+
78
+ | Form | Notes |
79
+ | --- | --- |
80
+ | `@databricks/sdk-experimental` `WorkspaceClient` | Reuses its host, authentication, and transport |
81
+ | `@databricks/sdk-modelserving/v1` `ModelServingClient` | Session-only cache: it exposes no host or principal |
82
+ | `{ host, headers }` connection (`ModelServingConnection`) | Headers are sent on every Serving Endpoints request |
83
+ | Sync or async function returning a connection (`ModelServingConnectionGenerator`) | Called once per refresh attempt |
84
+
85
+ An unsupported value, or a static connection without a host, fails before any
86
+ request with an error naming the supported forms. The catalog never resolves
87
+ profiles or stored credentials itself. Both SDK client shapes are typed
88
+ structurally (`WorkspaceClientLike`, `ModelServingSdkClientLike`), so the
89
+ package has no SDK runtime dependency. Listings follow `next_page_token` until
90
+ every page is read.
91
+
92
+ ### An existing SDK workspace client
93
+
94
+ The SDK client stays the only authentication owner. Build it however your
95
+ application already does, for example from a profile:
96
+
97
+ ```ts
98
+ import { WorkspaceClient } from "@databricks/sdk-experimental";
99
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
100
+
101
+ const workspaceClient = new WorkspaceClient({ profile: "my-profile" });
102
+ await using client = await createModelCatalogClient(undefined, { modelServingClient: workspaceClient });
103
+
104
+ const privateModel = await client.get("databricks-gpt-6-3");
105
+ const accessible = await client.isAccessible("databricks-gpt-6-3");
106
+ const status = await client.workspaceStatus(); // { status: "current", ... }
35
107
  ```
36
108
 
37
- For direct public ingestion without the service client, use the exported URL
38
- for the schema this package was generated against:
109
+ ### A modular Model Serving SDK client
110
+
111
+ The client calls `listInferenceEndpoints({})` and converts the camelCase,
112
+ `bigint`-timestamped result back to the snake_case Serving Endpoints wire
113
+ shape before normalizing it. This client keeps its host and credentials
114
+ private and has no current-user lookup, so its overlay is kept in session
115
+ memory only (`workspaceStatus().persistent` is `false` and `workspace` is
116
+ unset). The SDK drops fields its model does not declare, such as the
117
+ foundation model class, the AI Gateway profile, and endpoint capabilities, so
118
+ those values come from the public record when the endpoint matches one.
39
119
 
40
120
  ```ts
41
- import {
42
- PUBLISHED_CATALOG_INDEX_URL,
43
- PUBLISHED_CATALOG_URL,
44
- } from "@dbx-tools/dbx-model-catalog/browser";
121
+ import { ModelServingClient as ServingClient } from "@databricks/sdk-modelserving/v1";
122
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
45
123
 
46
- const catalog = await fetch(PUBLISHED_CATALOG_URL).then(response => response.json());
47
- const registry = await fetch(PUBLISHED_CATALOG_INDEX_URL).then(response => response.json());
124
+ await using client = await createModelCatalogClient(undefined, {
125
+ modelServingClient: new ServingClient({ host: "https://adb-1234567890123456.7.azuredatabricks.net" }),
126
+ });
127
+ const chat = await client.list({ type: ["chat"], limit: null });
128
+ ```
129
+
130
+ ### A connection value
131
+
132
+ `host` may be a bare host or a workspace URL. The headers are sent on every
133
+ Serving Endpoints request and are never cached or persisted. Use this form for
134
+ short-lived credentials.
135
+
136
+ ```ts
137
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
138
+
139
+ declare const token: string;
140
+
141
+ await using client = await createModelCatalogClient(undefined, {
142
+ modelServingClient: {
143
+ host: "https://adb-1234567890123456.7.azuredatabricks.net",
144
+ headers: { Authorization: `Bearer ${token}` },
145
+ },
146
+ });
147
+ const best = (await client.search("gpt 6.3", 1))[0]?.record.id;
148
+ ```
149
+
150
+ ### A connection generator
151
+
152
+ A sync or async function returning a connection. It is called once per refresh
153
+ attempt, and that connection serves both the principal lookup and the Serving
154
+ Endpoints listing, so refreshed credentials apply without rebuilding the
155
+ client. A connection without a host fails that refresh, which is reported in the
156
+ status rather than thrown.
157
+
158
+ ```ts
159
+ import { type ModelServingConnectionGenerator, createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
160
+
161
+ declare function currentToken(): Promise<string>;
162
+
163
+ const currentConnection: ModelServingConnectionGenerator = async () => ({
164
+ host: "adb-1234567890123456.7.azuredatabricks.net",
165
+ headers: { Authorization: `Bearer ${await currentToken()}` },
166
+ });
167
+ await using client = await createModelCatalogClient(undefined, { modelServingClient: currentConnection });
168
+ const tools = await client.list({ capability: ["tools"], limit: null });
169
+ ```
170
+
171
+ ### Browser
172
+
173
+ The `/browser` entry point's `modelServingClient` accepts only connection
174
+ values and generators (`BrowserModelServingClientOption`), and keeps overlays
175
+ in memory. It never touches the filesystem or local profiles, so supply your
176
+ own short-lived headers. Relative catalog URLs resolve against the page.
177
+
178
+ ```ts
179
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog/browser";
180
+
181
+ declare function getAccessToken(): Promise<string>;
182
+
183
+ await using client = await createModelCatalogClient(undefined, {
184
+ modelServingClient: async () => ({
185
+ host: "https://adb-1234567890123456.7.azuredatabricks.net",
186
+ headers: { Authorization: `Bearer ${await getAccessToken()}` },
187
+ }),
188
+ });
189
+ const chatModels = await client.list({ type: ["chat"], limit: null });
190
+ ```
191
+
192
+ ## Effective catalog, status, and provenance
193
+
194
+ ```ts
195
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
196
+
197
+ declare const token: string;
198
+
199
+ await using client = await createModelCatalogClient(undefined, {
200
+ modelServingClient: { host: "dbc-a1b2c3d4-e5f6.cloud.databricks.com", headers: { Authorization: `Bearer ${token}` } },
201
+ });
202
+ const effective = await client.effectiveCatalog();
203
+ for (const [name, endpoint] of Object.entries(effective.endpoints)) {
204
+ // `match` is the public record the endpoint joined to, if any; `fields` says where each
205
+ // overlaid value came from: "workspace", "public", or a schema-required "placeholder".
206
+ console.log(name, endpoint.state, endpoint.match?.id, endpoint.fields);
207
+ }
208
+ ```
209
+
210
+ - Record ids in the effective catalog are invocable endpoint names. Public order
211
+ is kept; an endpoint named like a public id replaces it in place, and other
212
+ endpoints follow sorted by name.
213
+ - An endpoint joins a public record by exact identity only (endpoint name,
214
+ served entity, foundation model, external model, `provider/name`, or
215
+ `system.ai.` model service), case-insensitively and then by normalized
216
+ identity. There is no fuzzy matching.
217
+ - Live display name, description, family, and function calling override the
218
+ public values. Missing live values keep the public value and its sources.
219
+ Absent capabilities stay unknown, never `false`.
220
+ - An unmatched endpoint whose task maps to a catalog type (for example
221
+ `llm/v1/chat` or `agent/v1/responses`, both `chat`) becomes a sparse record
222
+ whose schema-required unknowns are `placeholder` values.
223
+ - An unmatched endpoint with no task, or a task with no type mapping (such as a
224
+ custom Unity Catalog model endpoint), gets no record because any type would
225
+ be invented. It is listed in `effective.endpoints` by name and
226
+ `isAccessible(name)` is `true`, but it is absent from `catalog()`, `list`,
227
+ `get`, and `search`.
228
+ - Public records without a live endpoint stay searchable, but
229
+ `isAccessible(id)` is `true` only for endpoints the workspace listed.
230
+
231
+ ## Refresh, cache, and eviction
232
+
233
+ Reads are lazy: the first read lists the endpoints. Later reads reuse the
234
+ overlay and attempt a refresh at most every five minutes. Concurrent reads share
235
+ one attempt. If a refresh fails, the last overlay is served for up to seven days
236
+ with `status: "stale"`, its age, and the error. If no overlay exists, the public
237
+ catalog is served with `status: "unavailable"` and no access claims.
238
+
239
+ Overlays are cached under the workspace identity (the `X-Databricks-Org-Id`
240
+ or `X-Databricks-Workspace-Id` header, else a workspace ID in the host or `o=`
241
+ query, else the normalized host), the effective-contract version, and a SHA-256 of the caller's SCIM id.
242
+ On Node they persist to a file in the user cache directory; only the
243
+ normalized endpoint inventory is stored, never headers, tokens, or the
244
+ principal. When the workspace or principal cannot be determined the overlay
245
+ stays in the client's memory and `workspaceStatus().persistent` is `false`.
246
+
247
+ ```ts
248
+ import { createModelCatalogClient } from "@dbx-tools/dbx-model-catalog";
249
+
250
+ declare const token: string;
251
+
252
+ await using client = await createModelCatalogClient(undefined, {
253
+ modelServingClient: { host: "adb-1234567890123456.7.azuredatabricks.net", headers: { Authorization: `Bearer ${token}` } },
254
+ workspaceCache: { refreshAfterMs: 60_000, filename: "/tmp/model-catalog-workspace.json" },
255
+ });
256
+
257
+ const refreshed = await client.refreshWorkspace(); // never throws; check refreshed.status
258
+ await client.evictWorkspace(); // this workspace and principal only
259
+ await client.evictWorkspace({ all: true }); // every cached overlay
48
260
  ```
49
261
 
50
- The `/browser` entry point exports `loadModelCatalog()` and
51
- `createModelCatalogClient()` for browser and worker use. Both use the same
52
- TypeScript filtering and ranked-search implementation as the Node entry point.
262
+ Set `workspaceCache: { persistent: false }` to keep overlays in process memory,
263
+ pass a Keyv-compatible `store`, or pass a prepared `cache` such as
264
+ `createPersistentWorkspaceCatalogCache()`.
265
+
266
+ ## An already-loaded catalog
53
267
 
54
- Load the public catalog remotely when matching and enriching endpoints that
55
- another client already discovered:
268
+ Pass a `ModelCatalog` value with its search index to build the same client
269
+ without a download, for example over a catalog your application already caches:
56
270
 
57
271
  ```ts
58
272
  import {
59
- enrichLiveModels,
60
- loadModelCatalogIndex,
61
- } from "@dbx-tools/dbx-model-catalog/browser";
273
+ type CatalogSearchIndexPayload,
274
+ type ModelCatalog,
275
+ type WorkspaceClientLike,
276
+ createModelCatalogClient,
277
+ createPersistentWorkspaceCatalogCache,
278
+ } from "@dbx-tools/dbx-model-catalog";
62
279
 
63
- const modelCatalogIndex = await loadModelCatalogIndex();
280
+ declare const workspaceClient: WorkspaceClientLike;
281
+ declare const catalog: ModelCatalog;
282
+ declare const searchIndex: CatalogSearchIndexPayload;
64
283
 
65
- const enriched = enrichLiveModels(
66
- modelCatalogIndex,
67
- liveEndpoints,
68
- endpoint => [endpoint.name, endpoint.modelServiceName].filter(Boolean),
69
- );
284
+ await using client = await createModelCatalogClient(catalog, {
285
+ searchIndex,
286
+ modelServingClient: workspaceClient,
287
+ workspaceCache: { cache: createPersistentWorkspaceCatalogCache(), persistent: true },
288
+ });
70
289
  ```
71
290
 
72
- The join preserves live records that have no public catalog match. Workspace
73
- discovery remains authoritative when documentation lags. The npm package does
74
- not embed a catalog snapshot; catalog and search data are fetched from the
75
- published schema URL.
291
+ ## Schemas and URLs
76
292
 
77
- The local explorer demo uses the explicit Pynect adapter to connect to the
78
- Python server:
293
+ Generated catalog types are exported from both entry points, along with the
294
+ catalog-owned Zod schemas and parsers. Use them in downstream wire contracts
295
+ instead of recreating the catalog fields:
79
296
 
80
297
  ```ts
81
- import { createPynectCatalogClient } from "@dbx-tools/dbx-model-catalog/pynect";
298
+ import {
299
+ CatalogModelRecordSchema,
300
+ CatalogStatusSchema,
301
+ type CatalogModelRecord,
302
+ } from "@dbx-tools/dbx-model-catalog/browser";
82
303
 
83
- const client = createPynectCatalogClient({ baseUrl: "ws://127.0.0.1:8787" });
84
- const matches = await client.list({ query: "gpt", limit: 10 });
85
- client.close();
304
+ declare const value: unknown;
305
+
306
+ const model: CatalogModelRecord = CatalogModelRecordSchema.parse(value);
307
+ const status = CatalogStatusSchema.parse(model.status);
86
308
  ```
87
309
 
88
- Install `pynect` and `@chanx-js/client` only when using this optional adapter.
89
- They are not runtime dependencies of the default client.
310
+ For direct public ingestion, use the URL for the schema this package was
311
+ generated against:
312
+
313
+ ```ts
314
+ import {
315
+ PUBLISHED_CATALOG_INDEX_URL,
316
+ PUBLISHED_CATALOG_URL,
317
+ } from "@dbx-tools/dbx-model-catalog/browser";
318
+
319
+ const catalog = await fetch(PUBLISHED_CATALOG_URL).then(response => response.json());
320
+ const registry = await fetch(PUBLISHED_CATALOG_INDEX_URL).then(response => response.json());
321
+ ```
90
322
 
91
323
  The current URL is
92
324
  <https://raw.githubusercontent.com/reggie-db/dbx-model-catalog/main/packages/js/web/catalog/v16/catalog.json>.
93
325
  Its `updated_at` field records the latest source-fetch timestamp represented by
94
- the catalog.
326
+ the catalog. The npm package does not embed a catalog snapshot.
327
+
328
+ Each entry point exports only the client, its option and result types, the
329
+ catalog and effective-catalog types and schemas, the connection forms, and the
330
+ cache options. Endpoint normalization, overlay construction, and index building
331
+ are internal; `test/package-surface.test.ts` lists the exported names.
@@ -1,10 +1,11 @@
1
- import type { GetCatalogRequest, GetCatalogResponse, GetSearchIndexRequest, GetSearchIndexResponse, ListModelsRequest, ListModelsResponse, StreamModelsRequest, StreamModelsResponse } from './schemas.js';
2
- export type ModelsToServer = GetCatalogRequest | GetSearchIndexRequest | ListModelsRequest | StreamModelsRequest;
3
- export type ModelsToClient = GetCatalogResponse | GetSearchIndexResponse | ListModelsResponse | StreamModelsResponse;
1
+ import type { GetCatalogRequest, GetCatalogResponse, GetSearchIndexRequest, GetSearchIndexResponse, ListModelsRequest, ListModelsResponse, OverlayServingEndpointsRequest, OverlayServingEndpointsResponse, StreamModelsRequest, StreamModelsResponse } from './schemas.js';
2
+ export type ModelsToServer = GetCatalogRequest | GetSearchIndexRequest | ListModelsRequest | OverlayServingEndpointsRequest | StreamModelsRequest;
3
+ export type ModelsToClient = GetCatalogResponse | GetSearchIndexResponse | ListModelsResponse | OverlayServingEndpointsResponse | StreamModelsResponse;
4
4
  export type ModelsReplies = {
5
5
  get_catalog: GetCatalogResponse;
6
6
  get_search_index: GetSearchIndexResponse;
7
7
  list_models: ListModelsResponse;
8
+ overlay_serving_endpoints: OverlayServingEndpointsResponse;
8
9
  stream_models: StreamModelsResponse;
9
10
  };
10
11
  export declare const models: import("@chanx-js/client").ChannelDescriptor<ModelsToServer, ModelsToClient, "/ws/models", Record<never, never>, ModelsReplies> & {