@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
@@ -1,4 +1,17 @@
1
1
  import type { CatalogSearchIndexPayload, ModelCatalog } from "./_generated/schemas.js";
2
- import type { CatalogClient } from "./types.js";
3
- export declare function createModelCatalogClient(catalog: ModelCatalog, searchIndex: CatalogSearchIndexPayload): CatalogClient;
4
- export { filterCatalogRecords } from "./filter.js";
2
+ import type { ModelCatalogClient, ModelCatalogSource } from "./types.js";
3
+ import type { ModelServingConnector } from "./workspace-connection.js";
4
+ import { type WorkspaceCacheOptions, WorkspaceOverlaySession } from "./workspace-overlay.js";
5
+ /** Overlay session for a normalized connector, or `undefined` for a public-only client. Internal. */
6
+ export declare function workspaceOverlay(connector: ModelServingConnector | undefined, cache?: WorkspaceCacheOptions): WorkspaceOverlaySession | undefined;
7
+ /** A loaded public catalog, its search index, and where they came from. */
8
+ export interface LoadedCatalog {
9
+ readonly catalog: ModelCatalog;
10
+ readonly searchIndex: CatalogSearchIndexPayload;
11
+ readonly source: ModelCatalogSource;
12
+ }
13
+ /**
14
+ * The effective catalog client over a loaded public catalog and an optional overlay session. Every
15
+ * source builds this same client, so workspace enrichment works the same for each. Internal.
16
+ */
17
+ export declare function createCatalogClient({ catalog, searchIndex, source }: LoadedCatalog, overlay: WorkspaceOverlaySession | undefined): ModelCatalogClient;
package/dist/pynect.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- import type { ClientOptions } from "@chanx-js/client";
2
- import type { CatalogClient } from "./types.js";
3
- export declare function createPynectCatalogClient(options: ClientOptions): CatalogClient;
1
+ import type { CatalogSearchIndexPayload, ModelCatalog } from "./_generated/schemas.js";
2
+ /** Pull the catalog and its search index from the server, then close the connection. */
3
+ export declare function downloadWebSocketCatalog(baseUrl: string): Promise<{
4
+ catalog: ModelCatalog;
5
+ searchIndex: CatalogSearchIndexPayload;
6
+ }>;
package/dist/search.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CatalogModelRecord, CatalogSearchIndexPayload } from "./_generated/schemas.js";
1
+ import type { CatalogModelRecord, CatalogSearchIndexDocument, CatalogSearchIndexPayload, CatalogSearchQualityScores, CatalogSearchWeights } from "./_generated/schemas.js";
2
2
  export interface CatalogSearchMatch {
3
3
  readonly exact: boolean;
4
4
  readonly kind: "exact" | "fuzzy" | "token";
@@ -8,3 +8,9 @@ export interface CatalogSearchMatch {
8
8
  }
9
9
  export declare function searchCatalogRecords<T extends CatalogModelRecord>(index: CatalogSearchIndexPayload, models: readonly T[], query: string, limit?: number | null): T[];
10
10
  export declare function searchCatalogMatches<T extends CatalogModelRecord>(index: CatalogSearchIndexPayload, models: readonly T[], query: string, limit?: number | null): CatalogSearchMatch[];
11
+ /** Query-independent quality signals carried by one search document. */
12
+ export type CatalogSearchQuality = Pick<CatalogSearchIndexDocument, "quality_score" | "scores">;
13
+ /** Quality signals for precomputed scores, weighted like the published search index. */
14
+ export declare function catalogSearchQuality(scores: CatalogSearchQualityScores, weights: CatalogSearchWeights): CatalogSearchQuality;
15
+ /** Search document for one record, with text fields derived exactly as the published index does. */
16
+ export declare function catalogSearchDocument(record: CatalogModelRecord, quality: CatalogSearchQuality): CatalogSearchIndexDocument;
@@ -0,0 +1,15 @@
1
+ import type { EffectiveEndpoint, IdentityCandidate, ServingEndpoint, ServingEndpointsResponse } from "./_generated/schemas.js";
2
+ /** Catalog-owned normalized Serving Endpoints record; absent values stay absent (unknown). */
3
+ export type WorkspaceEndpoint = Omit<EffectiveEndpoint, "match" | "fields">;
4
+ /**
5
+ * Validate a raw `GET /api/2.0/serving-endpoints` listing and normalize every named endpoint,
6
+ * sorted by name. Endpoints without a name are skipped; a repeated name keeps its first entry.
7
+ */
8
+ export declare function normalizeServingEndpoints(response: ServingEndpointsResponse | unknown): WorkspaceEndpoint[];
9
+ /** Normalize one raw endpoint through the shared `WORKSPACE_OVERLAY_RULES` table. */
10
+ export declare function normalizeServingEndpoint(endpoint: ServingEndpoint | unknown): WorkspaceEndpoint;
11
+ /** Exact identities in rule order, deduplicated by value; `system.ai.` entities are model services. */
12
+ export declare function endpointIdentityCandidates(endpoint: ServingEndpoint | unknown): IdentityCandidate[];
13
+ /** Lowercase slug matching published catalog family values. */
14
+ export declare function normalizeFamily(value: string): string | undefined;
15
+ export declare function compareCodePoints(left: string, right: string): number;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Browser-safe catalog source loading for `createModelCatalogClient`. Internal: the Node entry
3
+ * point adds file paths and `DBX_MODEL_CATALOG_PATH` on top of these loaders.
4
+ */
5
+ import type { CatalogSearchIndexPayload, ModelCatalog } from "./_generated/schemas.js";
6
+ import type { LoadedCatalog } from "./local-client.js";
7
+ /**
8
+ * A catalog source: an `http(s)` catalog URL, a `ws(s)` URL of the Python catalog server, or an
9
+ * already-loaded catalog. The Node entry point also accepts file paths and `file:` URLs.
10
+ */
11
+ export type ModelCatalogSourceInput = string | URL | ModelCatalog;
12
+ /** Source-loading options shared by both entry points. */
13
+ export interface CatalogSourceOptions {
14
+ /** Transport for catalog downloads and workspace requests. */
15
+ fetch?: typeof globalThis.fetch;
16
+ /**
17
+ * The search index: a payload (required with an in-memory catalog) or its URL (in Node, also a
18
+ * file path). Defaults to `search-index.json` beside a catalog URL or file. WebSocket sources
19
+ * always read the server's index.
20
+ */
21
+ searchIndex?: CatalogSearchIndexPayload | string;
22
+ }
23
+ export declare function isWebSocketUrl(value: string): boolean;
24
+ export declare function isHttpUrl(value: string): boolean;
25
+ /** Load a source in any runtime: published default, URL download, WebSocket, or in-memory. */
26
+ export declare function loadBrowserSource(source: ModelCatalogSourceInput | undefined, options: CatalogSourceOptions): Promise<LoadedCatalog>;
27
+ export declare function loadPublished(options: CatalogSourceOptions): Promise<LoadedCatalog>;
28
+ export declare function loadUrl(url: string, options: CatalogSourceOptions): Promise<LoadedCatalog>;
29
+ export declare function loadMemory(catalog: ModelCatalog, options: CatalogSourceOptions): LoadedCatalog;
30
+ export declare function loadWebSocket(url: string): Promise<LoadedCatalog>;
package/dist/types.d.ts CHANGED
@@ -1,7 +1,22 @@
1
- import type { CatalogFilters, CatalogModelRecord, CatalogSearchIndexPayload, ModelCatalog } from "./_generated/schemas.js";
1
+ import type { CatalogFilters, CatalogModelRecord, CatalogSearchIndexPayload, EffectiveModelCatalog, ModelCatalog, WorkspaceRefresh } from "./_generated/schemas.js";
2
2
  import type { CatalogIdentityMatch } from "./catalog-index.js";
3
3
  import type { CatalogSearchMatch } from "./search.js";
4
- export interface CatalogClient {
4
+ /** Where a client's public catalog came from. */
5
+ export type ModelCatalogSourceKind = "published" | "url" | "websocket" | "file" | "memory";
6
+ export interface ModelCatalogSource {
7
+ readonly kind: ModelCatalogSourceKind;
8
+ /** Catalog URL, WebSocket server URL, or resolved file path; absent for an in-memory catalog. */
9
+ readonly location?: string;
10
+ }
11
+ /**
12
+ * Catalog client over the effective catalog: the public records plus, when a workspace connection
13
+ * is configured, the caller's accessible Serving Endpoints. `catalog`, `searchIndex`, `list`, `get`,
14
+ * `resolve`, `search`, and `stream` all read the effective records. Without a workspace connection
15
+ * the status is `disabled` and no workspace request is ever made.
16
+ */
17
+ export interface ModelCatalogClient extends AsyncDisposable {
18
+ /** Where the public catalog was loaded from. */
19
+ readonly source: ModelCatalogSource;
5
20
  catalog(): Promise<ModelCatalog>;
6
21
  searchIndex(): Promise<CatalogSearchIndexPayload>;
7
22
  list(filters?: CatalogFilters): Promise<CatalogModelRecord[]>;
@@ -9,5 +24,18 @@ export interface CatalogClient {
9
24
  resolve(identity: string): Promise<CatalogIdentityMatch | undefined>;
10
25
  search(query: string, limit?: number | null): Promise<CatalogSearchMatch[]>;
11
26
  stream(filters?: CatalogFilters): AsyncGenerator<CatalogModelRecord>;
12
- close(): void;
27
+ /** Merged records with workspace refresh state, endpoint access, and field provenance. */
28
+ effectiveCatalog(): Promise<EffectiveModelCatalog>;
29
+ /** Workspace refresh state of the served effective catalog. */
30
+ workspaceStatus(): Promise<WorkspaceRefresh>;
31
+ /** True when the connected workspace listed `id` as an invocable endpoint. */
32
+ isAccessible(id: string): Promise<boolean>;
33
+ /** Refresh this workspace and principal's overlay now; failures are reported, not thrown. */
34
+ refreshWorkspace(): Promise<WorkspaceRefresh>;
35
+ /** Drop this workspace and principal's cached overlay, or every cached overlay with `all`. */
36
+ evictWorkspace(options?: {
37
+ all?: boolean;
38
+ }): Promise<void>;
39
+ /** Wait for in-flight and background workspace refreshes. */
40
+ close(): Promise<void>;
13
41
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import type { AveragePrice, Capabilities, CatalogModel, CatalogModelRecord, CatalogSearchIndexPayload, Latency, ModelCatalog, Price, Rankings, Rankings1, RateLimits, Status } from "./_generated/schemas.js";
2
+ import type { AveragePrice, Capabilities, CatalogModel, CatalogModelRecord, CatalogSearchIndexPayload, EffectiveModelCatalog, Latency, ModelCatalog, Price, Rankings, Rankings1, RateLimits, ServingEndpoint, ServingEndpointsResponse, Status, WorkspaceRefresh } from "./_generated/schemas.js";
3
3
  /** Runtime schema for the complete published model catalog. */
4
4
  export declare const ModelCatalogSchema: z.ZodType<ModelCatalog>;
5
5
  /** Runtime schema for the published catalog search index. */
@@ -26,9 +26,23 @@ export declare const CatalogScoreRankingSchema: z.ZodType<Rankings1, unknown, z.
26
26
  export declare const CatalogRankingSchema: z.ZodUnion<readonly [z.ZodType<Rankings, unknown, z.core.$ZodTypeInternals<Rankings, unknown>>, z.ZodType<Rankings1, unknown, z.core.$ZodTypeInternals<Rankings1, unknown>>]>;
27
27
  /** Runtime schema for a catalog model lifecycle status. */
28
28
  export declare const CatalogStatusSchema: z.ZodType<Status, unknown, z.core.$ZodTypeInternals<Status, unknown>>;
29
+ /** Runtime schema for a workspace-effective catalog (public catalog plus accessible endpoints). */
30
+ export declare const EffectiveModelCatalogSchema: z.ZodType<EffectiveModelCatalog, unknown, z.core.$ZodTypeInternals<EffectiveModelCatalog, unknown>>;
31
+ /** Runtime schema for workspace overlay refresh state. */
32
+ export declare const WorkspaceRefreshSchema: z.ZodType<WorkspaceRefresh, unknown, z.core.$ZodTypeInternals<WorkspaceRefresh, unknown>>;
33
+ /** Runtime schema for a raw `GET /api/2.0/serving-endpoints` response; unknown members are ignored. */
34
+ export declare const ServingEndpointsResponseSchema: z.ZodType<ServingEndpointsResponse, unknown, z.core.$ZodTypeInternals<ServingEndpointsResponse, unknown>>;
35
+ /** Runtime schema for one raw serving endpoint. */
36
+ export declare const ServingEndpointSchema: z.ZodType<ServingEndpoint, unknown, z.core.$ZodTypeInternals<ServingEndpoint, unknown>>;
29
37
  /** Validate an untrusted catalog payload against the Python-owned contract. */
30
38
  export declare function parseModelCatalog(value: unknown): ModelCatalog;
31
39
  /** Validate an untrusted search-index payload against the Python-owned contract. */
32
40
  export declare function parseCatalogSearchIndex(value: unknown): CatalogSearchIndexPayload;
33
41
  /** Validate one untrusted catalog model record. */
34
42
  export declare function parseCatalogModelRecord(value: unknown): CatalogModelRecord;
43
+ /** Validate an untrusted effective catalog payload. */
44
+ export declare function parseEffectiveModelCatalog(value: unknown): EffectiveModelCatalog;
45
+ /** Validate a raw Serving Endpoints listing. */
46
+ export declare function parseServingEndpointsResponse(value: unknown): ServingEndpointsResponse;
47
+ /** Validate one raw serving endpoint. */
48
+ export declare function parseServingEndpoint(value: unknown): ServingEndpoint;
@@ -0,0 +1,68 @@
1
+ import type { WorkspaceIdentity } from "./workspace-identity.js";
2
+ /** Five minutes, from the shared `cache.refresh_interval_seconds` rule. */
3
+ export declare const DEFAULT_WORKSPACE_REFRESH_AFTER_MS: number;
4
+ /** Seven days, from the shared `cache.stale_ttl_seconds` rule. */
5
+ export declare const DEFAULT_WORKSPACE_STALE_ON_ERROR_MS: number;
6
+ /** Keyv-store-compatible persistence (for example `keyv-file`'s `KeyvFile`). `ttl` is milliseconds. */
7
+ export interface WorkspaceCacheStore {
8
+ get(key: string): Promise<unknown>;
9
+ set(key: string, value: unknown, ttl?: number): Promise<unknown>;
10
+ delete(key: string): Promise<boolean>;
11
+ clear(): Promise<unknown>;
12
+ }
13
+ /**
14
+ * Cache key for one workspace, contract version, and principal. `shared` is false when no
15
+ * principal identity is available; such entries stay in the cache instance's session memory.
16
+ */
17
+ export interface WorkspaceCacheKey {
18
+ readonly id: string;
19
+ readonly shared: boolean;
20
+ }
21
+ export interface WorkspaceCacheKeyInput {
22
+ /** Workspace identity; absent when the source exposes no host, which keeps the key session-only. */
23
+ readonly workspace?: WorkspaceIdentity | undefined;
24
+ readonly contractVersion: string | number;
25
+ /** Non-secret principal identity, such as the SCIM `Me` id. Stored only as a SHA-256 hash. */
26
+ readonly principal?: string | undefined;
27
+ }
28
+ export interface WorkspaceCatalogCacheOptions {
29
+ /** Shared store for keys with a principal. Defaults to process-wide memory. */
30
+ store?: WorkspaceCacheStore;
31
+ /** Age after which a hit is returned while one background refresh runs. Defaults to 5 minutes. */
32
+ refreshAfterMs?: number;
33
+ /** Maximum age of an entry served while refreshing or after a refresh error. Defaults to 7 days. */
34
+ staleOnErrorMs?: number;
35
+ now?: () => number;
36
+ }
37
+ /** `fresh`: within the refresh interval; `refreshing`: served while a refresh runs; `stale`: the last refresh failed. */
38
+ export type WorkspaceCacheStatus = "fresh" | "refreshing" | "stale";
39
+ export interface WorkspaceCacheResult<T> {
40
+ readonly value: T;
41
+ readonly status: WorkspaceCacheStatus;
42
+ readonly writtenAt: number;
43
+ readonly ageMs: number;
44
+ readonly shared: boolean;
45
+ /** The most recent refresh error when `status` is `stale`. */
46
+ readonly error?: unknown;
47
+ }
48
+ export interface WorkspaceCatalogCache<T> {
49
+ /** Return a cached value, refreshing in the background after the refresh interval, or load it. */
50
+ get(key: WorkspaceCacheKey, load: () => Promise<T>): Promise<WorkspaceCacheResult<T>>;
51
+ /** Reload now, returning a bounded stale entry with its error if the load fails. */
52
+ refresh(key: WorkspaceCacheKey, load: () => Promise<T>): Promise<WorkspaceCacheResult<T>>;
53
+ /** Remove only the matching workspace and principal entry. */
54
+ evict(key: WorkspaceCacheKey): Promise<boolean>;
55
+ /** Remove every entry in the shared store and this instance's session memory. */
56
+ clear(): Promise<void>;
57
+ /** Wait for background refreshes started by this instance. */
58
+ settle(): Promise<void>;
59
+ }
60
+ /**
61
+ * Build a key from workspace identity, contract version, and SHA-256 of the principal identity.
62
+ * The key is shared only when both the workspace and the principal are known.
63
+ */
64
+ export declare function workspaceCacheKey(input: WorkspaceCacheKeyInput): Promise<WorkspaceCacheKey>;
65
+ /** In-memory store with millisecond TTLs. */
66
+ export declare function createMemoryWorkspaceCacheStore(now?: () => number): WorkspaceCacheStore;
67
+ /** Workspace-scoped cache with refresh-after-write, in-flight coalescing, and bounded stale-on-error. */
68
+ export declare function createWorkspaceCatalogCache<T>(options?: WorkspaceCatalogCacheOptions): WorkspaceCatalogCache<T>;
@@ -0,0 +1,49 @@
1
+ import { type BrowserModelServingClientOption, type ModelServingConnector, type ModelServingConnectorOptions } from "./workspace-connection.js";
2
+ /** Request accepted by the Databricks SDK `ApiClient.request` for a raw-JSON GET. */
3
+ export interface WorkspaceClientRequest {
4
+ path: string;
5
+ method: "GET";
6
+ headers: Headers;
7
+ raw: false;
8
+ query?: Record<string, string>;
9
+ }
10
+ /**
11
+ * The `@databricks/sdk-experimental` `WorkspaceClient` surface the catalog uses. The SDK client
12
+ * stays the only authentication owner; the catalog never constructs one or resolves profiles.
13
+ */
14
+ export interface WorkspaceClientLike {
15
+ readonly config: {
16
+ getHost(): Promise<URL>;
17
+ authenticate(headers: Headers): Promise<void>;
18
+ };
19
+ readonly apiClient: {
20
+ request(options: WorkspaceClientRequest): Promise<unknown>;
21
+ };
22
+ }
23
+ /**
24
+ * The `@databricks/sdk-modelserving/v1` `ModelServingClient` surface the catalog uses. Its host,
25
+ * configuration, and credentials are private and it has no current-user lookup, so overlays from
26
+ * it stay in session memory.
27
+ */
28
+ export interface ModelServingSdkClientLike {
29
+ listInferenceEndpoints(request: {
30
+ readonly pageToken?: string;
31
+ }, options?: unknown): Promise<{
32
+ readonly endpoints?: readonly object[] | undefined;
33
+ readonly nextPageToken?: string | undefined;
34
+ }>;
35
+ }
36
+ /**
37
+ * The Node `modelServingClient` option: an existing `@databricks/sdk-experimental` `WorkspaceClient`
38
+ * or `@databricks/sdk-modelserving` `ModelServingClient` (reusing its authentication), a
39
+ * `{ host, headers }` connection, or a sync or async function returning one.
40
+ */
41
+ export type ModelServingClientOption = WorkspaceClientLike | ModelServingSdkClientLike | BrowserModelServingClientOption;
42
+ /**
43
+ * Normalize a Node `modelServingClient` option once. A `WorkspaceClient` lends its host,
44
+ * authentication, and transport (including SCIM `Me`); a modular `ModelServingClient` lists
45
+ * through `listInferenceEndpoints` and, exposing no host or principal, stays session-only.
46
+ */
47
+ export declare function connectModelServing(source: ModelServingClientOption, options?: ModelServingConnectorOptions): ModelServingConnector;
48
+ /** Deep-convert SDK output to wire JSON: camelCase keys to snake_case, `bigint` to number, `undefined` members dropped. */
49
+ export declare function toServingEndpointsWire(value: unknown): unknown;
@@ -0,0 +1,67 @@
1
+ import { type WorkspaceHeaders, type WorkspaceIdentity } from "./workspace-identity.js";
2
+ export declare const SERVING_ENDPOINTS_PATH: string;
3
+ export declare const CURRENT_USER_PATH: string;
4
+ /** Workspace host (bare host or workspace URL) and the headers sent on its API requests. */
5
+ export interface ModelServingConnection {
6
+ readonly host: string;
7
+ readonly headers?: WorkspaceHeaders;
8
+ }
9
+ /** Called before every refresh so refreshed credentials or targets take effect. */
10
+ export type ModelServingConnectionGenerator = () => ModelServingConnection | Promise<ModelServingConnection>;
11
+ /** `modelServingClient` forms the browser-safe entry point accepts: a connection value or a connection generator. */
12
+ export type BrowserModelServingClientOption = ModelServingConnection | ModelServingConnectionGenerator;
13
+ /** Raw, unvalidated snake_case `GET /api/2.0/serving-endpoints` listing with all pages concatenated. */
14
+ export interface RawServingEndpointsListing {
15
+ readonly endpoints: unknown[];
16
+ }
17
+ /**
18
+ * One refresh attempt, resolved once (a generator is called once): the workspace identity plus the
19
+ * Serving Endpoints and principal lookups bound to that host and those credentials.
20
+ */
21
+ export interface ModelServingSnapshot {
22
+ /** Workspace cache identity; absent when the source exposes no host. */
23
+ readonly workspace?: WorkspaceIdentity;
24
+ /** Every Serving Endpoints page in the snake_case wire shape. */
25
+ listServingEndpoints(): Promise<RawServingEndpointsListing>;
26
+ /** Non-secret principal identity (SCIM `Me` id, else userName); `undefined` when unavailable. */
27
+ principal(): Promise<string | undefined>;
28
+ }
29
+ /** Which `modelServingClient` form a connector was normalized from. */
30
+ export type ModelServingConnectorKind = "workspace_client" | "model_serving_client" | "connection" | "generator";
31
+ /**
32
+ * Internal normalization of one `modelServingClient` option. Not exported from the entry points:
33
+ * catalog clients build it once and take one snapshot per refresh attempt.
34
+ */
35
+ export interface ModelServingConnector {
36
+ readonly kind: ModelServingConnectorKind;
37
+ /** Resolve the workspace and transport for one refresh attempt. */
38
+ snapshot(): Promise<ModelServingSnapshot>;
39
+ }
40
+ export interface ModelServingConnectorOptions {
41
+ /** Transport for connection and generator requests. Defaults to `globalThis.fetch`. */
42
+ fetch?: typeof globalThis.fetch | undefined;
43
+ }
44
+ /** Raised when a workspace request returns a non-success status. */
45
+ export declare class WorkspaceRequestError extends Error {
46
+ readonly path: string;
47
+ readonly status: number;
48
+ readonly name = "WorkspaceRequestError";
49
+ constructor(path: string, status: number);
50
+ }
51
+ /** Raw-JSON GET for a workspace REST path. */
52
+ export type WorkspaceGet = (path: string, query?: Readonly<Record<string, string>>) => Promise<unknown>;
53
+ /** Supported forms the browser-safe entry point names in its unsupported-value error. */
54
+ export declare const BROWSER_MODEL_SERVING_FORMS = "a { host, headers } connection or a function returning one";
55
+ /**
56
+ * Normalize a browser-safe `modelServingClient`: a static connection (a missing or invalid host
57
+ * fails here, before any request) or a generator (a returned value without a host fails that
58
+ * refresh). Anything else fails with an error naming `supportedForms`.
59
+ */
60
+ export declare function connectBrowserModelServing(source: BrowserModelServingClientOption, options?: ModelServingConnectorOptions, supportedForms?: string): ModelServingConnector;
61
+ /** Snapshot over a raw-JSON GET transport: paged Serving Endpoints and SCIM `Me`. */
62
+ export declare function requesterSnapshot(workspace: WorkspaceIdentity | undefined, get: WorkspaceGet): ModelServingSnapshot;
63
+ /** Concatenate every page, following a non-empty page token until it is absent or repeats. */
64
+ export declare function collectPages(page: (pageToken: string | undefined) => Promise<{
65
+ endpoints: readonly unknown[];
66
+ next: unknown;
67
+ }>): Promise<RawServingEndpointsListing>;
@@ -0,0 +1,11 @@
1
+ import { type WorkspaceCacheStore, type WorkspaceCatalogCache, type WorkspaceCatalogCacheOptions } from "./workspace-cache.js";
2
+ export interface FileWorkspaceCacheStoreOptions {
3
+ /** Cache file. Defaults to `workspace-catalog.json` in the user cache directory for this package. */
4
+ filename?: string;
5
+ }
6
+ /** Default persistent cache file under the platform user cache directory. */
7
+ export declare function defaultWorkspaceCacheFile(): string;
8
+ /** Process-shared `keyv-file` store, one per file, so all caches on a file coalesce together. */
9
+ export declare function createFileWorkspaceCacheStore(options?: FileWorkspaceCacheStoreOptions): WorkspaceCacheStore;
10
+ /** Workspace cache persisted to a file for principal-scoped keys; session-only keys stay in memory. */
11
+ export declare function createPersistentWorkspaceCatalogCache<T>(options?: Omit<WorkspaceCatalogCacheOptions, "store"> & FileWorkspaceCacheStoreOptions): WorkspaceCatalogCache<T>;
@@ -0,0 +1,27 @@
1
+ /** Headers accepted by a model serving connection: a `Headers`, a record, or name/value pairs. */
2
+ export type WorkspaceHeaders = ConstructorParameters<typeof Headers>[0];
3
+ /** Raised for invalid or ambiguous workspace connection input. */
4
+ export declare class WorkspaceConnectionError extends TypeError {
5
+ readonly name = "WorkspaceConnectionError";
6
+ }
7
+ /**
8
+ * Non-secret workspace cache identity: a workspace ID from headers, host, or URL query, or
9
+ * otherwise the normalized host plus any non-root path.
10
+ */
11
+ export interface WorkspaceIdentity {
12
+ readonly kind: "workspace_id" | "host";
13
+ readonly value: string;
14
+ }
15
+ /** Parse a bare host (`adb-1.2.azuredatabricks.net`) or a full workspace URL. */
16
+ export declare function parseWorkspaceUrl(host: string): URL;
17
+ /** Lowercase hostname, any explicit port, and any non-root path, without scheme, query, or trailing slash. */
18
+ export declare function normalizeWorkspaceHost(host: string): string;
19
+ /** The shared string form used in `WorkspaceRefresh.workspace`: `id:<workspace id>` or `host:<host[/path]>`. */
20
+ export declare function formatWorkspaceIdentity(identity: WorkspaceIdentity): string;
21
+ /**
22
+ * Resolve the workspace cache identity using the shared `workspace_identity` rules:
23
+ * a matching header, then a host pattern or query parameter, then the normalized host.
24
+ */
25
+ export declare function resolveWorkspaceIdentity(host: string, headers?: WorkspaceHeaders): WorkspaceIdentity;
26
+ /** Non-secret principal identity (`id`, else `userName`) from a SCIM `Me` response. */
27
+ export declare function principalIdentity(user: unknown): string | undefined;
@@ -0,0 +1,71 @@
1
+ import type { WorkspaceRefresh } from "./_generated/schemas.js";
2
+ import { type WorkspaceEndpoint } from "./serving-endpoints.js";
3
+ import { type WorkspaceCacheStore, type WorkspaceCatalogCache } from "./workspace-cache.js";
4
+ import type { ModelServingConnector } from "./workspace-connection.js";
5
+ /** Cached overlay payload: the normalized endpoint inventory only, never headers or principals. */
6
+ export interface CachedWorkspaceOverlay {
7
+ readonly endpoints: WorkspaceEndpoint[];
8
+ }
9
+ /** Workspace overlay refresh and persistence settings. */
10
+ export interface WorkspaceCacheOptions {
11
+ /** Minimum time between refresh attempts. Defaults to five minutes. */
12
+ refreshAfterMs?: number;
13
+ /** Maximum age of an overlay served after a failed refresh. Defaults to seven days. */
14
+ staleOnErrorMs?: number;
15
+ /** Keyv-compatible store for principal-scoped overlays. Defaults to process memory. */
16
+ store?: WorkspaceCacheStore;
17
+ /** Whether `store` keeps entries across processes; reported as `WorkspaceRefresh.persistent`. */
18
+ persistent?: boolean;
19
+ /**
20
+ * A prepared overlay cache, such as `createPersistentWorkspaceCatalogCache()`; replaces the cache
21
+ * built from `store`, `refreshAfterMs`, and `staleOnErrorMs`.
22
+ */
23
+ cache?: WorkspaceCatalogCache<CachedWorkspaceOverlay>;
24
+ now?: () => number;
25
+ }
26
+ /** The served endpoints (absent when enrichment is unavailable) and their refresh state. */
27
+ export interface WorkspaceOverlayState {
28
+ readonly endpoints?: readonly WorkspaceEndpoint[];
29
+ readonly refresh: WorkspaceRefresh;
30
+ }
31
+ /**
32
+ * One client's workspace overlay: refresh schedule, cache use, and failure state.
33
+ *
34
+ * A refresh is attempted when none was attempted within the refresh interval, or on
35
+ * `load({ force: true })`. Each attempt takes one connector snapshot (a generator is called once) and
36
+ * uses it for both the principal and Serving Endpoints requests. When the connection exposes no
37
+ * workspace host or principal the overlay stays in session memory. A fresh cache entry
38
+ * written by another client is reused; otherwise the inventory is fetched, coalesced per cache key.
39
+ * A failed refresh serves the newest entry at most `staleOnErrorMs` old as `stale`, or reports the
40
+ * workspace `unavailable` with no endpoints. Failures are reported in the state, never thrown.
41
+ * Internal: catalog clients build it from their `modelServingClient` option.
42
+ */
43
+ export declare class WorkspaceOverlaySession {
44
+ private readonly modelServing;
45
+ private readonly cache;
46
+ private readonly now;
47
+ private readonly persistent;
48
+ private readonly refreshAfterMs;
49
+ private readonly staleOnErrorMs;
50
+ private attemptedAt;
51
+ private entry;
52
+ private inflight;
53
+ private key;
54
+ private state;
55
+ private workspace;
56
+ constructor(modelServing: ModelServingConnector, options?: WorkspaceCacheOptions);
57
+ /** Return the current overlay, refreshing it when due (or when `force` is set). */
58
+ load(options?: {
59
+ force?: boolean;
60
+ }): Promise<WorkspaceOverlayState>;
61
+ /** Forget this session's overlay and delete its cache entry, or every entry when `all`. */
62
+ evict(options?: {
63
+ all?: boolean;
64
+ }): Promise<void>;
65
+ /** Wait for the in-flight attempt and any background cache refreshes. */
66
+ settle(): Promise<void>;
67
+ private attempt;
68
+ private succeeded;
69
+ private failed;
70
+ private serve;
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbx-tools/dbx-model-catalog",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Node and browser client for the published Databricks model catalog",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.4.4",
@@ -33,11 +33,6 @@
33
33
  "import": "./dist/browser.js",
34
34
  "default": "./dist/browser.js"
35
35
  },
36
- "./pynect": {
37
- "types": "./dist/pynect.d.ts",
38
- "import": "./dist/pynect.js",
39
- "default": "./dist/pynect.js"
40
- },
41
36
  "./package.json": "./package.json"
42
37
  },
43
38
  "files": [
@@ -52,12 +47,16 @@
52
47
  },
53
48
  "devDependencies": {
54
49
  "@chanx-js/client": "2.3.2",
50
+ "@databricks/sdk-experimental": "0.18.1",
51
+ "@databricks/sdk-modelserving": "0.55.0",
55
52
  "@types/bun": "^1.4.4",
56
53
  "@types/node": "^24.10.0",
57
54
  "pynect": "^1.0.0",
58
55
  "typescript": "^5.9.3"
59
56
  },
60
57
  "dependencies": {
58
+ "env-paths": "^4.0.0",
59
+ "keyv-file": "5.3.5",
61
60
  "zod": "^4.6.7"
62
61
  },
63
62
  "peerDependencies": {
@@ -10,16 +10,19 @@ import type {
10
10
  GetSearchIndexResponse,
11
11
  ListModelsRequest,
12
12
  ListModelsResponse,
13
+ OverlayServingEndpointsRequest,
14
+ OverlayServingEndpointsResponse,
13
15
  StreamModelsRequest,
14
16
  StreamModelsResponse,
15
17
  } from './schemas.js';
16
18
 
17
- export type ModelsToServer = GetCatalogRequest | GetSearchIndexRequest | ListModelsRequest | StreamModelsRequest;
18
- export type ModelsToClient = GetCatalogResponse | GetSearchIndexResponse | ListModelsResponse | StreamModelsResponse;
19
+ export type ModelsToServer = GetCatalogRequest | GetSearchIndexRequest | ListModelsRequest | OverlayServingEndpointsRequest | StreamModelsRequest;
20
+ export type ModelsToClient = GetCatalogResponse | GetSearchIndexResponse | ListModelsResponse | OverlayServingEndpointsResponse | StreamModelsResponse;
19
21
  export type ModelsReplies = {
20
22
  get_catalog: GetCatalogResponse;
21
23
  get_search_index: GetSearchIndexResponse;
22
24
  list_models: ListModelsResponse;
25
+ overlay_serving_endpoints: OverlayServingEndpointsResponse;
23
26
  stream_models: StreamModelsResponse;
24
27
  };
25
28