@dbx-tools/dbx-model-catalog 0.1.8 → 0.2.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 +25 -6
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +95 -8991
- package/dist/cli.js +181 -9094
- package/dist/index.d.ts +1 -1
- package/dist/index.js +77 -9027
- package/dist/pynect.js +6 -2
- package/dist/validation.d.ts +30 -1
- package/package.json +4 -7
- package/src/_generated/channels.ts +38 -0
- package/src/_generated/index.ts +6 -0
- package/src/_generated/json-schema.ts +3 -0
- package/src/_generated/published.ts +7 -0
- package/src/_generated/schemas.ts +408 -0
- package/src/browser.ts +64 -0
- package/src/catalog-index.ts +94 -0
- package/src/cli.ts +102 -0
- package/src/filter.ts +47 -0
- package/src/identity.ts +79 -0
- package/src/index.ts +114 -0
- package/src/local-client.ts +51 -0
- package/src/pynect.ts +68 -0
- package/src/search.ts +534 -0
- package/src/types.ts +19 -0
- package/src/validation.ts +94 -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.map +0 -15
- package/dist/search-index.json +0 -1
- package/dist/snapshot.d.ts +0 -7
- package/dist/snapshot.js +0 -9495
- package/dist/snapshot.js.map +0 -36
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
// Generated by @chanx-js/codegen. Do not edit.
|
|
2
|
+
// Regenerate with: npx @chanx-js/codegen
|
|
3
|
+
|
|
4
|
+
/** Model availability on one Databricks cloud provider. */
|
|
5
|
+
export interface Availability {
|
|
6
|
+
status: Status1;
|
|
7
|
+
serving_modes: Array<ServingMode>;
|
|
8
|
+
details?: string | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Normalized Databricks price in one currency. */
|
|
12
|
+
export interface AveragePrice {
|
|
13
|
+
unit: Unit;
|
|
14
|
+
rates: Record<string, number>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Task-suite benchmark result. */
|
|
18
|
+
export interface Benchmark {
|
|
19
|
+
name: string;
|
|
20
|
+
rank: number;
|
|
21
|
+
score: number;
|
|
22
|
+
task_count: number;
|
|
23
|
+
published_at?: string | null;
|
|
24
|
+
variant?: Variant2 | null;
|
|
25
|
+
sources: Array<SourceLink>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Supported reasoning-token budget range. */
|
|
29
|
+
export interface Budget {
|
|
30
|
+
min?: number | null;
|
|
31
|
+
max?: number | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Capabilities used to select the model for a workload. */
|
|
35
|
+
export interface Capabilities {
|
|
36
|
+
attachments?: boolean | null;
|
|
37
|
+
tools?: boolean | null;
|
|
38
|
+
structured_output?: boolean | null;
|
|
39
|
+
temperature?: boolean | null;
|
|
40
|
+
interleaved_reasoning?: boolean | null;
|
|
41
|
+
responses: boolean;
|
|
42
|
+
apply_patch: boolean;
|
|
43
|
+
web_search: boolean;
|
|
44
|
+
reasoning?: Reasoning | Reasoning1 | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface CatalogFilters {
|
|
48
|
+
query?: string | null;
|
|
49
|
+
status?: Array<Status>;
|
|
50
|
+
type?: Array<Type>;
|
|
51
|
+
publisher?: Array<string>;
|
|
52
|
+
task?: Array<string>;
|
|
53
|
+
capability?: Array<"apply-patch" | "attachments" | "reasoning" | "responses" | "structured-output" | "tools" | "web-search">;
|
|
54
|
+
limit?: number | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Published statistics for one Databricks model. */
|
|
58
|
+
export interface CatalogModel {
|
|
59
|
+
name: string;
|
|
60
|
+
description: string;
|
|
61
|
+
aliases: Array<string>;
|
|
62
|
+
type: Type;
|
|
63
|
+
family?: string | null;
|
|
64
|
+
publisher?: string | null;
|
|
65
|
+
license?: string | null;
|
|
66
|
+
open_weights?: boolean | null;
|
|
67
|
+
status: Status;
|
|
68
|
+
release_date?: string | null;
|
|
69
|
+
last_updated?: string | null;
|
|
70
|
+
knowledge_cutoff?: string | null;
|
|
71
|
+
retirement?: Retirement | null;
|
|
72
|
+
modalities: Modalities;
|
|
73
|
+
capabilities: Capabilities;
|
|
74
|
+
limits?: Limits | null;
|
|
75
|
+
rate_limits?: RateLimits | null;
|
|
76
|
+
latency?: Latency | null;
|
|
77
|
+
tasks: Array<string>;
|
|
78
|
+
use_cases: Array<string>;
|
|
79
|
+
availability: Record<string, Availability>;
|
|
80
|
+
price: Record<string, Record<string, Price>>;
|
|
81
|
+
average_price: Record<string, AveragePrice>;
|
|
82
|
+
sources: Record<string, Array<SourceLink>>;
|
|
83
|
+
notices: Array<Notice>;
|
|
84
|
+
rankings: Array<Rankings | Rankings1>;
|
|
85
|
+
benchmarks: Array<Benchmark>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface CatalogModelRecord {
|
|
89
|
+
name: string;
|
|
90
|
+
description: string;
|
|
91
|
+
aliases: Array<string>;
|
|
92
|
+
type: Type;
|
|
93
|
+
family?: string | null;
|
|
94
|
+
publisher?: string | null;
|
|
95
|
+
license?: string | null;
|
|
96
|
+
open_weights?: boolean | null;
|
|
97
|
+
status: Status;
|
|
98
|
+
release_date?: string | null;
|
|
99
|
+
last_updated?: string | null;
|
|
100
|
+
knowledge_cutoff?: string | null;
|
|
101
|
+
retirement?: Retirement | null;
|
|
102
|
+
modalities: Modalities;
|
|
103
|
+
capabilities: Capabilities;
|
|
104
|
+
limits?: Limits | null;
|
|
105
|
+
rate_limits?: RateLimits | null;
|
|
106
|
+
latency?: Latency | null;
|
|
107
|
+
tasks: Array<string>;
|
|
108
|
+
use_cases: Array<string>;
|
|
109
|
+
availability: Record<string, Availability>;
|
|
110
|
+
price: Record<string, Record<string, Price>>;
|
|
111
|
+
average_price: Record<string, AveragePrice>;
|
|
112
|
+
sources: Record<string, Array<SourceLink>>;
|
|
113
|
+
notices: Array<Notice>;
|
|
114
|
+
rankings: Array<Rankings | Rankings1>;
|
|
115
|
+
benchmarks: Array<Benchmark>;
|
|
116
|
+
id: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface CatalogSearchIndexDocument {
|
|
120
|
+
id: string;
|
|
121
|
+
exact_identities: Array<string>;
|
|
122
|
+
identities: Array<string>;
|
|
123
|
+
keywords: string;
|
|
124
|
+
description: string;
|
|
125
|
+
tokens: Array<string>;
|
|
126
|
+
family?: string | null;
|
|
127
|
+
version: Array<number>;
|
|
128
|
+
quality_score: number;
|
|
129
|
+
scores: CatalogSearchQualityScores;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface CatalogSearchIndexPayload {
|
|
133
|
+
schema_version: number;
|
|
134
|
+
catalog_schema_version: number;
|
|
135
|
+
updated_at: string;
|
|
136
|
+
weights: CatalogSearchWeights;
|
|
137
|
+
documents: Array<CatalogSearchIndexDocument>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface CatalogSearchQualityScores {
|
|
141
|
+
leaderboard: number;
|
|
142
|
+
benchmark: number;
|
|
143
|
+
version: number;
|
|
144
|
+
freshness: number;
|
|
145
|
+
lifecycle: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface CatalogSearchWeights {
|
|
149
|
+
relevance: number;
|
|
150
|
+
leaderboard: number;
|
|
151
|
+
benchmark: number;
|
|
152
|
+
version: number;
|
|
153
|
+
freshness: number;
|
|
154
|
+
lifecycle: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Default reasoning effort when no level is specified. */
|
|
158
|
+
export type DefaultEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "default";
|
|
159
|
+
|
|
160
|
+
/** Normalized reasoning effort level. */
|
|
161
|
+
export type EffortEnum = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "default";
|
|
162
|
+
|
|
163
|
+
export interface GetCatalogRequest {
|
|
164
|
+
action: "get_catalog";
|
|
165
|
+
payload: CatalogFilters;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface GetCatalogResponse {
|
|
169
|
+
action: "catalog";
|
|
170
|
+
payload: ModelCatalog;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface GetSearchIndexRequest {
|
|
174
|
+
action: "get_search_index";
|
|
175
|
+
payload: CatalogFilters;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface GetSearchIndexResponse {
|
|
179
|
+
action: "search_index";
|
|
180
|
+
payload: CatalogSearchIndexPayload;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Known model input and output modalities. */
|
|
184
|
+
export type Input = "text" | "image" | "audio" | "video" | "application/pdf" | "embedding" | "reranking" | "decision";
|
|
185
|
+
|
|
186
|
+
/** Known Databricks documentation notice kinds. */
|
|
187
|
+
export type Kind = "note" | "important" | "warning" | "tip" | "caution" | "info";
|
|
188
|
+
|
|
189
|
+
/** Normalized response-time score and public benchmark measurements. */
|
|
190
|
+
export interface Latency {
|
|
191
|
+
score: number;
|
|
192
|
+
measurements: LatencyMeasurements;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Public benchmark measurements underlying one latency score. */
|
|
196
|
+
export interface LatencyMeasurements {
|
|
197
|
+
time_to_first_token_ms: number;
|
|
198
|
+
output_tokens_per_second: number;
|
|
199
|
+
successful_run_count: number;
|
|
200
|
+
completion_token_count: number;
|
|
201
|
+
measured_at: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Documented token limits. */
|
|
205
|
+
export interface Limits {
|
|
206
|
+
context?: number | null;
|
|
207
|
+
input?: number | null;
|
|
208
|
+
output?: number | null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface ListModelsRequest {
|
|
212
|
+
action: "list_models";
|
|
213
|
+
payload: CatalogFilters;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface ListModelsResponse {
|
|
217
|
+
action: "models";
|
|
218
|
+
payload: Array<CatalogModelRecord>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Model input and output modalities. */
|
|
222
|
+
export interface Modalities {
|
|
223
|
+
input: Array<Input | string>;
|
|
224
|
+
output: Array<Output | string>;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Published Databricks model catalog with identity, capabilities, availability, pricing, lifecycle, rankings, and benchmarks. */
|
|
228
|
+
export interface ModelCatalog {
|
|
229
|
+
schema_version: 16;
|
|
230
|
+
updated_at: string;
|
|
231
|
+
models: Record<string, CatalogModel>;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Important Databricks documentation notice. */
|
|
235
|
+
export interface Notice {
|
|
236
|
+
kind: Kind | string;
|
|
237
|
+
title?: string | null;
|
|
238
|
+
text: string;
|
|
239
|
+
sources: Array<SourceLink>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Known model input and output modalities. */
|
|
243
|
+
export type Output = "text" | "image" | "audio" | "video" | "application/pdf" | "embedding" | "reranking" | "decision";
|
|
244
|
+
|
|
245
|
+
/** Normalized Databricks price in one currency. */
|
|
246
|
+
export interface Price {
|
|
247
|
+
unit: Unit;
|
|
248
|
+
rates: Record<string, number>;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** An RFC 9457 problem details object, the payload of an error frame. See https://python.chanx.dev/en/latest/protocol.html#protocol-errors */
|
|
252
|
+
export interface ProblemDetails {
|
|
253
|
+
/** A URI reference that identifies the problem type. */
|
|
254
|
+
type: string;
|
|
255
|
+
/** A short, human-readable summary of the problem type. */
|
|
256
|
+
title: string;
|
|
257
|
+
/** The HTTP status code generated by the origin server for this occurrence of the problem. */
|
|
258
|
+
status?: number;
|
|
259
|
+
/** A human-readable explanation specific to this occurrence of the problem. */
|
|
260
|
+
detail: string;
|
|
261
|
+
/** A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. */
|
|
262
|
+
instance?: string;
|
|
263
|
+
/** The validation failures, when type is validation-failed. */
|
|
264
|
+
errors?: Array<ValidationFailure>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Competitive ranking based on human preference ratings. */
|
|
268
|
+
export interface Rankings {
|
|
269
|
+
domain: string;
|
|
270
|
+
category: string;
|
|
271
|
+
rank: number;
|
|
272
|
+
published_at?: string | null;
|
|
273
|
+
variant?: Variant | null;
|
|
274
|
+
sources: Array<SourceLink>;
|
|
275
|
+
metric: "rating";
|
|
276
|
+
rating: number;
|
|
277
|
+
lower: number;
|
|
278
|
+
upper: number;
|
|
279
|
+
variance: number;
|
|
280
|
+
votes: number;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Competitive ranking based on a scored evaluation. */
|
|
284
|
+
export interface Rankings1 {
|
|
285
|
+
domain: string;
|
|
286
|
+
category: string;
|
|
287
|
+
rank: number;
|
|
288
|
+
published_at?: string | null;
|
|
289
|
+
variant?: Variant1 | null;
|
|
290
|
+
sources: Array<SourceLink>;
|
|
291
|
+
metric: "score";
|
|
292
|
+
score: number;
|
|
293
|
+
lower: number;
|
|
294
|
+
upper: number;
|
|
295
|
+
observations: number;
|
|
296
|
+
sessions: number | null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Published pay-per-token limits for one model. */
|
|
300
|
+
export interface RateLimits {
|
|
301
|
+
input_tokens_per_minute: number | null;
|
|
302
|
+
output_tokens_per_minute: number | null;
|
|
303
|
+
queries_per_hour: number | null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Reasoning support and controls when known. */
|
|
307
|
+
export interface Reasoning {
|
|
308
|
+
supported: false;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Reasoning support and controls when known. */
|
|
312
|
+
export interface Reasoning1 {
|
|
313
|
+
supported: true;
|
|
314
|
+
effort?: Array<EffortEnum> | null;
|
|
315
|
+
default_effort?: DefaultEffort | null;
|
|
316
|
+
toggle?: boolean | null;
|
|
317
|
+
budget?: Budget | null;
|
|
318
|
+
description?: string | null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Reasoning effort used by the evaluated variant. */
|
|
322
|
+
export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "default";
|
|
323
|
+
|
|
324
|
+
/** Reasoning execution mode used by the evaluated variant. */
|
|
325
|
+
export type ReasoningMode = "auto" | "thinking";
|
|
326
|
+
|
|
327
|
+
/** Databricks retirement and replacement information. */
|
|
328
|
+
export interface Retirement {
|
|
329
|
+
schedules: Array<Schedule>;
|
|
330
|
+
replacement?: string | null;
|
|
331
|
+
replacement_name?: string | null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Retirement dates for one serving offering. */
|
|
335
|
+
export interface Schedule {
|
|
336
|
+
offering: string;
|
|
337
|
+
dates: Array<string>;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** Databricks serving mode available for the model. */
|
|
341
|
+
export type ServingMode = "pay_per_token" | "priority_pay_per_token" | "provisioned_throughput" | "batch";
|
|
342
|
+
|
|
343
|
+
/** Openable attribution for published catalog data. */
|
|
344
|
+
export interface SourceLink {
|
|
345
|
+
label: string;
|
|
346
|
+
url: string;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Current normalized lifecycle state. */
|
|
350
|
+
export type Status = "active" | "preview" | "alpha" | "beta" | "legacy" | "deprecated" | "retired";
|
|
351
|
+
|
|
352
|
+
/** Lifecycle state for this cloud-provider deployment. */
|
|
353
|
+
export type Status1 = "active" | "preview" | "alpha" | "beta" | "legacy" | "deprecated" | "retired";
|
|
354
|
+
|
|
355
|
+
export interface StreamModelsRequest {
|
|
356
|
+
action: "stream_models";
|
|
357
|
+
payload: CatalogFilters;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export interface StreamModelsResponse {
|
|
361
|
+
action: "model";
|
|
362
|
+
payload: CatalogModelRecord;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** Normalized model type. */
|
|
366
|
+
export type Type = "chat" | "image" | "video" | "embedding" | "reranking" | "decision" | "transcription" | "speech" | "realtime" | "extraction" | "audio";
|
|
367
|
+
|
|
368
|
+
/** Quantity to which the rates apply. */
|
|
369
|
+
export type Unit = "per_million_tokens" | "per_hour" | "per_hour_per_50_model_units";
|
|
370
|
+
|
|
371
|
+
/** One validation failure, shaped like RFC 9457's validation example. */
|
|
372
|
+
export interface ValidationFailure {
|
|
373
|
+
/** The JSON Schema keyword that failed, or custom. */
|
|
374
|
+
keyword: string;
|
|
375
|
+
/** A JSON Pointer to the failing value in the frame; for required, the object lacking the member. */
|
|
376
|
+
pointer: string;
|
|
377
|
+
/** A human-readable message. */
|
|
378
|
+
detail: string;
|
|
379
|
+
/** For required only: the missing member. */
|
|
380
|
+
property?: string | number;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** Evaluated model variant when it differs from the base model. */
|
|
384
|
+
export interface Variant {
|
|
385
|
+
reasoning?: boolean | null;
|
|
386
|
+
reasoning_effort?: ReasoningEffort | null;
|
|
387
|
+
reasoning_mode?: ReasoningMode | null;
|
|
388
|
+
harness?: string | null;
|
|
389
|
+
context?: number | null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Evaluated model variant when it differs from the base model. */
|
|
393
|
+
export interface Variant1 {
|
|
394
|
+
reasoning?: boolean | null;
|
|
395
|
+
reasoning_effort?: ReasoningEffort | null;
|
|
396
|
+
reasoning_mode?: ReasoningMode | null;
|
|
397
|
+
harness?: string | null;
|
|
398
|
+
context?: number | null;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Evaluated model variant when it differs from the base model. */
|
|
402
|
+
export interface Variant2 {
|
|
403
|
+
reasoning?: boolean | null;
|
|
404
|
+
reasoning_effort?: ReasoningEffort | null;
|
|
405
|
+
reasoning_mode?: ReasoningMode | null;
|
|
406
|
+
harness?: string | null;
|
|
407
|
+
context?: number | null;
|
|
408
|
+
}
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createModelCatalogClient } from "./local-client.js";
|
|
2
|
+
import type { CatalogClient } from "./types.js";
|
|
3
|
+
import { createModelCatalogIndex, type ModelCatalogIndex } from "./catalog-index.js";
|
|
4
|
+
import {
|
|
5
|
+
PUBLISHED_CATALOG_SEARCH_INDEX_URL,
|
|
6
|
+
PUBLISHED_CATALOG_URL,
|
|
7
|
+
} from "./_generated/published.js";
|
|
8
|
+
import { parseCatalogSearchIndex, parseModelCatalog } from "./validation.js";
|
|
9
|
+
|
|
10
|
+
export type * from "./_generated/schemas.js";
|
|
11
|
+
export type * from "./types.js";
|
|
12
|
+
export {
|
|
13
|
+
PUBLISHED_CATALOG_DATABASE_URL,
|
|
14
|
+
PUBLISHED_CATALOG_INDEX_URL,
|
|
15
|
+
PUBLISHED_CATALOG_ROOT_URL,
|
|
16
|
+
PUBLISHED_CATALOG_SCHEMA_URL,
|
|
17
|
+
PUBLISHED_CATALOG_SCHEMA_VERSION,
|
|
18
|
+
PUBLISHED_CATALOG_SEARCH_INDEX_URL,
|
|
19
|
+
PUBLISHED_CATALOG_URL,
|
|
20
|
+
} from "./_generated/published.js";
|
|
21
|
+
|
|
22
|
+
export interface LoadModelCatalogOptions {
|
|
23
|
+
catalogUrl?: string;
|
|
24
|
+
fetch?: typeof globalThis.fetch;
|
|
25
|
+
searchIndexUrl?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function loadModelCatalog(
|
|
29
|
+
options: LoadModelCatalogOptions = {},
|
|
30
|
+
): Promise<CatalogClient> {
|
|
31
|
+
const index = await loadModelCatalogIndex(options);
|
|
32
|
+
return createModelCatalogClient(index.catalog, index.searchIndex);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function loadModelCatalogIndex(
|
|
36
|
+
options: LoadModelCatalogOptions = {},
|
|
37
|
+
): Promise<ModelCatalogIndex> {
|
|
38
|
+
const loader = options.fetch ?? globalThis.fetch;
|
|
39
|
+
const catalogUrl = options.catalogUrl ?? PUBLISHED_CATALOG_URL;
|
|
40
|
+
const searchIndexUrl = options.searchIndexUrl ?? (
|
|
41
|
+
options.catalogUrl
|
|
42
|
+
? new URL("search-index.json", options.catalogUrl).toString()
|
|
43
|
+
: PUBLISHED_CATALOG_SEARCH_INDEX_URL
|
|
44
|
+
);
|
|
45
|
+
const [catalogResponse, searchIndexResponse] = await Promise.all([
|
|
46
|
+
loader(catalogUrl),
|
|
47
|
+
loader(searchIndexUrl),
|
|
48
|
+
]);
|
|
49
|
+
if (!catalogResponse.ok) throw new Error(`Catalog request failed with ${catalogResponse.status}`);
|
|
50
|
+
if (!searchIndexResponse.ok) {
|
|
51
|
+
throw new Error(`Search index request failed with ${searchIndexResponse.status}`);
|
|
52
|
+
}
|
|
53
|
+
return createModelCatalogIndex(
|
|
54
|
+
parseModelCatalog(await catalogResponse.json()),
|
|
55
|
+
parseCatalogSearchIndex(await searchIndexResponse.json()),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export * from "./catalog-index.js";
|
|
60
|
+
export * from "./identity.js";
|
|
61
|
+
export * from "./validation.js";
|
|
62
|
+
export { createModelCatalogClient } from "./local-client.js";
|
|
63
|
+
export { filterCatalogRecords } from "./local-client.js";
|
|
64
|
+
export { searchCatalogMatches, searchCatalogRecords } from "./search.js";
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
/** Immutable identity and search index over one catalog snapshot. */
|
|
22
|
+
export class ModelCatalogIndex {
|
|
23
|
+
readonly records: readonly CatalogModelRecord[];
|
|
24
|
+
private readonly exact = new Map<string, CatalogIdentityMatch>();
|
|
25
|
+
private readonly normalized = new Map<string, CatalogIdentityMatch | null>();
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
readonly catalog: ModelCatalog,
|
|
29
|
+
readonly searchIndex: CatalogSearchIndexPayload,
|
|
30
|
+
) {
|
|
31
|
+
if (catalog.schema_version !== searchIndex.catalog_schema_version) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Catalog schema v${catalog.schema_version} does not match search index schema v${searchIndex.catalog_schema_version}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (catalog.updated_at !== searchIndex.updated_at) {
|
|
37
|
+
throw new Error("Catalog and search index timestamps do not match");
|
|
38
|
+
}
|
|
39
|
+
this.records = Object.entries(catalog.models).map(([id, model]) => ({ ...model, id }));
|
|
40
|
+
for (const record of this.records) {
|
|
41
|
+
for (const identity of modelIdentities(record)) {
|
|
42
|
+
this.exact.set(identity.value.toLowerCase(), { identity, record });
|
|
43
|
+
const key = normalizeModelIdentity(identity.value);
|
|
44
|
+
const current = this.normalized.get(key);
|
|
45
|
+
this.normalized.set(key, current === undefined ? { identity, record } : null);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get(id: string): CatalogModelRecord | undefined {
|
|
51
|
+
return this.catalog.models[id] ? { ...this.catalog.models[id]!, id } : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
resolve(value: string): CatalogIdentityMatch | undefined {
|
|
55
|
+
const exact = this.exact.get(value.trim().toLowerCase());
|
|
56
|
+
if (exact) return exact;
|
|
57
|
+
return this.normalized.get(normalizeModelIdentity(value)) ?? undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
matchAny(values: readonly string[]): CatalogIdentityMatch | undefined {
|
|
61
|
+
for (const value of values) {
|
|
62
|
+
const match = this.resolve(value);
|
|
63
|
+
if (match) return match;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
list(filters: CatalogFilters = {}): CatalogModelRecord[] {
|
|
69
|
+
return filterCatalogRecords(this.records, this.searchIndex, filters);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
search(query: string, limit: number | null = 50): CatalogSearchMatch[] {
|
|
73
|
+
return searchCatalogMatches(this.searchIndex, this.records, query, limit);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function createModelCatalogIndex(
|
|
78
|
+
catalog: ModelCatalog,
|
|
79
|
+
searchIndex: CatalogSearchIndexPayload,
|
|
80
|
+
): ModelCatalogIndex {
|
|
81
|
+
return new ModelCatalogIndex(catalog, searchIndex);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Join live models to published facts without dropping undocumented live entries. */
|
|
85
|
+
export function enrichLiveModels<T>(
|
|
86
|
+
index: ModelCatalogIndex,
|
|
87
|
+
models: readonly T[],
|
|
88
|
+
identities: (model: T) => readonly string[],
|
|
89
|
+
): EnrichedLiveModel<T>[] {
|
|
90
|
+
return models.map(live => {
|
|
91
|
+
const published = index.matchAny(identities(live));
|
|
92
|
+
return published ? { live, published } : { live };
|
|
93
|
+
});
|
|
94
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
CatalogFilters,
|
|
5
|
+
} from './browser.js';
|
|
6
|
+
import { connectModelCatalog } from './index.js';
|
|
7
|
+
|
|
8
|
+
type Command = 'catalog' | 'models' | 'model-feed';
|
|
9
|
+
|
|
10
|
+
interface CliOptions {
|
|
11
|
+
readonly command: Command;
|
|
12
|
+
readonly filters: CatalogFilters;
|
|
13
|
+
readonly url?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const listOptions = new Set([
|
|
17
|
+
'--status',
|
|
18
|
+
'--type',
|
|
19
|
+
'--publisher',
|
|
20
|
+
'--task',
|
|
21
|
+
'--capability',
|
|
22
|
+
]);
|
|
23
|
+
const scalarOptions = new Set(['--url', '--limit']);
|
|
24
|
+
|
|
25
|
+
function parseArgs(args: string[]): CliOptions {
|
|
26
|
+
const command = args.shift();
|
|
27
|
+
if (command === undefined || command === '--help' || command === '-h') {
|
|
28
|
+
throw new Error(
|
|
29
|
+
'Usage: bun run chanx-model-catalog <catalog|models|model-feed> [query] '
|
|
30
|
+
+ '[--status VALUE] [--type VALUE] [--publisher VALUE] [--task VALUE] '
|
|
31
|
+
+ '[--capability VALUE] [--limit NUMBER] '
|
|
32
|
+
+ '[--url https://HOST/catalog.json]',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (!['catalog', 'models', 'model-feed'].includes(command)) {
|
|
36
|
+
throw new Error(`Unknown command: ${command}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const positional: string[] = [];
|
|
40
|
+
const values = new Map<string, string[]>();
|
|
41
|
+
while (args.length > 0) {
|
|
42
|
+
const option = args.shift()!;
|
|
43
|
+
if (!option.startsWith('--')) {
|
|
44
|
+
positional.push(option);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!listOptions.has(option) && !scalarOptions.has(option)) {
|
|
48
|
+
throw new Error(`Unknown option: ${option}`);
|
|
49
|
+
}
|
|
50
|
+
const value = args.shift();
|
|
51
|
+
if (!value || value.startsWith('--')) throw new Error(`Missing value for ${option}`);
|
|
52
|
+
values.set(option, [...(values.get(option) ?? []), value]);
|
|
53
|
+
}
|
|
54
|
+
if (positional.length > 1) throw new Error('Only one query may be provided.');
|
|
55
|
+
|
|
56
|
+
const limit = numberOption(values, '--limit');
|
|
57
|
+
const filters = {
|
|
58
|
+
...(positional[0] ? { query: positional[0] } : {}),
|
|
59
|
+
...(values.get('--status') ? { status: values.get('--status')! } : {}),
|
|
60
|
+
...(values.get('--type') ? { type: values.get('--type')! } : {}),
|
|
61
|
+
...(values.get('--publisher') ? { publisher: values.get('--publisher')! } : {}),
|
|
62
|
+
...(values.get('--task') ? { task: values.get('--task')! } : {}),
|
|
63
|
+
...(values.get('--capability') ? { capability: values.get('--capability')! } : {}),
|
|
64
|
+
...(limit === undefined ? {} : { limit }),
|
|
65
|
+
} as CatalogFilters;
|
|
66
|
+
return {
|
|
67
|
+
command: command as Command,
|
|
68
|
+
filters,
|
|
69
|
+
...(values.get('--url')?.[0] ? { url: values.get('--url')![0] } : {}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function numberOption(values: Map<string, string[]>, name: string): number | undefined {
|
|
74
|
+
const value = values.get(name)?.[0];
|
|
75
|
+
if (value === undefined) return undefined;
|
|
76
|
+
const parsed = Number(value);
|
|
77
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
78
|
+
throw new Error(`${name} must be a non-negative integer.`);
|
|
79
|
+
}
|
|
80
|
+
return parsed;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function main(): Promise<void> {
|
|
84
|
+
const options = parseArgs(process.argv.slice(2));
|
|
85
|
+
await using session = await connectModelCatalog(options.url);
|
|
86
|
+
process.stderr.write(`Using ${session.mode} catalog ${session.source}\n`);
|
|
87
|
+
|
|
88
|
+
if (options.command === 'catalog') {
|
|
89
|
+
process.stdout.write(`${JSON.stringify(await session.client.catalog())}\n`);
|
|
90
|
+
} else if (options.command === 'models') {
|
|
91
|
+
process.stdout.write(`${JSON.stringify(await session.client.list(options.filters), null, 2)}\n`);
|
|
92
|
+
} else {
|
|
93
|
+
for await (const model of session.client.stream(options.filters)) {
|
|
94
|
+
process.stdout.write(`${JSON.stringify(model)}\n`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
void main().catch(error => {
|
|
100
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
});
|