@dbx-tools/dbx-model-catalog 0.1.9 → 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.
- package/README.md +296 -55
- package/dist/_generated/channels.d.ts +4 -3
- package/dist/_generated/json-schema.d.ts +6527 -175
- package/dist/_generated/schemas.d.ts +154 -0
- package/dist/_generated/workspace-rules.d.ts +133 -0
- package/dist/browser.d.ts +34 -15
- package/dist/browser.js +1152 -9042
- package/dist/catalog-index.d.ts +15 -2
- package/dist/chunk-engbh7tj.js +39 -0
- package/dist/chunk-gzjer0mc.js +1797 -0
- package/dist/chunk-pp7fw379.js +51 -0
- package/dist/chunk-pwssxaq0.js +39 -0
- package/dist/cli.js +41 -9619
- package/dist/effective.d.ts +31 -0
- package/dist/index.d.ts +33 -16
- package/dist/index.js +60 -9630
- package/dist/local-client.d.ts +16 -3
- package/dist/pynect.d.ts +6 -3
- package/dist/search.d.ts +7 -1
- package/dist/serving-endpoints.d.ts +15 -0
- package/dist/sources.d.ts +30 -0
- package/dist/types.d.ts +31 -3
- package/dist/validation.d.ts +15 -1
- package/dist/workspace-cache.d.ts +68 -0
- package/dist/workspace-client.d.ts +49 -0
- package/dist/workspace-connection.d.ts +67 -0
- package/dist/workspace-file-cache.d.ts +11 -0
- package/dist/workspace-identity.d.ts +27 -0
- package/dist/workspace-overlay.d.ts +71 -0
- package/package.json +8 -12
- package/src/_generated/channels.ts +41 -0
- package/src/_generated/index.ts +6 -0
- package/src/_generated/json-schema.ts +5 -0
- package/src/_generated/published.ts +7 -0
- package/src/_generated/schemas.ts +585 -0
- package/src/_generated/workspace-rules.ts +285 -0
- package/src/browser.ts +115 -0
- package/src/catalog-index.ts +121 -0
- package/src/cli.ts +99 -0
- package/src/effective.ts +200 -0
- package/src/filter.ts +47 -0
- package/src/identity.ts +56 -0
- package/src/index.ts +187 -0
- package/src/local-client.ts +127 -0
- package/src/pynect.ts +31 -0
- package/src/search.ts +582 -0
- package/src/serving-endpoints.ts +157 -0
- package/src/sources.ts +107 -0
- package/src/types.ts +49 -0
- package/src/validation.ts +127 -0
- package/src/workspace-cache.ts +234 -0
- package/src/workspace-client.ts +134 -0
- package/src/workspace-connection.ts +160 -0
- package/src/workspace-file-cache.ts +45 -0
- package/src/workspace-identity.ts +77 -0
- package/src/workspace-overlay.ts +200 -0
- package/dist/browser.js.map +0 -38
- package/dist/catalog.json +0 -1
- package/dist/cli.js.map +0 -40
- package/dist/index.js.map +0 -39
- package/dist/pynect.js +0 -553
- package/dist/pynect.js.map +0 -15
- package/dist/search-index.json +0 -1
- package/dist/snapshot.d.ts +0 -7
- package/dist/snapshot.js +0 -9515
- package/dist/snapshot.js.map +0 -36
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// Generated from the Python-owned workspace overlay rules. Do not edit.
|
|
2
|
+
export const WORKSPACE_OVERLAY_RULES = {
|
|
3
|
+
"contract_version": 1,
|
|
4
|
+
"serving_endpoints_path": "/api/2.0/serving-endpoints",
|
|
5
|
+
"principal": {
|
|
6
|
+
"path": "/api/2.0/preview/scim/v2/Me",
|
|
7
|
+
"fields": [
|
|
8
|
+
"id",
|
|
9
|
+
"userName"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"cache": {
|
|
13
|
+
"refresh_interval_seconds": 300,
|
|
14
|
+
"stale_ttl_seconds": 604800
|
|
15
|
+
},
|
|
16
|
+
"identity_fields": [
|
|
17
|
+
{
|
|
18
|
+
"kind": "endpoint_name",
|
|
19
|
+
"path": [
|
|
20
|
+
"name"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"kind": "served_entity",
|
|
25
|
+
"path": [
|
|
26
|
+
"config",
|
|
27
|
+
"served_entities",
|
|
28
|
+
"*",
|
|
29
|
+
"entity_name"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"kind": "served_entity",
|
|
34
|
+
"path": [
|
|
35
|
+
"config",
|
|
36
|
+
"served_models",
|
|
37
|
+
"*",
|
|
38
|
+
"model_name"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"kind": "foundation_model",
|
|
43
|
+
"path": [
|
|
44
|
+
"config",
|
|
45
|
+
"served_entities",
|
|
46
|
+
"*",
|
|
47
|
+
"foundation_model",
|
|
48
|
+
"name"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"kind": "external_model",
|
|
53
|
+
"path": [
|
|
54
|
+
"config",
|
|
55
|
+
"served_entities",
|
|
56
|
+
"*",
|
|
57
|
+
"external_model",
|
|
58
|
+
"name"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"kind": "external_model",
|
|
63
|
+
"path": [
|
|
64
|
+
"config",
|
|
65
|
+
"served_entities",
|
|
66
|
+
"*",
|
|
67
|
+
"external_model"
|
|
68
|
+
],
|
|
69
|
+
"join": [
|
|
70
|
+
"provider",
|
|
71
|
+
"name"
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"model_service_prefixes": [
|
|
76
|
+
"system.ai."
|
|
77
|
+
],
|
|
78
|
+
"display_name_fields": [
|
|
79
|
+
[
|
|
80
|
+
"config",
|
|
81
|
+
"served_entities",
|
|
82
|
+
"*",
|
|
83
|
+
"foundation_model",
|
|
84
|
+
"display_name"
|
|
85
|
+
]
|
|
86
|
+
],
|
|
87
|
+
"display_name_tag_keys": [
|
|
88
|
+
"display_name",
|
|
89
|
+
"displayName"
|
|
90
|
+
],
|
|
91
|
+
"description_fields": [
|
|
92
|
+
[
|
|
93
|
+
"description"
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
"config",
|
|
97
|
+
"served_entities",
|
|
98
|
+
"*",
|
|
99
|
+
"foundation_model",
|
|
100
|
+
"description"
|
|
101
|
+
]
|
|
102
|
+
],
|
|
103
|
+
"family_fields": [
|
|
104
|
+
[
|
|
105
|
+
"config",
|
|
106
|
+
"served_entities",
|
|
107
|
+
"*",
|
|
108
|
+
"foundation_model",
|
|
109
|
+
"model_class"
|
|
110
|
+
]
|
|
111
|
+
],
|
|
112
|
+
"profile_fields": [
|
|
113
|
+
[
|
|
114
|
+
"config",
|
|
115
|
+
"served_entities",
|
|
116
|
+
"*",
|
|
117
|
+
"foundation_model",
|
|
118
|
+
"ai_gateway_model_profile"
|
|
119
|
+
]
|
|
120
|
+
],
|
|
121
|
+
"profile_keys": [
|
|
122
|
+
"quality",
|
|
123
|
+
"speed",
|
|
124
|
+
"cost"
|
|
125
|
+
],
|
|
126
|
+
"capability_fields": {
|
|
127
|
+
"function_calling": [
|
|
128
|
+
"capabilities",
|
|
129
|
+
"function_calling"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"task_types": {
|
|
133
|
+
"llm/v1/chat": {
|
|
134
|
+
"type": "chat",
|
|
135
|
+
"modalities": {
|
|
136
|
+
"input": [
|
|
137
|
+
"text"
|
|
138
|
+
],
|
|
139
|
+
"output": [
|
|
140
|
+
"text"
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"llm/v1/completions": {
|
|
145
|
+
"type": "chat",
|
|
146
|
+
"modalities": {
|
|
147
|
+
"input": [
|
|
148
|
+
"text"
|
|
149
|
+
],
|
|
150
|
+
"output": [
|
|
151
|
+
"text"
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"llm/v1/embeddings": {
|
|
156
|
+
"type": "embedding",
|
|
157
|
+
"modalities": {
|
|
158
|
+
"input": [
|
|
159
|
+
"text"
|
|
160
|
+
],
|
|
161
|
+
"output": [
|
|
162
|
+
"embedding"
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"agent/v1/chat": {
|
|
167
|
+
"type": "chat",
|
|
168
|
+
"modalities": {
|
|
169
|
+
"input": [
|
|
170
|
+
"text"
|
|
171
|
+
],
|
|
172
|
+
"output": [
|
|
173
|
+
"text"
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"agent/v2/chat": {
|
|
178
|
+
"type": "chat",
|
|
179
|
+
"modalities": {
|
|
180
|
+
"input": [
|
|
181
|
+
"text"
|
|
182
|
+
],
|
|
183
|
+
"output": [
|
|
184
|
+
"text"
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"agent/v1/responses": {
|
|
189
|
+
"type": "chat",
|
|
190
|
+
"modalities": {
|
|
191
|
+
"input": [
|
|
192
|
+
"text"
|
|
193
|
+
],
|
|
194
|
+
"output": [
|
|
195
|
+
"text"
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
"overlay_fields": [
|
|
201
|
+
{
|
|
202
|
+
"target": "name",
|
|
203
|
+
"source": "display_name"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"target": "description",
|
|
207
|
+
"source": "description"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"target": "family",
|
|
211
|
+
"source": "family"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"target": "capabilities.tools",
|
|
215
|
+
"source": "capabilities.function_calling"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"target": "type",
|
|
219
|
+
"source": "type",
|
|
220
|
+
"unmatched_only": true
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"target": "modalities",
|
|
224
|
+
"source": "modalities",
|
|
225
|
+
"unmatched_only": true
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
"placeholders": {
|
|
229
|
+
"description": "",
|
|
230
|
+
"type": "chat",
|
|
231
|
+
"status": "active",
|
|
232
|
+
"modalities": {
|
|
233
|
+
"input": [],
|
|
234
|
+
"output": []
|
|
235
|
+
},
|
|
236
|
+
"capabilities.responses": false,
|
|
237
|
+
"capabilities.apply_patch": false,
|
|
238
|
+
"capabilities.web_search": false
|
|
239
|
+
},
|
|
240
|
+
"runtime_search_quality": {
|
|
241
|
+
"leaderboard": 50,
|
|
242
|
+
"benchmark": 50,
|
|
243
|
+
"version": 50,
|
|
244
|
+
"freshness": 50,
|
|
245
|
+
"lifecycle": 100
|
|
246
|
+
},
|
|
247
|
+
"provider_prefixes": [
|
|
248
|
+
"alibaba",
|
|
249
|
+
"anthropic",
|
|
250
|
+
"deepseek",
|
|
251
|
+
"google",
|
|
252
|
+
"meta",
|
|
253
|
+
"moonshot",
|
|
254
|
+
"openai",
|
|
255
|
+
"xai",
|
|
256
|
+
"zhipu"
|
|
257
|
+
],
|
|
258
|
+
"provider_families": [
|
|
259
|
+
"claude",
|
|
260
|
+
"deepseek",
|
|
261
|
+
"gemini",
|
|
262
|
+
"gemma",
|
|
263
|
+
"glm",
|
|
264
|
+
"gpt",
|
|
265
|
+
"grok",
|
|
266
|
+
"gte",
|
|
267
|
+
"bge",
|
|
268
|
+
"kimi",
|
|
269
|
+
"llama",
|
|
270
|
+
"qwen"
|
|
271
|
+
],
|
|
272
|
+
"workspace_identity": {
|
|
273
|
+
"header_names": [
|
|
274
|
+
"x-databricks-org-id",
|
|
275
|
+
"x-databricks-workspace-id"
|
|
276
|
+
],
|
|
277
|
+
"host_patterns": [
|
|
278
|
+
"^adb-(\\d+)\\.\\d+\\.azuredatabricks\\.net$",
|
|
279
|
+
"^(\\d+)\\.\\d+\\.gcp\\.databricks\\.com$"
|
|
280
|
+
],
|
|
281
|
+
"query_parameters": [
|
|
282
|
+
"o"
|
|
283
|
+
]
|
|
284
|
+
}
|
|
285
|
+
} as const;
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createCatalogClient, workspaceOverlay } from "./local-client.js";
|
|
2
|
+
import { type CatalogSourceOptions, type ModelCatalogSourceInput, loadBrowserSource } from "./sources.js";
|
|
3
|
+
import type { ModelCatalogClient } from "./types.js";
|
|
4
|
+
import { type BrowserModelServingClientOption, connectBrowserModelServing } from "./workspace-connection.js";
|
|
5
|
+
import type { WorkspaceCacheOptions } from "./workspace-overlay.js";
|
|
6
|
+
|
|
7
|
+
/** Options for the browser `createModelCatalogClient`. */
|
|
8
|
+
interface BrowserModelCatalogClientOptions extends CatalogSourceOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Workspace connection: a `{ host, headers }` connection or a sync or async function returning
|
|
11
|
+
* one. SDK clients need the Node entry point.
|
|
12
|
+
*/
|
|
13
|
+
modelServingClient?: BrowserModelServingClientOption;
|
|
14
|
+
/** Workspace overlay refresh and cache settings. Defaults to process memory. */
|
|
15
|
+
workspaceCache?: WorkspaceCacheOptions;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a catalog client from any source: the published catalog by default, an `http(s)` catalog
|
|
20
|
+
* URL (its `search-index.json` is read from the same directory), a `ws(s)` URL of the Python
|
|
21
|
+
* catalog server (needs the optional `pynect` and `@chanx-js/client` peers), or an in-memory
|
|
22
|
+
* catalog with `options.searchIndex`. With `modelServingClient` every read serves the
|
|
23
|
+
* workspace-effective catalog, whatever the source.
|
|
24
|
+
*/
|
|
25
|
+
export async function createModelCatalogClient(
|
|
26
|
+
source?: ModelCatalogSourceInput,
|
|
27
|
+
options: BrowserModelCatalogClientOptions = {},
|
|
28
|
+
): Promise<ModelCatalogClient> {
|
|
29
|
+
// Validate the optional workspace connection before any request.
|
|
30
|
+
const connector = options.modelServingClient === undefined
|
|
31
|
+
? undefined
|
|
32
|
+
: connectBrowserModelServing(options.modelServingClient, { fetch: options.fetch });
|
|
33
|
+
const loaded = await loadBrowserSource(source, options);
|
|
34
|
+
return createCatalogClient(loaded, workspaceOverlay(connector, options.workspaceCache));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type { BrowserModelCatalogClientOptions as ModelCatalogClientOptions };
|
|
38
|
+
export type { ModelCatalogSourceInput } from "./sources.js";
|
|
39
|
+
export type { ModelCatalogClient, ModelCatalogSource, ModelCatalogSourceKind } from "./types.js";
|
|
40
|
+
export type {
|
|
41
|
+
Availability,
|
|
42
|
+
AveragePrice,
|
|
43
|
+
Benchmark,
|
|
44
|
+
Capabilities,
|
|
45
|
+
CatalogFilters,
|
|
46
|
+
CatalogModel,
|
|
47
|
+
CatalogModelRecord,
|
|
48
|
+
CatalogSearchIndexDocument,
|
|
49
|
+
CatalogSearchIndexPayload,
|
|
50
|
+
CatalogSearchQualityScores,
|
|
51
|
+
EffectiveEndpoint,
|
|
52
|
+
EffectiveModelCatalog,
|
|
53
|
+
FieldOrigin,
|
|
54
|
+
IdentityCandidate,
|
|
55
|
+
Latency,
|
|
56
|
+
Limits,
|
|
57
|
+
MatchedPublicIdentity,
|
|
58
|
+
Modalities,
|
|
59
|
+
ModelCatalog,
|
|
60
|
+
Notice,
|
|
61
|
+
Price,
|
|
62
|
+
Rankings,
|
|
63
|
+
RateLimits,
|
|
64
|
+
Reasoning,
|
|
65
|
+
Retirement,
|
|
66
|
+
SourceLink,
|
|
67
|
+
Status,
|
|
68
|
+
Type,
|
|
69
|
+
WorkspaceEndpointCapabilities,
|
|
70
|
+
WorkspaceEndpointSource,
|
|
71
|
+
WorkspaceModelProfile,
|
|
72
|
+
WorkspaceRefresh,
|
|
73
|
+
WorkspaceRefreshStatus,
|
|
74
|
+
} from "./_generated/schemas.js";
|
|
75
|
+
export type { CatalogIdentityMatch } from "./catalog-index.js";
|
|
76
|
+
export type { ModelIdentity, ModelIdentityKind } from "./identity.js";
|
|
77
|
+
export type { CatalogSearchMatch } from "./search.js";
|
|
78
|
+
export type { CachedWorkspaceOverlay, WorkspaceCacheOptions } from "./workspace-overlay.js";
|
|
79
|
+
export type { WorkspaceCacheStore, WorkspaceCatalogCache } from "./workspace-cache.js";
|
|
80
|
+
export type {
|
|
81
|
+
BrowserModelServingClientOption,
|
|
82
|
+
ModelServingConnection,
|
|
83
|
+
ModelServingConnectionGenerator,
|
|
84
|
+
} from "./workspace-connection.js";
|
|
85
|
+
export { EFFECTIVE_CATALOG_CONTRACT_VERSION } from "./effective.js";
|
|
86
|
+
export {
|
|
87
|
+
PUBLISHED_CATALOG_DATABASE_URL,
|
|
88
|
+
PUBLISHED_CATALOG_INDEX_URL,
|
|
89
|
+
PUBLISHED_CATALOG_ROOT_URL,
|
|
90
|
+
PUBLISHED_CATALOG_SCHEMA_URL,
|
|
91
|
+
PUBLISHED_CATALOG_SCHEMA_VERSION,
|
|
92
|
+
PUBLISHED_CATALOG_SEARCH_INDEX_URL,
|
|
93
|
+
PUBLISHED_CATALOG_URL,
|
|
94
|
+
} from "./_generated/published.js";
|
|
95
|
+
export {
|
|
96
|
+
CatalogAveragePriceSchema,
|
|
97
|
+
CatalogCapabilitiesSchema,
|
|
98
|
+
CatalogLatencySchema,
|
|
99
|
+
CatalogModelRecordSchema,
|
|
100
|
+
CatalogModelSchema,
|
|
101
|
+
CatalogPreferenceRankingSchema,
|
|
102
|
+
CatalogPriceSchema,
|
|
103
|
+
CatalogRankingSchema,
|
|
104
|
+
CatalogRateLimitsSchema,
|
|
105
|
+
CatalogScoreRankingSchema,
|
|
106
|
+
CatalogSearchIndexSchema,
|
|
107
|
+
CatalogStatusSchema,
|
|
108
|
+
EffectiveModelCatalogSchema,
|
|
109
|
+
ModelCatalogSchema,
|
|
110
|
+
WorkspaceRefreshSchema,
|
|
111
|
+
parseCatalogModelRecord,
|
|
112
|
+
parseCatalogSearchIndex,
|
|
113
|
+
parseEffectiveModelCatalog,
|
|
114
|
+
parseModelCatalog,
|
|
115
|
+
} from "./validation.js";
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CatalogFilters,
|
|
3
|
+
CatalogModelRecord,
|
|
4
|
+
CatalogSearchIndexPayload,
|
|
5
|
+
ModelCatalog,
|
|
6
|
+
} from "./_generated/schemas.js";
|
|
7
|
+
import { modelIdentities, normalizeModelIdentity, type ModelIdentity } from "./identity.js";
|
|
8
|
+
import { filterCatalogRecords } from "./filter.js";
|
|
9
|
+
import { searchCatalogMatches, type CatalogSearchMatch } from "./search.js";
|
|
10
|
+
|
|
11
|
+
export interface CatalogIdentityMatch {
|
|
12
|
+
readonly identity: ModelIdentity;
|
|
13
|
+
readonly record: CatalogModelRecord;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface EnrichedLiveModel<T> {
|
|
17
|
+
readonly live: T;
|
|
18
|
+
readonly published?: CatalogIdentityMatch;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Exact (case-insensitive) then normalized identity lookup; never fuzzy. A normalized key is
|
|
23
|
+
* ambiguous, and resolves to nothing, only when identities of two different records normalize
|
|
24
|
+
* to it; identities of one record that normalize alike keep the first identity's match.
|
|
25
|
+
*/
|
|
26
|
+
export class CatalogIdentityIndex {
|
|
27
|
+
private readonly exact = new Map<string, CatalogIdentityMatch>();
|
|
28
|
+
private readonly normalized = new Map<string, CatalogIdentityMatch | null>();
|
|
29
|
+
|
|
30
|
+
constructor(records: Iterable<CatalogModelRecord>) {
|
|
31
|
+
for (const record of records) {
|
|
32
|
+
for (const identity of modelIdentities(record)) {
|
|
33
|
+
this.exact.set(identity.value.toLowerCase(), { identity, record });
|
|
34
|
+
const key = normalizeModelIdentity(identity.value);
|
|
35
|
+
const current = this.normalized.get(key);
|
|
36
|
+
if (current === undefined) this.normalized.set(key, { identity, record });
|
|
37
|
+
else if (current !== null && current.record.id !== record.id) this.normalized.set(key, null);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
resolve(value: string): CatalogIdentityMatch | undefined {
|
|
43
|
+
const exact = this.exact.get(value.trim().toLowerCase());
|
|
44
|
+
if (exact) return exact;
|
|
45
|
+
return this.normalized.get(normalizeModelIdentity(value)) ?? undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
matchAny(values: readonly string[]): CatalogIdentityMatch | undefined {
|
|
49
|
+
for (const value of values) {
|
|
50
|
+
const match = this.resolve(value);
|
|
51
|
+
if (match) return match;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Immutable identity and search index over one catalog snapshot. */
|
|
58
|
+
export class ModelCatalogIndex {
|
|
59
|
+
readonly records: readonly CatalogModelRecord[];
|
|
60
|
+
private readonly identities: CatalogIdentityIndex;
|
|
61
|
+
|
|
62
|
+
constructor(
|
|
63
|
+
readonly catalog: ModelCatalog,
|
|
64
|
+
readonly searchIndex: CatalogSearchIndexPayload,
|
|
65
|
+
) {
|
|
66
|
+
if (catalog.schema_version !== searchIndex.catalog_schema_version) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Catalog schema v${catalog.schema_version} does not match search index schema v${searchIndex.catalog_schema_version}`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (catalog.updated_at !== searchIndex.updated_at) {
|
|
72
|
+
throw new Error("Catalog and search index timestamps do not match");
|
|
73
|
+
}
|
|
74
|
+
this.records = catalogRecords(catalog);
|
|
75
|
+
this.identities = new CatalogIdentityIndex(this.records);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get(id: string): CatalogModelRecord | undefined {
|
|
79
|
+
return this.catalog.models[id] ? { ...this.catalog.models[id]!, id } : undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
resolve(value: string): CatalogIdentityMatch | undefined {
|
|
83
|
+
return this.identities.resolve(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
matchAny(values: readonly string[]): CatalogIdentityMatch | undefined {
|
|
87
|
+
return this.identities.matchAny(values);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
list(filters: CatalogFilters = {}): CatalogModelRecord[] {
|
|
91
|
+
return filterCatalogRecords(this.records, this.searchIndex, filters);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
search(query: string, limit: number | null = 50): CatalogSearchMatch[] {
|
|
95
|
+
return searchCatalogMatches(this.searchIndex, this.records, query, limit);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Catalog records with their map keys as ids, in catalog order. */
|
|
100
|
+
export function catalogRecords(catalog: ModelCatalog): CatalogModelRecord[] {
|
|
101
|
+
return Object.entries(catalog.models).map(([id, model]) => ({ ...model, id }));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function createModelCatalogIndex(
|
|
105
|
+
catalog: ModelCatalog,
|
|
106
|
+
searchIndex: CatalogSearchIndexPayload,
|
|
107
|
+
): ModelCatalogIndex {
|
|
108
|
+
return new ModelCatalogIndex(catalog, searchIndex);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Join live models to published facts without dropping undocumented live entries. */
|
|
112
|
+
export function enrichLiveModels<T>(
|
|
113
|
+
index: ModelCatalogIndex,
|
|
114
|
+
models: readonly T[],
|
|
115
|
+
identities: (model: T) => readonly string[],
|
|
116
|
+
): EnrichedLiveModel<T>[] {
|
|
117
|
+
return models.map(live => {
|
|
118
|
+
const published = index.matchAny(identities(live));
|
|
119
|
+
return published ? { live, published } : { live };
|
|
120
|
+
});
|
|
121
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { type CatalogFilters, createModelCatalogClient } from './index.js';
|
|
4
|
+
|
|
5
|
+
type Command = 'catalog' | 'models' | 'model-feed';
|
|
6
|
+
|
|
7
|
+
interface CliOptions {
|
|
8
|
+
readonly command: Command;
|
|
9
|
+
readonly filters: CatalogFilters;
|
|
10
|
+
readonly url?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const listOptions = new Set([
|
|
14
|
+
'--status',
|
|
15
|
+
'--type',
|
|
16
|
+
'--publisher',
|
|
17
|
+
'--task',
|
|
18
|
+
'--capability',
|
|
19
|
+
]);
|
|
20
|
+
const scalarOptions = new Set(['--url', '--limit']);
|
|
21
|
+
|
|
22
|
+
function parseArgs(args: string[]): CliOptions {
|
|
23
|
+
const command = args.shift();
|
|
24
|
+
if (command === undefined || command === '--help' || command === '-h') {
|
|
25
|
+
throw new Error(
|
|
26
|
+
'Usage: bun run dbx-model-catalog <catalog|models|model-feed> [query] '
|
|
27
|
+
+ '[--status VALUE] [--type VALUE] [--publisher VALUE] [--task VALUE] '
|
|
28
|
+
+ '[--capability VALUE] [--limit NUMBER] '
|
|
29
|
+
+ '[--url https://HOST/catalog.json | ws://HOST:PORT | PATH/catalog.json]',
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (!['catalog', 'models', 'model-feed'].includes(command)) {
|
|
33
|
+
throw new Error(`Unknown command: ${command}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const positional: string[] = [];
|
|
37
|
+
const values = new Map<string, string[]>();
|
|
38
|
+
while (args.length > 0) {
|
|
39
|
+
const option = args.shift()!;
|
|
40
|
+
if (!option.startsWith('--')) {
|
|
41
|
+
positional.push(option);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!listOptions.has(option) && !scalarOptions.has(option)) {
|
|
45
|
+
throw new Error(`Unknown option: ${option}`);
|
|
46
|
+
}
|
|
47
|
+
const value = args.shift();
|
|
48
|
+
if (!value || value.startsWith('--')) throw new Error(`Missing value for ${option}`);
|
|
49
|
+
values.set(option, [...(values.get(option) ?? []), value]);
|
|
50
|
+
}
|
|
51
|
+
if (positional.length > 1) throw new Error('Only one query may be provided.');
|
|
52
|
+
|
|
53
|
+
const limit = numberOption(values, '--limit');
|
|
54
|
+
const filters = {
|
|
55
|
+
...(positional[0] ? { query: positional[0] } : {}),
|
|
56
|
+
...(values.get('--status') ? { status: values.get('--status')! } : {}),
|
|
57
|
+
...(values.get('--type') ? { type: values.get('--type')! } : {}),
|
|
58
|
+
...(values.get('--publisher') ? { publisher: values.get('--publisher')! } : {}),
|
|
59
|
+
...(values.get('--task') ? { task: values.get('--task')! } : {}),
|
|
60
|
+
...(values.get('--capability') ? { capability: values.get('--capability')! } : {}),
|
|
61
|
+
...(limit === undefined ? {} : { limit }),
|
|
62
|
+
} as CatalogFilters;
|
|
63
|
+
return {
|
|
64
|
+
command: command as Command,
|
|
65
|
+
filters,
|
|
66
|
+
...(values.get('--url')?.[0] ? { url: values.get('--url')![0] } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function numberOption(values: Map<string, string[]>, name: string): number | undefined {
|
|
71
|
+
const value = values.get(name)?.[0];
|
|
72
|
+
if (value === undefined) return undefined;
|
|
73
|
+
const parsed = Number(value);
|
|
74
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
75
|
+
throw new Error(`${name} must be a non-negative integer.`);
|
|
76
|
+
}
|
|
77
|
+
return parsed;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function main(): Promise<void> {
|
|
81
|
+
const options = parseArgs(process.argv.slice(2));
|
|
82
|
+
await using client = await createModelCatalogClient(options.url);
|
|
83
|
+
process.stderr.write(`Using ${client.source.kind} catalog ${client.source.location ?? ''}\n`);
|
|
84
|
+
|
|
85
|
+
if (options.command === 'catalog') {
|
|
86
|
+
process.stdout.write(`${JSON.stringify(await client.catalog())}\n`);
|
|
87
|
+
} else if (options.command === 'models') {
|
|
88
|
+
process.stdout.write(`${JSON.stringify(await client.list(options.filters), null, 2)}\n`);
|
|
89
|
+
} else {
|
|
90
|
+
for await (const model of client.stream(options.filters)) {
|
|
91
|
+
process.stdout.write(`${JSON.stringify(model)}\n`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void main().catch(error => {
|
|
97
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
});
|