ai-model-directory 0.1.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 ADDED
@@ -0,0 +1,11 @@
1
+ # ai-model-directory
2
+
3
+ Bundled version of [the AI Model Directory's](https://github.com/The-Best-Codes/ai-model-directory) `data/all.min.json` with a compact typed payload.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import { openai } from "ai-model-directory";
9
+
10
+ console.log(openai.models["gpt-5.5"]?.pricing?.input);
11
+ ```
@@ -0,0 +1,3 @@
1
+ import type { CompactProviderEntry } from "./compact-types.js";
2
+ import type { ModelDirectory } from "./types.js";
3
+ export declare function decodeModelDirectory(data: readonly CompactProviderEntry[]): ModelDirectory;
@@ -0,0 +1,196 @@
1
+ const modelNameSameAsId = "";
2
+ const modalityOrder = [
3
+ "audio",
4
+ "file",
5
+ "image",
6
+ "text",
7
+ "video",
8
+ ];
9
+ const featureKeys = [
10
+ "attachment",
11
+ "reasoning",
12
+ "tool_call",
13
+ "structured_output",
14
+ "temperature",
15
+ ];
16
+ const pricingKeys = [
17
+ "input",
18
+ "output",
19
+ "reasoning",
20
+ "cache_read",
21
+ "cache_write",
22
+ "input_audio",
23
+ "output_audio",
24
+ ];
25
+ const limitKeys = [
26
+ "context",
27
+ "input",
28
+ "output",
29
+ ];
30
+ function toTimestamp(value) {
31
+ return value === null || value === undefined ? undefined : String(value);
32
+ }
33
+ function decodeAiSdk(value) {
34
+ if (!value) {
35
+ return undefined;
36
+ }
37
+ const [npmPackage, defaultApiKeyEnv] = value;
38
+ const result = {};
39
+ if (npmPackage !== null && npmPackage !== undefined) {
40
+ result.npmPackage = npmPackage;
41
+ }
42
+ if (defaultApiKeyEnv !== null && defaultApiKeyEnv !== undefined) {
43
+ result.defaultApiKeyEnv = [...defaultApiKeyEnv];
44
+ }
45
+ return Object.keys(result).length > 0 ? result : undefined;
46
+ }
47
+ function decodeFeatures(value) {
48
+ if (!value) {
49
+ return undefined;
50
+ }
51
+ const [presentMask, truthyMask] = value;
52
+ const result = {};
53
+ for (let index = 0; index < featureKeys.length; index += 1) {
54
+ const key = featureKeys[index];
55
+ if (!key) {
56
+ continue;
57
+ }
58
+ const bit = 1 << index;
59
+ if ((presentMask & bit) === 0) {
60
+ continue;
61
+ }
62
+ result[key] = (truthyMask & bit) !== 0;
63
+ }
64
+ return Object.keys(result).length > 0 ? result : undefined;
65
+ }
66
+ function decodePricing(value) {
67
+ if (!value) {
68
+ return undefined;
69
+ }
70
+ const result = {};
71
+ for (let index = 0; index < pricingKeys.length; index += 1) {
72
+ const key = pricingKeys[index];
73
+ const entry = value[index];
74
+ if (key && entry !== null && entry !== undefined) {
75
+ result[key] = entry;
76
+ }
77
+ }
78
+ return Object.keys(result).length > 0 ? result : undefined;
79
+ }
80
+ function decodeLimit(value) {
81
+ if (!value) {
82
+ return undefined;
83
+ }
84
+ const result = {};
85
+ for (let index = 0; index < limitKeys.length; index += 1) {
86
+ const key = limitKeys[index];
87
+ const entry = value[index];
88
+ if (key && entry !== null && entry !== undefined) {
89
+ result[key] = entry;
90
+ }
91
+ }
92
+ return Object.keys(result).length > 0 ? result : undefined;
93
+ }
94
+ function decodeModalityMask(mask) {
95
+ if (mask === null || mask === undefined || mask === 0) {
96
+ return undefined;
97
+ }
98
+ const result = [];
99
+ for (let index = 0; index < modalityOrder.length; index += 1) {
100
+ const modality = modalityOrder[index];
101
+ if (modality && (mask & (1 << index)) !== 0) {
102
+ result.push(modality);
103
+ }
104
+ }
105
+ return result.length > 0 ? result : undefined;
106
+ }
107
+ function decodeModalities(value) {
108
+ if (!value) {
109
+ return undefined;
110
+ }
111
+ const [inputMask, outputMask] = value;
112
+ const result = {};
113
+ const input = decodeModalityMask(inputMask);
114
+ const output = decodeModalityMask(outputMask);
115
+ if (input) {
116
+ result.input = input;
117
+ }
118
+ if (output) {
119
+ result.output = output;
120
+ }
121
+ return Object.keys(result).length > 0 ? result : undefined;
122
+ }
123
+ function decodeModel(entry) {
124
+ const [id, compactName, releaseDate, knowledgeCutoff, lastUpdated, openWeights, features, pricing, limit, modalities,] = entry;
125
+ const model = { id };
126
+ const releaseDateValue = toTimestamp(releaseDate);
127
+ const knowledgeCutoffValue = toTimestamp(knowledgeCutoff);
128
+ const lastUpdatedValue = toTimestamp(lastUpdated);
129
+ const decodedFeatures = decodeFeatures(features);
130
+ const decodedPricing = decodePricing(pricing);
131
+ const decodedLimit = decodeLimit(limit);
132
+ const decodedModalities = decodeModalities(modalities);
133
+ if (compactName === modelNameSameAsId) {
134
+ model.name = id;
135
+ }
136
+ else if (compactName !== null && compactName !== undefined) {
137
+ model.name = compactName;
138
+ }
139
+ if (knowledgeCutoffValue !== undefined) {
140
+ model.knowledge_cutoff = knowledgeCutoffValue;
141
+ }
142
+ if (releaseDateValue !== undefined) {
143
+ model.release_date = releaseDateValue;
144
+ }
145
+ if (lastUpdatedValue !== undefined) {
146
+ model.last_updated = lastUpdatedValue;
147
+ }
148
+ if (openWeights !== null && openWeights !== undefined) {
149
+ model.open_weights = openWeights;
150
+ }
151
+ if (decodedFeatures) {
152
+ model.features = decodedFeatures;
153
+ }
154
+ if (decodedPricing) {
155
+ model.pricing = decodedPricing;
156
+ }
157
+ if (decodedLimit) {
158
+ model.limit = decodedLimit;
159
+ }
160
+ if (decodedModalities) {
161
+ model.modalities = decodedModalities;
162
+ }
163
+ return model;
164
+ }
165
+ function decodeProvider(entry) {
166
+ const [id, name, website, apiBaseUrl, aiSdk, models = []] = entry;
167
+ const compactModels = models ?? [];
168
+ const provider = {
169
+ id,
170
+ name,
171
+ };
172
+ if (website !== null && website !== undefined) {
173
+ provider.website = website;
174
+ }
175
+ if (apiBaseUrl !== null && apiBaseUrl !== undefined) {
176
+ provider.apiBaseUrl = apiBaseUrl;
177
+ }
178
+ const decodedAiSdk = decodeAiSdk(aiSdk);
179
+ if (decodedAiSdk) {
180
+ provider.aiSdk = decodedAiSdk;
181
+ }
182
+ provider.models = {};
183
+ for (const modelEntry of compactModels) {
184
+ const model = decodeModel(modelEntry);
185
+ provider.models[model.id] = model;
186
+ }
187
+ return provider;
188
+ }
189
+ export function decodeModelDirectory(data) {
190
+ const result = {};
191
+ for (const providerEntry of data) {
192
+ const provider = decodeProvider(providerEntry);
193
+ result[provider.id] = provider;
194
+ }
195
+ return result;
196
+ }
@@ -0,0 +1,46 @@
1
+ export type CompactAiSdk = readonly [
2
+ npmPackage?: string | null,
3
+ defaultApiKeyEnv?: readonly string[] | null
4
+ ];
5
+ export type CompactFeatures = readonly [
6
+ presentMask: number,
7
+ truthyMask: number
8
+ ];
9
+ export type CompactPricing = readonly [
10
+ input?: number | null,
11
+ output?: number | null,
12
+ reasoning?: number | null,
13
+ cacheRead?: number | null,
14
+ cacheWrite?: number | null,
15
+ inputAudio?: number | null,
16
+ outputAudio?: number | null
17
+ ];
18
+ export type CompactLimit = readonly [
19
+ context?: number | null,
20
+ input?: number | null,
21
+ output?: number | null
22
+ ];
23
+ export type CompactModalities = readonly [
24
+ inputMask?: number | null,
25
+ outputMask?: number | null
26
+ ];
27
+ export type CompactModelEntry = readonly [
28
+ id: string,
29
+ name?: string | null,
30
+ releaseDate?: number | null,
31
+ knowledgeCutoff?: number | null,
32
+ lastUpdated?: number | null,
33
+ openWeights?: boolean | null,
34
+ features?: CompactFeatures | null,
35
+ pricing?: CompactPricing | null,
36
+ limit?: CompactLimit | null,
37
+ modalities?: CompactModalities | null
38
+ ];
39
+ export type CompactProviderEntry = readonly [
40
+ id: string,
41
+ name: string,
42
+ website?: string | null,
43
+ apiBaseUrl?: string | null,
44
+ aiSdk?: CompactAiSdk | null,
45
+ models?: readonly CompactModelEntry[] | null
46
+ ];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { CompactProviderEntry } from "./compact-types.js";
2
+ export declare const compactModelDirectoryData: readonly CompactProviderEntry[];
@@ -0,0 +1,2 @@
1
+ import { rawCompactModelDirectoryData } from "./generated-data.js";
2
+ export const compactModelDirectoryData = rawCompactModelDirectoryData;
@@ -0,0 +1 @@
1
+ export declare const rawCompactModelDirectoryData: (string | (string | string[])[] | (string | number | boolean | (number | null)[] | null)[][])[][];