@yanlinglabs/winter-provider-catalog 0.0.1

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.
@@ -0,0 +1,94 @@
1
+ // src/families.ts
2
+ var SLOT_NAME_RE2 = /^[a-z0-9][a-z0-9.-]{0,31}$/;
3
+ var FAMILY_ID_RE2 = /^[a-z0-9][a-z0-9-]{0,31}$/;
4
+ var CLAUDE_FAMILY_ID2 = "claude";
5
+ var OTHER_FAMILY_ID2 = "other";
6
+ var CLAUDE_RESERVED_SLOT_NAMES2 = ["fable", "opus", "sonnet", "haiku"];
7
+ var CURRENCY_RE2 = /(?:[$€£]\s?\d)|(?:\d\s?(?:usd|dollars?)\b)/i;
8
+ var NAMESPACE_PREFIXES = ["models/", "anthropic/", "openai/", "google/", "deepseek/", "deepseek-ai/", "meta-llama/", "meta/", "qwen/", "x-ai/", "xai/", "moonshot/", "moonshotai/", "zai-org/", "z-ai/", "minimax/", "mistralai/", "nvidia/", "cline-pass/", "hf:", "aphrodite/"];
9
+ var BEDROCK_PREFIXES = ["us.", "eu.", "apac.", "global.", "anthropic.", "openai."];
10
+ function canonicalModelIdOf2(upstreamId) {
11
+ let id = upstreamId.trim().toLowerCase();
12
+ const account = /^accounts\/[^/]+\/models\/(.+)$/.exec(id);
13
+ if (account !== null)
14
+ id = account[1];
15
+ let namespaced = true;
16
+ while (namespaced) {
17
+ namespaced = false;
18
+ for (const prefix of NAMESPACE_PREFIXES) {
19
+ if (id.startsWith(prefix)) {
20
+ id = id.slice(prefix.length);
21
+ namespaced = true;
22
+ break;
23
+ }
24
+ }
25
+ }
26
+ let stripped = true;
27
+ while (stripped) {
28
+ stripped = false;
29
+ for (const prefix of BEDROCK_PREFIXES) {
30
+ if (id.startsWith(prefix)) {
31
+ id = id.slice(prefix.length);
32
+ stripped = true;
33
+ }
34
+ }
35
+ }
36
+ id = id.replace(/-(?:v)?\d+:\d+$/, "");
37
+ if (id.startsWith("zai-glm"))
38
+ id = id.slice("zai-".length);
39
+ id = id.replace(/-(\d)-(\d)(?=-|$)/g, "-$1.$2");
40
+ id = id.replace(/:(\d+[bB])$/, "-$1");
41
+ return id;
42
+ }
43
+ function familyIdOf2(canonicalModelId, families) {
44
+ for (const family of families) {
45
+ for (const matcher of family.matchers) {
46
+ if (new RegExp(matcher.pattern).test(canonicalModelId))
47
+ return family.id;
48
+ }
49
+ }
50
+ return OTHER_FAMILY_ID2;
51
+ }
52
+ function stampFamilyFields2(rows, families) {
53
+ return rows.map((row) => {
54
+ const canonicalModelId = row.canonicalModelId ?? canonicalModelIdOf2(row.upstreamId);
55
+ const modelFamily = row.modelFamily ?? familyIdOf2(canonicalModelId, families);
56
+ return { ...row, canonicalModelId, modelFamily };
57
+ });
58
+ }
59
+ function resolveSlotName2(name, activeFamilyId, families) {
60
+ const active = families.find((f) => f.id === activeFamilyId);
61
+ const own = active?.slots.find((s) => s.name === name);
62
+ if (active !== undefined && own !== undefined)
63
+ return { kind: "slot", family: active, slot: own, advertised: true };
64
+ if (CLAUDE_RESERVED_SLOT_NAMES2.includes(name)) {
65
+ const claude = families.find((f) => f.id === CLAUDE_FAMILY_ID2);
66
+ const slot = claude?.slots.find((s) => s.name === name);
67
+ if (claude !== undefined && slot !== undefined)
68
+ return { kind: "slot", family: claude, slot, advertised: false };
69
+ }
70
+ const hits = [];
71
+ for (const family of families)
72
+ for (const slot of family.slots)
73
+ if (slot.name === name)
74
+ hits.push({ family, slot });
75
+ if (hits.length === 1)
76
+ return { kind: "slot", family: hits[0].family, slot: hits[0].slot, advertised: false };
77
+ if (hits.length > 1)
78
+ return { kind: "ambiguous", name, candidates: hits.map((h) => `${h.family.id}/${h.slot.name}`) };
79
+ return { kind: "unknown", name };
80
+ }
81
+ function familyOfModelKey2(catalog, modelKey) {
82
+ const row = catalog.models.find((m) => m.key === modelKey);
83
+ if (row === undefined)
84
+ return;
85
+ return catalog.families.find((f) => f.id === row.modelFamily);
86
+ }
87
+ function isSlotServableRow2(row) {
88
+ return row.status !== "blocked" && row.status !== "deprecated" && (row.endpoints.includes("chat") || row.endpoints.includes("responses"));
89
+ }
90
+ function rowsForCanonicalId2(catalog, canonicalModelId) {
91
+ return catalog.models.filter((m) => m.canonicalModelId === canonicalModelId && isSlotServableRow2(m));
92
+ }
93
+
94
+ export { SLOT_NAME_RE2, FAMILY_ID_RE2, CLAUDE_FAMILY_ID2, OTHER_FAMILY_ID2, CLAUDE_RESERVED_SLOT_NAMES2, CURRENCY_RE2, canonicalModelIdOf2, familyIdOf2, stampFamilyFields2, resolveSlotName2, familyOfModelKey2, isSlotServableRow2, rowsForCanonicalId2 };
@@ -0,0 +1,19 @@
1
+ export type { CapabilityEvidence, CatalogValidationResult, EvidenceConfidence, EvidenceSource, FamilySlot, ModelFamilyDescriptor, ModelPricing, ModelStatus, ProviderAuthKind, ProviderProtocol, ReasoningCapabilities, SlotBasis, SlotStatus, ToolCalling, WinterCatalog, WinterModelDescriptor, WinterProviderDescriptor, } from "./types.js";
2
+ export { CATALOG_VOCABULARIES, scanForSecrets, validateCatalog } from "./validate.js";
3
+ export { CLAUDE_FAMILY_ID, CLAUDE_RESERVED_SLOT_NAMES, CURRENCY_RE, FAMILY_ID_RE, OTHER_FAMILY_ID, SLOT_NAME_RE, canonicalModelIdOf, familyIdOf, familyOfModelKey, isSlotServableRow, resolveSlotName, rowsForCanonicalId, stampFamilyFields, } from "./families.js";
4
+ export type { SlotNameResolution } from "./families.js";
5
+ import type { WinterCatalog } from "./types.js";
6
+ /**
7
+ * The catalog compiled into this build.
8
+ *
9
+ * VALIDATES rather than casts. TypeScript infers the imported JSON's *widened* shape
10
+ * (`schemaVersion: number`, every union member a bare `string`), so `catalogJson as WinterCatalog`
11
+ * would be an unchecked assertion dressed as a type — and a malformed committed catalog would then
12
+ * surface as an incomprehensible failure deep in an adapter. Running the real validator is what
13
+ * narrows it, and a failure here is a BUILD defect, so it throws rather than degrading.
14
+ *
15
+ * Memoised: the validator walks every row, and the catalog is immutable for the life of a process.
16
+ */
17
+ export declare function loadCatalog(): WinterCatalog;
18
+ /** Test seam: forget the memoised catalog. Never used in production — `loadCatalog()` is idempotent there. */
19
+ export declare function __resetCatalogCacheForTests(): void;