@goliapkg/tiktoken-wasm 3.1.1 → 3.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 CHANGED
@@ -1,14 +1,14 @@
1
- # @goliapkg/tokenrs-wasm
1
+ # @goliapkg/tiktoken-wasm
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@goliapkg/tokenrs-wasm?style=flat-square&logo=npm)](https://www.npmjs.com/package/@goliapkg/tokenrs-wasm)
4
- [![License](https://img.shields.io/npm/l/@goliapkg/tokenrs-wasm?style=flat-square)](../LICENSE)
3
+ [![npm](https://img.shields.io/npm/v/@goliapkg/tiktoken-wasm?style=flat-square&logo=npm)](https://www.npmjs.com/package/@goliapkg/tiktoken-wasm)
4
+ [![License](https://img.shields.io/npm/l/@goliapkg/tiktoken-wasm?style=flat-square)](../LICENSE)
5
5
 
6
- WebAssembly bindings for the [tiktoken](https://crates.io/crates/tiktoken) BPE tokenizer — run OpenAI-compatible tokenization directly in the browser or Node.js with near-native performance.
6
+ WebAssembly bindings for the [tiktoken](https://crates.io/crates/tiktoken) BPE tokenizer — run multi-provider tokenization directly in the browser or Node.js with near-native performance.
7
7
 
8
8
  ## Install
9
9
 
10
10
  ```bash
11
- npm install @goliapkg/tokenrs-wasm
11
+ npm install @goliapkg/tiktoken-wasm
12
12
  ```
13
13
 
14
14
  ## Build from source
@@ -21,7 +21,7 @@ wasm-pack build --target web --release
21
21
 
22
22
  Output is in `pkg/` — a complete npm-ready package containing:
23
23
  - `tiktoken_wasm.js` — ES module with WASM loader
24
- - `tiktoken_wasm_bg.wasm` — compiled WASM binary (~3 MB)
24
+ - `tiktoken_wasm_bg.wasm` — compiled WASM binary (~7 MB, ~3 MB gzipped)
25
25
  - `tiktoken_wasm.d.ts` — TypeScript type definitions
26
26
 
27
27
  ## Usage
@@ -32,29 +32,50 @@ Output is in `pkg/` — a complete npm-ready package containing:
32
32
  import init, {
33
33
  getEncoding,
34
34
  encodingForModel,
35
+ listEncodings,
36
+ modelToEncoding,
35
37
  estimateCost,
36
38
  getModelInfo,
39
+ allModels,
40
+ modelsByProvider,
37
41
  type Encoding,
38
- } from '@goliapkg/tokenrs-wasm'
42
+ type ModelInfo,
43
+ } from '@goliapkg/tiktoken-wasm'
39
44
 
40
45
  // initialize WASM module (required once, before any other calls)
41
46
  await init()
42
47
 
48
+ // discover available encodings
49
+ const names: string[] = listEncodings()
50
+ // ["cl100k_base", "o200k_base", ..., "mistral_v3"]
51
+
43
52
  // encode / decode
44
53
  const enc: Encoding = getEncoding('cl100k_base')
45
54
  const tokens: Uint32Array = enc.encode('hello world')
46
55
  const text: string = enc.decode(tokens) // "hello world"
47
56
  const count: number = enc.count('hello world') // 2
48
57
 
49
- // by model name
58
+ // special token handling
59
+ const countST: number = enc.countWithSpecialTokens('hi<|endoftext|>bye')
60
+
61
+ // vocabulary info
62
+ console.log(enc.vocabSize) // 100256
63
+ console.log(enc.numSpecialTokens) // 5
64
+
65
+ // by model name — supports OpenAI, Meta, DeepSeek, Qwen, Mistral
50
66
  const enc2 = encodingForModel('gpt-4o')
67
+ const encName = modelToEncoding('llama-4-scout') // "llama3"
51
68
 
52
69
  // cost estimation (USD)
53
70
  const cost: number = estimateCost('gpt-4o', 1000, 500)
54
71
 
55
- // model metadata
56
- const info = getModelInfo('claude-opus-4')
57
- // { id, provider, input_per_1m, output_per_1m, cached_input_per_1m, context_window, max_output }
72
+ // model metadata (fully typed)
73
+ const info: ModelInfo = getModelInfo('claude-opus-4')
74
+ console.log(info.id, info.provider, info.inputPer1m, info.contextWindow)
75
+
76
+ // browse all models or filter by provider
77
+ const all: ModelInfo[] = allModels()
78
+ const openai: ModelInfo[] = modelsByProvider('OpenAI')
58
79
 
59
80
  // free WASM memory when done
60
81
  enc.free()
@@ -97,40 +118,84 @@ module.exports = {
97
118
 
98
119
  ## API Reference
99
120
 
121
+ ### `listEncodings(): string[]`
122
+
123
+ List all available encoding names (9 encodings).
124
+
100
125
  ### `getEncoding(name: string): Encoding`
101
126
 
102
- Get a tokenizer by encoding name. Supported: `cl100k_base`, `o200k_base`, `p50k_base`, `p50k_edit`, `r50k_base`.
127
+ Get a tokenizer by encoding name. Supported:
128
+ - `cl100k_base` — GPT-4, GPT-3.5-turbo
129
+ - `o200k_base` — GPT-4o, GPT-4.1, o1, o3
130
+ - `p50k_base` — text-davinci-002/003
131
+ - `p50k_edit` — text-davinci-edit
132
+ - `r50k_base` — GPT-3 (davinci, curie, etc.)
133
+ - `llama3` — Meta Llama 3/4
134
+ - `deepseek_v3` — DeepSeek V3/R1
135
+ - `qwen2` — Qwen 2/2.5/3
136
+ - `mistral_v3` — Mistral/Codestral/Pixtral
103
137
 
104
138
  ### `encodingForModel(model: string): Encoding`
105
139
 
106
- Get a tokenizer by OpenAI model name (e.g. `gpt-4o`, `o3-mini`, `gpt-3.5-turbo`).
140
+ Get a tokenizer by model name (e.g. `gpt-4o`, `llama-4-scout`, `deepseek-r1`, `qwen3-235b`).
141
+
142
+ ### `modelToEncoding(model: string): string | null`
143
+
144
+ Map a model name to its encoding name without loading the encoding.
107
145
 
108
146
  ### `Encoding`
109
147
 
110
- | Method | Returns | Description |
111
- |--------|---------|-------------|
148
+ | Method / Property | Type | Description |
149
+ |-------------------|------|-------------|
112
150
  | `encode(text)` | `Uint32Array` | Encode text to token ids |
113
151
  | `encodeWithSpecialTokens(text)` | `Uint32Array` | Encode with special token recognition |
114
152
  | `decode(tokens)` | `string` | Decode token ids to text |
115
153
  | `count(text)` | `number` | Count tokens (faster than `encode().length`) |
154
+ | `countWithSpecialTokens(text)` | `number` | Count tokens with special token recognition |
116
155
  | `name` | `string` | Encoding name (getter) |
156
+ | `vocabSize` | `number` | Number of regular tokens in vocabulary |
157
+ | `numSpecialTokens` | `number` | Number of special tokens |
117
158
  | `free()` | `void` | Release WASM memory |
118
159
 
119
160
  ### `estimateCost(modelId, inputTokens, outputTokens): number`
120
161
 
121
- Estimate API cost in USD. Supports OpenAI, Anthropic Claude, and Google Gemini models.
162
+ Estimate API cost in USD. Supports 57 models across 7 providers.
163
+
164
+ ### `getModelInfo(modelId): ModelInfo`
165
+
166
+ Get model metadata with full TypeScript typing.
167
+
168
+ ### `allModels(): ModelInfo[]`
169
+
170
+ List all 57 supported models with pricing info.
171
+
172
+ ### `modelsByProvider(provider): ModelInfo[]`
173
+
174
+ Filter models by provider: `"OpenAI"`, `"Anthropic"`, `"Google"`, `"Meta"`, `"DeepSeek"`, `"Alibaba"`, `"Mistral"`.
122
175
 
123
- ### `getModelInfo(modelId): object`
176
+ ### `ModelInfo`
124
177
 
125
- Get model metadata: pricing, context window, max output tokens.
178
+ | Property | Type | Description |
179
+ |----------|------|-------------|
180
+ | `id` | `string` | Model identifier |
181
+ | `provider` | `string` | Provider name |
182
+ | `inputPer1m` | `number` | Input cost per 1M tokens (USD) |
183
+ | `outputPer1m` | `number` | Output cost per 1M tokens (USD) |
184
+ | `cachedInputPer1m` | `number \| undefined` | Cached input cost per 1M tokens |
185
+ | `contextWindow` | `number` | Max context window (tokens) |
186
+ | `maxOutput` | `number` | Max output tokens |
126
187
 
127
188
  ## Supported Models (pricing)
128
189
 
129
190
  | Provider | Models |
130
191
  |----------|--------|
131
- | OpenAI | gpt-4o, gpt-4o-mini, o1, o3, o4-mini, gpt-4-turbo, gpt-4, gpt-3.5-turbo, embeddings |
132
- | Anthropic | claude-opus-4, claude-sonnet-4, claude-3.5-haiku, claude-3.5-sonnet, claude-3-opus, claude-3-haiku |
192
+ | OpenAI | gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, gpt-4o, gpt-4o-mini, o3, o3-pro, o3-mini, o4-mini, o1, gpt-4-turbo, gpt-4, gpt-3.5-turbo, embeddings |
193
+ | Anthropic | claude-opus-4, claude-sonnet-4, claude-4.5-sonnet, claude-4.5-haiku, claude-4.6-sonnet, claude-4.6-opus, claude-4.6-haiku, claude-3.5-haiku, claude-3.5-sonnet, claude-3-opus, claude-3-haiku |
133
194
  | Google | gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash, gemini-1.5-pro, gemini-1.5-flash |
195
+ | Meta | llama-4-scout, llama-4-maverick, llama-3.3-70b, llama-3.1-405b, llama-3.1-70b, llama-3.1-8b |
196
+ | DeepSeek | deepseek-r1, deepseek-v3, deepseek-chat |
197
+ | Qwen | qwen3-235b, qwen3-32b, qwen3-30b-a3b, qwen3-14b, qwen-2.5-72b, qwen-2.5-coder-32b, qwen-turbo |
198
+ | Mistral | mistral-large, mistral-medium, mistral-small, codestral, pixtral-large |
134
199
 
135
200
  ## Demo
136
201
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@goliapkg/tiktoken-wasm",
3
3
  "type": "module",
4
4
  "description": "WASM bindings for the tiktoken BPE tokenizer",
5
- "version": "3.1.1",
5
+ "version": "3.2.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -17,6 +17,13 @@ export class Encoding {
17
17
  * Faster than `encode(text).length` for cases where you only need the count.
18
18
  */
19
19
  count(text: string): number;
20
+ /**
21
+ * Count tokens, recognizing special tokens.
22
+ *
23
+ * Like `count()` but special tokens (e.g. `<|endoftext|>`) are counted
24
+ * as single tokens instead of being split into sub-word pieces.
25
+ */
26
+ countWithSpecialTokens(text: string): number;
20
27
  /**
21
28
  * Decode token ids back to a UTF-8 string.
22
29
  *
@@ -41,8 +48,39 @@ export class Encoding {
41
48
  * Get the encoding name (e.g. `"cl100k_base"`).
42
49
  */
43
50
  readonly name: string;
51
+ /**
52
+ * Get the number of special tokens in the vocabulary.
53
+ */
54
+ readonly numSpecialTokens: number;
55
+ /**
56
+ * Get the number of regular (non-special) tokens in the vocabulary.
57
+ */
58
+ readonly vocabSize: number;
44
59
  }
45
60
 
61
+ /**
62
+ * Model pricing and metadata.
63
+ */
64
+ export class ModelInfo {
65
+ private constructor();
66
+ free(): void;
67
+ [Symbol.dispose](): void;
68
+ readonly cachedInputPer1m: number | undefined;
69
+ readonly contextWindow: number;
70
+ readonly id: string;
71
+ readonly inputPer1m: number;
72
+ readonly maxOutput: number;
73
+ readonly outputPer1m: number;
74
+ readonly provider: string;
75
+ }
76
+
77
+ /**
78
+ * List all supported models with pricing info.
79
+ *
80
+ * Returns an array of `ModelInfo` objects.
81
+ */
82
+ export function allModels(): ModelInfo[];
83
+
46
84
  /**
47
85
  * Get an encoding for a model name (e.g. `"gpt-4o"`, `"o3-mini"`, `"llama-4"`, `"deepseek-r1"`).
48
86
  *
@@ -79,34 +117,72 @@ export function estimateCost(model_id: string, input_tokens: number, output_toke
79
117
  export function getEncoding(name: string): Encoding;
80
118
 
81
119
  /**
82
- * Get model pricing and metadata as a JS object.
120
+ * Get model pricing and metadata.
83
121
  *
84
- * Returns an object with: `id`, `provider`, `input_per_1m`, `output_per_1m`,
85
- * `cached_input_per_1m`, `context_window`, `max_output`.
122
+ * Returns a typed object with: `id`, `provider`, `inputPer1m`, `outputPer1m`,
123
+ * `cachedInputPer1m`, `contextWindow`, `maxOutput`.
86
124
  *
87
125
  * Throws `Error` for unknown model ids.
88
126
  */
89
- export function getModelInfo(model_id: string): any;
127
+ export function getModelInfo(model_id: string): ModelInfo;
128
+
129
+ /**
130
+ * List all available encoding names.
131
+ *
132
+ * Returns an array of strings: `["cl100k_base", "o200k_base", ...]`
133
+ */
134
+ export function listEncodings(): any[];
135
+
136
+ /**
137
+ * Map a model name to its encoding name without loading the encoding.
138
+ *
139
+ * Returns the encoding name string (e.g. `"o200k_base"`) or `null` for unknown models.
140
+ */
141
+ export function modelToEncoding(model: string): string | undefined;
142
+
143
+ /**
144
+ * List models filtered by provider name.
145
+ *
146
+ * Provider names: `"OpenAI"`, `"Anthropic"`, `"Google"`, `"Meta"`, `"DeepSeek"`, `"Alibaba"`, `"Mistral"`.
147
+ * Returns an empty array for unknown providers.
148
+ */
149
+ export function modelsByProvider(provider: string): ModelInfo[];
90
150
 
91
151
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
92
152
 
93
153
  export interface InitOutput {
94
154
  readonly memory: WebAssembly.Memory;
95
155
  readonly __wbg_encoding_free: (a: number, b: number) => void;
156
+ readonly __wbg_modelinfo_free: (a: number, b: number) => void;
157
+ readonly allModels: () => [number, number];
96
158
  readonly encodingForModel: (a: number, b: number) => [number, number, number];
97
159
  readonly encoding_count: (a: number, b: number, c: number) => number;
160
+ readonly encoding_countWithSpecialTokens: (a: number, b: number, c: number) => number;
98
161
  readonly encoding_decode: (a: number, b: number, c: number) => [number, number];
99
162
  readonly encoding_encode: (a: number, b: number, c: number) => [number, number];
100
163
  readonly encoding_encodeWithSpecialTokens: (a: number, b: number, c: number) => [number, number];
101
164
  readonly encoding_name: (a: number) => [number, number];
165
+ readonly encoding_numSpecialTokens: (a: number) => number;
166
+ readonly encoding_vocabSize: (a: number) => number;
102
167
  readonly estimateCost: (a: number, b: number, c: number, d: number) => [number, number, number];
103
168
  readonly getEncoding: (a: number, b: number) => [number, number, number];
104
169
  readonly getModelInfo: (a: number, b: number) => [number, number, number];
170
+ readonly listEncodings: () => [number, number];
171
+ readonly modelToEncoding: (a: number, b: number) => [number, number];
172
+ readonly modelinfo_cachedInputPer1m: (a: number) => [number, number];
173
+ readonly modelinfo_contextWindow: (a: number) => number;
174
+ readonly modelinfo_id: (a: number) => [number, number];
175
+ readonly modelinfo_inputPer1m: (a: number) => number;
176
+ readonly modelinfo_maxOutput: (a: number) => number;
177
+ readonly modelinfo_outputPer1m: (a: number) => number;
178
+ readonly modelinfo_provider: (a: number) => [number, number];
179
+ readonly modelsByProvider: (a: number, b: number) => [number, number];
180
+ readonly __wbindgen_externrefs: WebAssembly.Table;
181
+ readonly __externref_drop_slice: (a: number, b: number) => void;
182
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
105
183
  readonly __wbindgen_malloc: (a: number, b: number) => number;
106
184
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
107
- readonly __wbindgen_externrefs: WebAssembly.Table;
108
185
  readonly __externref_table_dealloc: (a: number) => void;
109
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
110
186
  readonly __wbindgen_start: () => void;
111
187
  }
112
188
 
package/tiktoken_wasm.js CHANGED
@@ -37,6 +37,20 @@ export class Encoding {
37
37
  const ret = wasm.encoding_count(this.__wbg_ptr, ptr0, len0);
38
38
  return ret >>> 0;
39
39
  }
40
+ /**
41
+ * Count tokens, recognizing special tokens.
42
+ *
43
+ * Like `count()` but special tokens (e.g. `<|endoftext|>`) are counted
44
+ * as single tokens instead of being split into sub-word pieces.
45
+ * @param {string} text
46
+ * @returns {number}
47
+ */
48
+ countWithSpecialTokens(text) {
49
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
50
+ const len0 = WASM_VECTOR_LEN;
51
+ const ret = wasm.encoding_countWithSpecialTokens(this.__wbg_ptr, ptr0, len0);
52
+ return ret >>> 0;
53
+ }
40
54
  /**
41
55
  * Decode token ids back to a UTF-8 string.
42
56
  *
@@ -106,9 +120,127 @@ export class Encoding {
106
120
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
107
121
  }
108
122
  }
123
+ /**
124
+ * Get the number of special tokens in the vocabulary.
125
+ * @returns {number}
126
+ */
127
+ get numSpecialTokens() {
128
+ const ret = wasm.encoding_numSpecialTokens(this.__wbg_ptr);
129
+ return ret >>> 0;
130
+ }
131
+ /**
132
+ * Get the number of regular (non-special) tokens in the vocabulary.
133
+ * @returns {number}
134
+ */
135
+ get vocabSize() {
136
+ const ret = wasm.encoding_vocabSize(this.__wbg_ptr);
137
+ return ret >>> 0;
138
+ }
109
139
  }
110
140
  if (Symbol.dispose) Encoding.prototype[Symbol.dispose] = Encoding.prototype.free;
111
141
 
142
+ /**
143
+ * Model pricing and metadata.
144
+ */
145
+ export class ModelInfo {
146
+ static __wrap(ptr) {
147
+ ptr = ptr >>> 0;
148
+ const obj = Object.create(ModelInfo.prototype);
149
+ obj.__wbg_ptr = ptr;
150
+ ModelInfoFinalization.register(obj, obj.__wbg_ptr, obj);
151
+ return obj;
152
+ }
153
+ __destroy_into_raw() {
154
+ const ptr = this.__wbg_ptr;
155
+ this.__wbg_ptr = 0;
156
+ ModelInfoFinalization.unregister(this);
157
+ return ptr;
158
+ }
159
+ free() {
160
+ const ptr = this.__destroy_into_raw();
161
+ wasm.__wbg_modelinfo_free(ptr, 0);
162
+ }
163
+ /**
164
+ * @returns {number | undefined}
165
+ */
166
+ get cachedInputPer1m() {
167
+ const ret = wasm.modelinfo_cachedInputPer1m(this.__wbg_ptr);
168
+ return ret[0] === 0 ? undefined : ret[1];
169
+ }
170
+ /**
171
+ * @returns {number}
172
+ */
173
+ get contextWindow() {
174
+ const ret = wasm.modelinfo_contextWindow(this.__wbg_ptr);
175
+ return ret >>> 0;
176
+ }
177
+ /**
178
+ * @returns {string}
179
+ */
180
+ get id() {
181
+ let deferred1_0;
182
+ let deferred1_1;
183
+ try {
184
+ const ret = wasm.modelinfo_id(this.__wbg_ptr);
185
+ deferred1_0 = ret[0];
186
+ deferred1_1 = ret[1];
187
+ return getStringFromWasm0(ret[0], ret[1]);
188
+ } finally {
189
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
190
+ }
191
+ }
192
+ /**
193
+ * @returns {number}
194
+ */
195
+ get inputPer1m() {
196
+ const ret = wasm.modelinfo_inputPer1m(this.__wbg_ptr);
197
+ return ret;
198
+ }
199
+ /**
200
+ * @returns {number}
201
+ */
202
+ get maxOutput() {
203
+ const ret = wasm.modelinfo_maxOutput(this.__wbg_ptr);
204
+ return ret >>> 0;
205
+ }
206
+ /**
207
+ * @returns {number}
208
+ */
209
+ get outputPer1m() {
210
+ const ret = wasm.modelinfo_outputPer1m(this.__wbg_ptr);
211
+ return ret;
212
+ }
213
+ /**
214
+ * @returns {string}
215
+ */
216
+ get provider() {
217
+ let deferred1_0;
218
+ let deferred1_1;
219
+ try {
220
+ const ret = wasm.modelinfo_provider(this.__wbg_ptr);
221
+ deferred1_0 = ret[0];
222
+ deferred1_1 = ret[1];
223
+ return getStringFromWasm0(ret[0], ret[1]);
224
+ } finally {
225
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
226
+ }
227
+ }
228
+ }
229
+ if (Symbol.dispose) ModelInfo.prototype[Symbol.dispose] = ModelInfo.prototype.free;
230
+
231
+ /**
232
+ * List all supported models with pricing info.
233
+ *
234
+ * Returns an array of `ModelInfo` objects.
235
+ * @returns {ModelInfo[]}
236
+ */
237
+ export function allModels() {
238
+ const ret = wasm.allModels();
239
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
240
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
241
+ return v1;
242
+ }
243
+
112
244
  /**
113
245
  * Get an encoding for a model name (e.g. `"gpt-4o"`, `"o3-mini"`, `"llama-4"`, `"deepseek-r1"`).
114
246
  *
@@ -177,14 +309,14 @@ export function getEncoding(name) {
177
309
  }
178
310
 
179
311
  /**
180
- * Get model pricing and metadata as a JS object.
312
+ * Get model pricing and metadata.
181
313
  *
182
- * Returns an object with: `id`, `provider`, `input_per_1m`, `output_per_1m`,
183
- * `cached_input_per_1m`, `context_window`, `max_output`.
314
+ * Returns a typed object with: `id`, `provider`, `inputPer1m`, `outputPer1m`,
315
+ * `cachedInputPer1m`, `contextWindow`, `maxOutput`.
184
316
  *
185
317
  * Throws `Error` for unknown model ids.
186
318
  * @param {string} model_id
187
- * @returns {any}
319
+ * @returns {ModelInfo}
188
320
  */
189
321
  export function getModelInfo(model_id) {
190
322
  const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -193,7 +325,56 @@ export function getModelInfo(model_id) {
193
325
  if (ret[2]) {
194
326
  throw takeFromExternrefTable0(ret[1]);
195
327
  }
196
- return takeFromExternrefTable0(ret[0]);
328
+ return ModelInfo.__wrap(ret[0]);
329
+ }
330
+
331
+ /**
332
+ * List all available encoding names.
333
+ *
334
+ * Returns an array of strings: `["cl100k_base", "o200k_base", ...]`
335
+ * @returns {any[]}
336
+ */
337
+ export function listEncodings() {
338
+ const ret = wasm.listEncodings();
339
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
340
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
341
+ return v1;
342
+ }
343
+
344
+ /**
345
+ * Map a model name to its encoding name without loading the encoding.
346
+ *
347
+ * Returns the encoding name string (e.g. `"o200k_base"`) or `null` for unknown models.
348
+ * @param {string} model
349
+ * @returns {string | undefined}
350
+ */
351
+ export function modelToEncoding(model) {
352
+ const ptr0 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
353
+ const len0 = WASM_VECTOR_LEN;
354
+ const ret = wasm.modelToEncoding(ptr0, len0);
355
+ let v2;
356
+ if (ret[0] !== 0) {
357
+ v2 = getStringFromWasm0(ret[0], ret[1]).slice();
358
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
359
+ }
360
+ return v2;
361
+ }
362
+
363
+ /**
364
+ * List models filtered by provider name.
365
+ *
366
+ * Provider names: `"OpenAI"`, `"Anthropic"`, `"Google"`, `"Meta"`, `"DeepSeek"`, `"Alibaba"`, `"Mistral"`.
367
+ * Returns an empty array for unknown providers.
368
+ * @param {string} provider
369
+ * @returns {ModelInfo[]}
370
+ */
371
+ export function modelsByProvider(provider) {
372
+ const ptr0 = passStringToWasm0(provider, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
373
+ const len0 = WASM_VECTOR_LEN;
374
+ const ret = wasm.modelsByProvider(ptr0, len0);
375
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
376
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
377
+ return v2;
197
378
  }
198
379
 
199
380
  function __wbg_get_imports() {
@@ -203,29 +384,14 @@ function __wbg_get_imports() {
203
384
  const ret = Error(getStringFromWasm0(arg0, arg1));
204
385
  return ret;
205
386
  },
206
- __wbg_String_8564e559799eccda: function(arg0, arg1) {
207
- const ret = String(arg1);
208
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
209
- const len1 = WASM_VECTOR_LEN;
210
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
211
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
212
- },
213
387
  __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
214
388
  throw new Error(getStringFromWasm0(arg0, arg1));
215
389
  },
216
- __wbg_new_ab79df5bd7c26067: function() {
217
- const ret = new Object();
218
- return ret;
219
- },
220
- __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
221
- arg0[arg1] = arg2;
222
- },
223
- __wbindgen_cast_0000000000000001: function(arg0) {
224
- // Cast intrinsic for `F64 -> Externref`.
225
- const ret = arg0;
390
+ __wbg_modelinfo_new: function(arg0) {
391
+ const ret = ModelInfo.__wrap(arg0);
226
392
  return ret;
227
393
  },
228
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
394
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
229
395
  // Cast intrinsic for `Ref(String) -> Externref`.
230
396
  const ret = getStringFromWasm0(arg0, arg1);
231
397
  return ret;
@@ -249,6 +415,20 @@ function __wbg_get_imports() {
249
415
  const EncodingFinalization = (typeof FinalizationRegistry === 'undefined')
250
416
  ? { register: () => {}, unregister: () => {} }
251
417
  : new FinalizationRegistry(ptr => wasm.__wbg_encoding_free(ptr >>> 0, 1));
418
+ const ModelInfoFinalization = (typeof FinalizationRegistry === 'undefined')
419
+ ? { register: () => {}, unregister: () => {} }
420
+ : new FinalizationRegistry(ptr => wasm.__wbg_modelinfo_free(ptr >>> 0, 1));
421
+
422
+ function getArrayJsValueFromWasm0(ptr, len) {
423
+ ptr = ptr >>> 0;
424
+ const mem = getDataViewMemory0();
425
+ const result = [];
426
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
427
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
428
+ }
429
+ wasm.__externref_drop_slice(ptr, len);
430
+ return result;
431
+ }
252
432
 
253
433
  function getArrayU32FromWasm0(ptr, len) {
254
434
  ptr = ptr >>> 0;
Binary file