@dbx-tools/model 0.9.21 → 0.9.29

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 (86) hide show
  1. package/README.md +61 -10
  2. package/index.ts +12 -2
  3. package/lib/exports.d.ts +1 -0
  4. package/lib/exports.js +2 -0
  5. package/lib/index.d.ts +12 -2
  6. package/lib/index.js +9 -2
  7. package/lib/src/_metadata-contract.d.ts +42 -0
  8. package/lib/src/_metadata-contract.js +11 -0
  9. package/lib/src/_metadata-generator.d.ts +7 -0
  10. package/lib/src/_metadata-generator.js +182 -0
  11. package/lib/src/_ranking.d.ts +20 -0
  12. package/lib/src/_ranking.js +226 -0
  13. package/lib/src/_selection.d.ts +23 -0
  14. package/lib/src/_selection.js +95 -0
  15. package/lib/src/classes.d.ts +2 -2
  16. package/lib/src/classes.js +10 -8
  17. package/lib/src/classify.d.ts +130 -0
  18. package/lib/src/classify.js +283 -0
  19. package/lib/src/fallback.d.ts +4 -4
  20. package/lib/src/fallback.js +7 -7
  21. package/lib/src/generated/model-capabilities.json +90 -0
  22. package/lib/src/generated/model-rate-limits.json +342 -0
  23. package/lib/src/generated/retired-models.json +32 -0
  24. package/lib/src/invoke.js +3 -3
  25. package/lib/src/metadata.d.ts +33 -0
  26. package/lib/src/metadata.js +120 -0
  27. package/lib/src/model-catalog.d.ts +4 -4
  28. package/lib/src/model-catalog.js +19 -24
  29. package/lib/src/model-client.d.ts +67 -0
  30. package/lib/src/model-client.js +181 -0
  31. package/lib/src/policy.d.ts +14 -8
  32. package/lib/src/policy.js +173 -14
  33. package/lib/src/python.d.ts +2 -0
  34. package/lib/src/python.js +3 -0
  35. package/lib/src/resolve.d.ts +10 -143
  36. package/lib/src/resolve.js +11 -196
  37. package/lib/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +15 -5
  39. package/src/_metadata-contract.ts +56 -0
  40. package/src/_metadata-generator.ts +199 -0
  41. package/src/_ranking.ts +260 -0
  42. package/src/_selection.ts +141 -0
  43. package/src/classes.ts +11 -7
  44. package/src/classify.ts +324 -0
  45. package/src/fallback.ts +11 -7
  46. package/src/generated/model-capabilities.json +90 -0
  47. package/src/generated/model-rate-limits.json +342 -0
  48. package/src/generated/retired-models.json +32 -0
  49. package/src/invoke.ts +2 -2
  50. package/src/metadata.ts +189 -0
  51. package/src/model-catalog.ts +26 -28
  52. package/src/model-client.ts +311 -0
  53. package/src/policy.ts +176 -19
  54. package/src/python.ts +2 -0
  55. package/src/resolve.ts +24 -270
  56. package/._LICENSE +0 -0
  57. package/._README.md +0 -0
  58. package/._index.ts +0 -0
  59. package/._package.json +0 -0
  60. package/lib/._index.d.ts +0 -0
  61. package/lib/._index.js +0 -0
  62. package/lib/._tsconfig.tsbuildinfo +0 -0
  63. package/lib/src/.__native.d.ts +0 -0
  64. package/lib/src/.__native.js +0 -0
  65. package/lib/src/._classes.d.ts +0 -0
  66. package/lib/src/._classes.js +0 -0
  67. package/lib/src/._fallback.d.ts +0 -0
  68. package/lib/src/._fallback.js +0 -0
  69. package/lib/src/._invoke.d.ts +0 -0
  70. package/lib/src/._invoke.js +0 -0
  71. package/lib/src/._model-catalog.d.ts +0 -0
  72. package/lib/src/._model-catalog.js +0 -0
  73. package/lib/src/._policy.d.ts +0 -0
  74. package/lib/src/._policy.js +0 -0
  75. package/lib/src/._resolve.d.ts +0 -0
  76. package/lib/src/._resolve.js +0 -0
  77. package/lib/src/_native.d.ts +0 -14
  78. package/lib/src/_native.js +0 -124
  79. package/src/.__native.ts +0 -0
  80. package/src/._classes.ts +0 -0
  81. package/src/._fallback.ts +0 -0
  82. package/src/._invoke.ts +0 -0
  83. package/src/._model-catalog.ts +0 -0
  84. package/src/._policy.ts +0 -0
  85. package/src/._resolve.ts +0 -0
  86. package/src/_native.ts +0 -174
package/src/_native.ts DELETED
@@ -1,174 +0,0 @@
1
- import {
2
- ModelClass as NativeModelClass,
3
- ReasoningEffort as NativeReasoningEffort,
4
- normalizeServingEndpointsJson,
5
- rankModels as rankModelsWithRust,
6
- type ModelQuery as NativeModelQuery,
7
- type ServingEndpointSummary as NativeServingEndpointSummary,
8
- } from "@dbx-tools/model-rs";
9
- import {
10
- model,
11
- type ModelQuery,
12
- type RankedModel,
13
- type ReasoningEffort,
14
- type ServingEndpointSummary,
15
- } from "@dbx-tools/shared-model";
16
-
17
- type ModelClass = model.ModelClass;
18
-
19
- const MODEL_CLASS_TO_NATIVE: Readonly<Record<ModelClass, NativeModelClass>> = {
20
- [model.ModelClass.ChatThinking]: NativeModelClass.ChatThinking,
21
- [model.ModelClass.ChatBalanced]: NativeModelClass.ChatBalanced,
22
- [model.ModelClass.ChatFast]: NativeModelClass.ChatFast,
23
- [model.ModelClass.Embedding]: NativeModelClass.Embedding,
24
- };
25
-
26
- const REASONING_EFFORT_TO_NATIVE: Readonly<Record<string, NativeReasoningEffort>> = {
27
- none: NativeReasoningEffort.None,
28
- minimal: NativeReasoningEffort.Minimal,
29
- low: NativeReasoningEffort.Low,
30
- medium: NativeReasoningEffort.Medium,
31
- high: NativeReasoningEffort.High,
32
- xhigh: NativeReasoningEffort.Xhigh,
33
- max: NativeReasoningEffort.Max,
34
- };
35
-
36
- const REASONING_EFFORT_FROM_NATIVE: Readonly<Record<NativeReasoningEffort, ReasoningEffort>> = {
37
- [NativeReasoningEffort.None]: "none",
38
- [NativeReasoningEffort.Minimal]: "minimal",
39
- [NativeReasoningEffort.Low]: "low",
40
- [NativeReasoningEffort.Medium]: "medium",
41
- [NativeReasoningEffort.High]: "high",
42
- [NativeReasoningEffort.Xhigh]: "xhigh",
43
- [NativeReasoningEffort.Max]: "max",
44
- };
45
-
46
- interface NativeRankingOptions {
47
- readonly includeDeprecated?: boolean;
48
- readonly modelClass?: ModelClass;
49
- readonly task?: string;
50
- }
51
-
52
- /** Rank public endpoint records through the Rust-owned model policy. */
53
- export function rankEndpoints(
54
- endpoints: readonly ServingEndpointSummary[],
55
- query: ModelQuery = {},
56
- options: NativeRankingOptions = {},
57
- ): RankedModel[] {
58
- const endpointsByName = new Map(endpoints.map((endpoint) => [endpoint.name, endpoint]));
59
- return rankModelsWithRust(
60
- endpoints.map((endpoint) => toNativeEndpoint(endpoint, options)),
61
- toNativeQuery(query, options.includeDeprecated ?? false),
62
- ).map((ranked) => {
63
- const endpoint = endpointsByName.get(ranked.endpoint.name);
64
- if (!endpoint) {
65
- throw new Error(`Rust model ranking returned unknown endpoint "${ranked.endpoint.name}"`);
66
- }
67
- return {
68
- endpoint,
69
- modelClass: fromNativeClass(ranked.modelClass),
70
- ...(ranked.score !== undefined ? { score: ranked.score } : {}),
71
- };
72
- });
73
- }
74
-
75
- /** Classify chat and embedding endpoints through the Rust-owned policy. */
76
- export function classifyEndpointClasses(
77
- endpoints: readonly ServingEndpointSummary[],
78
- ): ReadonlyMap<string, ModelClass> {
79
- const chat = rankEndpoints(endpoints, {}, { includeDeprecated: true });
80
- const embeddings = rankEndpoints(
81
- endpoints,
82
- { modelClass: model.ModelClass.Embedding },
83
- { includeDeprecated: true },
84
- );
85
- return new Map(
86
- [...chat, ...embeddings].map((ranked) => [ranked.endpoint.name, ranked.modelClass]),
87
- );
88
- }
89
-
90
- /** Normalize serialized SDK endpoint records through the Rust-owned catalogue policy. */
91
- export function normalizeEndpoints(endpoints: readonly unknown[]): ServingEndpointSummary[] {
92
- return normalizeServingEndpointsJson(JSON.stringify({ endpoints })).map(fromNativeEndpoint);
93
- }
94
-
95
- function toNativeQuery(query: ModelQuery, includeDeprecated: boolean): NativeModelQuery {
96
- return {
97
- search: query.search,
98
- modelClass:
99
- query.modelClass === undefined ? undefined : MODEL_CLASS_TO_NATIVE[query.modelClass],
100
- requiresTools: query.requiresTools,
101
- includeDeprecated: includeDeprecated || undefined,
102
- limit: query.limit,
103
- threshold: query.threshold,
104
- };
105
- }
106
-
107
- function toNativeEndpoint(
108
- endpoint: ServingEndpointSummary,
109
- options: NativeRankingOptions,
110
- ): NativeServingEndpointSummary {
111
- const modelClass = options.modelClass ?? endpoint.class;
112
- return {
113
- name: endpoint.name,
114
- displayName: endpoint.displayName,
115
- family: endpoint.family,
116
- task: options.task ?? endpoint.task,
117
- state: endpoint.state,
118
- description: endpoint.description,
119
- supportsTools: endpoint.supportsTools,
120
- profile: endpoint.profile,
121
- modelClass: modelClass === undefined ? undefined : MODEL_CLASS_TO_NATIVE[modelClass],
122
- serviceNames: new Map(Object.entries(endpoint.serviceNames ?? {})),
123
- modelServiceName: endpoint.modelServiceName,
124
- reasoningEfforts: (endpoint.reasoningEfforts ?? []).map((effort) => {
125
- const native = REASONING_EFFORT_TO_NATIVE[effort];
126
- if (native === undefined) throw new Error(`Unknown reasoning effort "${effort}"`);
127
- return native;
128
- }),
129
- status: { deprecated: endpoint.status?.deprecated ?? false },
130
- dimension: endpoint.dimension,
131
- };
132
- }
133
-
134
- function fromNativeEndpoint(endpoint: NativeServingEndpointSummary): ServingEndpointSummary {
135
- return {
136
- name: endpoint.name,
137
- ...(endpoint.displayName !== undefined ? { displayName: endpoint.displayName } : {}),
138
- ...(endpoint.family !== undefined ? { family: endpoint.family } : {}),
139
- ...(endpoint.task !== undefined ? { task: endpoint.task } : {}),
140
- ...(endpoint.state !== undefined ? { state: endpoint.state } : {}),
141
- ...(endpoint.description !== undefined ? { description: endpoint.description } : {}),
142
- ...(endpoint.supportsTools !== undefined ? { supportsTools: endpoint.supportsTools } : {}),
143
- ...(endpoint.profile !== undefined ? { profile: endpoint.profile } : {}),
144
- ...(endpoint.modelClass !== undefined ? { class: fromNativeClass(endpoint.modelClass) } : {}),
145
- ...(endpoint.serviceNames.size > 0
146
- ? { serviceNames: Object.fromEntries(endpoint.serviceNames) }
147
- : {}),
148
- ...(endpoint.modelServiceName !== undefined
149
- ? { modelServiceName: endpoint.modelServiceName }
150
- : {}),
151
- ...(endpoint.reasoningEfforts.length > 0
152
- ? {
153
- reasoningEfforts: endpoint.reasoningEfforts.map(
154
- (effort) => REASONING_EFFORT_FROM_NATIVE[effort],
155
- ),
156
- }
157
- : {}),
158
- status: { deprecated: endpoint.status.deprecated },
159
- ...(endpoint.dimension !== undefined ? { dimension: endpoint.dimension } : {}),
160
- };
161
- }
162
-
163
- function fromNativeClass(modelClass: NativeModelClass): ModelClass {
164
- switch (modelClass) {
165
- case NativeModelClass.ChatThinking:
166
- return model.ModelClass.ChatThinking;
167
- case NativeModelClass.ChatBalanced:
168
- return model.ModelClass.ChatBalanced;
169
- case NativeModelClass.ChatFast:
170
- return model.ModelClass.ChatFast;
171
- case NativeModelClass.Embedding:
172
- return model.ModelClass.Embedding;
173
- }
174
- }