@goliapkg/tiktoken-wasm 4.1.2 → 5.0.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
@@ -23,7 +23,7 @@ wasm-pack build --target web --release
23
23
 
24
24
  Output is in `pkg/` — a complete npm-ready package containing:
25
25
  - `tiktoken_wasm.js` — ES module with WASM loader
26
- - `tiktoken_wasm_bg.wasm` — compiled WASM binary (6.28 MB, 5.55 MB gzipped, all 17 vocabularies)
26
+ - `tiktoken_wasm_bg.wasm` — compiled WASM binary (8.96 MB, 8.22 MB gzipped, all 20 vocabularies)
27
27
 
28
28
  Building it yourself, `--no-default-features --features vocab-o200k_base` (or
29
29
  any other `vocab-*` / vendor group forwarded from `tiktoken`) drops that to
@@ -53,7 +53,7 @@ await init()
53
53
 
54
54
  // discover available encodings
55
55
  const names: string[] = listEncodings()
56
- // ["cl100k_base", "o200k_base", ..., "mistral_v3"]
56
+ // ["cl100k_base", "o200k_base", ..., "minimax_m2"]
57
57
 
58
58
  // encode / decode
59
59
  const enc: Encoding = getEncoding('cl100k_base')
@@ -70,7 +70,7 @@ console.log(enc.numSpecialTokens) // 5
70
70
 
71
71
  // by model name — supports OpenAI, Meta, DeepSeek, Qwen, Mistral
72
72
  const enc2 = encodingForModel('gpt-4o')
73
- const encName = modelToEncoding('llama-4-scout') // "llama3"
73
+ const encName = modelToEncoding('llama-4-scout') // "llama4"
74
74
 
75
75
  // cost estimation (USD)
76
76
  const cost: number = estimateCost('gpt-4o', 1000, 500)
@@ -132,22 +132,25 @@ List all available encoding names (17 encodings).
132
132
 
133
133
  Get a tokenizer by encoding name. Supported:
134
134
  - `cl100k_base` — GPT-4, GPT-3.5-turbo
135
- - `o200k_base` — GPT-4o, GPT-4.1, GPT-5–5.6, o1, o3, o4-mini
135
+ - `o200k_base` — GPT-4o, GPT-4.1, GPT-5–5.6, GPT-6 (unconfirmed), o1, o3, o4-mini
136
136
  - `o200k_harmony` — gpt-oss (harmony chat format)
137
137
  - `p50k_base` — text-davinci-002/003
138
138
  - `p50k_edit` — text-davinci-edit
139
139
  - `r50k_base` — GPT-3 (davinci, curie, etc.)
140
140
  - `gpt2` — GPT-2 (alias for `r50k_base`)
141
- - `llama3` — Meta Llama 3/4
141
+ - `llama3` — Meta Llama 3.x
142
+ - `llama4` — Meta Llama 4, Muse
142
143
  - `deepseek_v3` — DeepSeek V3/R1
143
144
  - `qwen2` — Qwen 2/2.5/3
145
+ - `qwen3_5` — Qwen 3.5–3.8, Qwen 4 (unconfirmed)
144
146
  - `mistral_v3` — Mistral/Codestral/Pixtral (Tekken)
145
- - `deepseek_v4` — DeepSeek V4 Pro/Flash
147
+ - `mistral_v15` — Mistral Large 4 (Tekken v15)
148
+ - `deepseek_v4` — DeepSeek V4 Pro/Flash, V4.1 Flash
146
149
  - `kimi_k2` — Kimi K2/K2.5/K2.6
147
- - `kimi_k3` — Kimi K3
150
+ - `kimi_k3` — Kimi K3/K3.1
148
151
  - `glm4` — GLM-4.5/4.6/4.7
149
- - `glm5` — GLM-5/5.2
150
- - `minimax_m2` — MiniMax M2 family
152
+ - `glm5` — GLM-5/5.1/5.2/5.3
153
+ - `minimax_m2` — MiniMax M2 and M3 families
151
154
 
152
155
  ### `encodingForModel(model: string): Encoding`
153
156
 
@@ -173,7 +176,7 @@ Map a model name to its encoding name without loading the encoding.
173
176
 
174
177
  ### `estimateCost(modelId, inputTokens, outputTokens): number`
175
178
 
176
- Estimate API cost in USD. Supports 116 models across 11 providers.
179
+ Estimate API cost in USD. Supports 153 models across 11 providers.
177
180
 
178
181
  ### `getModelInfo(modelId): ModelInfo`
179
182
 
@@ -185,7 +188,7 @@ model. The returned `id` is this table's own spelling.
185
188
 
186
189
  ### `allModels(): ModelInfo[]`
187
190
 
188
- List all 116 supported models with pricing info.
191
+ List all 153 supported models with pricing info.
189
192
 
190
193
  ### `modelsByProvider(provider): ModelInfo[]`
191
194
 
@@ -205,21 +208,21 @@ Filter models by provider: `"OpenAI"`, `"Anthropic"`, `"Google"`, `"Meta"`, `"De
205
208
 
206
209
  ## Supported Models (pricing)
207
210
 
208
- `estimateCost` / `getModelInfo` / `allModels` cover **116 models across 11
209
- providers** (2026-08 pricing). Per provider, newest first:
211
+ `estimateCost` / `getModelInfo` / `allModels` cover **153 models across 11
212
+ providers** (2026-11 pricing). Per provider, newest first:
210
213
 
211
214
  | Provider | Models | Latest entries |
212
215
  |----------|-------:|----------------|
213
- | OpenAI | 34 | gpt-5.6-sol/terra/luna, gpt-5.5(-pro), gpt-5.4(-mini/nano/pro), gpt-5.2(-pro), gpt-5.1, gpt-5(-mini/nano/pro), gpt-4.1, gpt-4o, o1/o3/o4-mini, … |
214
- | Anthropic | 17 | claude-fable-5, claude-mythos-5, claude-opus-5, claude-sonnet-5, claude-opus-4.8/4.7/4.6, claude-haiku-4.5, … |
215
- | Google | 13 | gemini-3.1-pro-preview, gemini-3.6/3.5-flash, gemini-2.5-pro/flash, … |
216
- | Mistral | 12 | mistral-large/medium/small, codestral, devstral, ministral, pixtral-large, … |
217
- | Alibaba | 9 | qwen3.8-max, qwen3.5-plus, qwen3-max/plus/coder, qwen2.5-72b, … |
218
- | Meta | 6 | llama-4-scout/maverick, llama-3.3-70b, llama-3.1-405b/70b/8b |
219
- | Zhipu | 5 | glm-5.2, glm-5, glm-4.7, glm-4.5(-air) |
220
- | DeepSeek | 4 | deepseek-v4-pro, deepseek-v4-flash, deepseek-v3, deepseek-r1 |
221
- | MiniMax | 4 | minimax-m2.7, minimax-m2.5, minimax-m2.1, minimax-m2 |
222
- | Moonshot | 4 | kimi-k3, kimi-k2.7-code, kimi-k2.6, kimi-k2.5 |
216
+ | OpenAI | 41 | gpt-6.2-astra/sol, gpt-6.1-sol/terra, gpt-6-astra/sol/luna, gpt-5.6-sol/terra/luna, gpt-5.5(-pro), gpt-5.4(-mini/nano/pro), gpt-5.2(-pro), gpt-5.1, gpt-5(-mini/nano/pro), gpt-4.1, gpt-4o, o1/o3/o4-mini, … |
217
+ | Anthropic | 24 | claude-fable-5.2/5.1/5, claude-mythos-5.2/5.1/5, claude-opus-5.5/5, claude-sonnet-5.5/5, claude-haiku-5.5, claude-opus-4.8/4.7/4.6, claude-haiku-4.5, … |
218
+ | Google | 19 | gemini-4-neon/hydrogen/carbon/argon, gemini-3.8-flash, gemini-3.1-pro-preview, gemini-3.6/3.5-flash, gemini-embedding-2, gemini-2.5-pro/flash, … |
219
+ | Mistral | 15 | mistral-large-4, mistral-large/medium/small, codestral, devstral, ministral, mistral-embed, codestral-embed, pixtral-large, … |
220
+ | Alibaba | 13 | qwen4-max, qwen3.8-max/flash/27b/2.4t-a95b, qwen3.5-plus, qwen3-max/plus/coder, qwen2.5-72b, … |
221
+ | Meta | 8 | muse-spark-open, muse-glimmer-30b, llama-4-scout/maverick, llama-3.3-70b, llama-3.1-405b/70b/8b |
222
+ | Zhipu | 8 | glm-5.3(-flashx/-flash), glm-5.2, glm-5, glm-4.7, glm-4.5(-air) |
223
+ | DeepSeek | 5 | deepseek-flash, deepseek-v4-pro, deepseek-v4-flash, deepseek-v3, deepseek-r1 |
224
+ | MiniMax | 6 | minimax-m3, minimax-m3.1-flash, minimax-m2.7/m2.5/m2.1/m2 |
225
+ | Moonshot | 6 | kimi-k3.1-pro(-highspeed), kimi-k3, kimi-k2.7-code, kimi-k2.6, kimi-k2.5 |
223
226
  | Voyage | 8 | voyage-4-large/4/4-lite/code-4, voyage-3-large, voyage-3.5(-lite), voyage-code-3 (embeddings) |
224
227
 
225
228
  The authoritative list is the code: call `allModels()` at runtime, or see
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": "4.1.2",
5
+ "version": "5.0.0",
6
6
  "license": "MIT OR Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -11,12 +11,6 @@ export class Encoding {
11
11
  private constructor();
12
12
  free(): void;
13
13
  [Symbol.dispose](): void;
14
- /**
15
- * Count tokens without building the full token id array.
16
- *
17
- * Faster than `encode(text).length` for cases where you only need the count.
18
- */
19
- count(text: string): number;
20
14
  /**
21
15
  * Count tokens, recognizing special tokens.
22
16
  *
@@ -25,18 +19,17 @@ export class Encoding {
25
19
  */
26
20
  countWithSpecialTokens(text: string): number;
27
21
  /**
28
- * Decode token ids back to a UTF-8 string.
22
+ * Count tokens without building the full token id array.
29
23
  *
30
- * Uses lossy UTF-8 conversion — invalid byte sequences are replaced with U+FFFD.
24
+ * Faster than `encode(text).length` for cases where you only need the count.
31
25
  */
32
- decode(tokens: Uint32Array): string;
26
+ count(text: string): number;
33
27
  /**
34
- * Encode text into token ids (returns `Uint32Array` in JS).
28
+ * Decode token ids back to a UTF-8 string.
35
29
  *
36
- * Special tokens like `<|endoftext|>` are treated as ordinary text.
37
- * Use `encodeWithSpecialTokens()` to recognize them.
30
+ * Uses lossy UTF-8 conversion — invalid byte sequences are replaced with U+FFFD.
38
31
  */
39
- encode(text: string): Uint32Array;
32
+ decode(tokens: Uint32Array | number[]): string;
40
33
  /**
41
34
  * Encode text into token ids, recognizing special tokens.
42
35
  *
@@ -44,6 +37,13 @@ export class Encoding {
44
37
  * instead of being split into sub-word pieces.
45
38
  */
46
39
  encodeWithSpecialTokens(text: string): Uint32Array;
40
+ /**
41
+ * Encode text into token ids (returns `Uint32Array` in JS).
42
+ *
43
+ * Special tokens like `<|endoftext|>` are treated as ordinary text.
44
+ * Use `encodeWithSpecialTokens()` to recognize them.
45
+ */
46
+ encode(text: string): Uint32Array;
47
47
  /**
48
48
  * Get the encoding name (e.g. `"cl100k_base"`).
49
49
  */
@@ -103,16 +103,20 @@ export function estimateCost(model_id: string, input_tokens: number, output_toke
103
103
  *
104
104
  * Supported encodings:
105
105
  * - `"cl100k_base"` — GPT-4, GPT-3.5-turbo
106
- * - `"o200k_base"` — GPT-4o, GPT-4.1, o1, o3
106
+ * - `"o200k_base"` — GPT-4o, GPT-4.1, GPT-5.x, GPT-6.x, o1, o3
107
107
  * - `"o200k_harmony"` — gpt-oss (harmony chat format)
108
108
  * - `"p50k_base"` — text-davinci-002/003
109
109
  * - `"p50k_edit"` — text-davinci-edit
110
110
  * - `"r50k_base"` — GPT-3 (davinci, curie, etc.)
111
111
  * - `"gpt2"` — GPT-2 (alias for r50k_base)
112
- * - `"llama3"` — Meta Llama 3/4
112
+ * - `"llama3"` — Meta Llama 3.x
113
+ * - `"llama4"` — Meta Llama 4, Muse
113
114
  * - `"deepseek_v3"` — DeepSeek V3/R1
114
115
  * - `"qwen2"` — Qwen 2/2.5/3
116
+ * - `"qwen3_5"` — Qwen 3.5–3.8
115
117
  * - `"mistral_v3"` — Mistral/Codestral/Pixtral
118
+ * - `"mistral_v15"` — Mistral Large 4
119
+ * - `"deepseek_v4"`, `"kimi_k2"`, `"kimi_k3"`, `"glm4"`, `"glm5"`, `"minimax_m2"`
116
120
  *
117
121
  * Throws `Error` for unknown encoding names.
118
122
  */
@@ -185,10 +189,14 @@ export interface InitOutput {
185
189
  readonly modelinfo_outputPer1m: (a: number) => number;
186
190
  readonly modelinfo_provider: (a: number, b: number) => void;
187
191
  readonly modelsByProvider: (a: number, b: number, c: number) => void;
192
+ readonly __wbindgen_externrefs: WebAssembly.Table;
188
193
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
189
- readonly __wbindgen_export: (a: number, b: number, c: number) => void;
190
- readonly __wbindgen_export2: (a: number, b: number) => number;
191
- readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
194
+ readonly __wbindgen_export: (a: number, b: number) => void;
195
+ readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
196
+ readonly __wbindgen_export3: (a: number, b: number) => number;
197
+ readonly __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
198
+ readonly __wbindgen_export5: (a: number) => void;
199
+ readonly __wbindgen_start: () => void;
192
200
  }
193
201
 
194
202
  export type SyncInitInput = BufferSource | WebAssembly.Module;
package/tiktoken_wasm.js CHANGED
@@ -24,45 +24,45 @@ export class Encoding {
24
24
  wasm.__wbg_encoding_free(ptr, 0);
25
25
  }
26
26
  /**
27
- * Count tokens without building the full token id array.
27
+ * Count tokens, recognizing special tokens.
28
28
  *
29
- * Faster than `encode(text).length` for cases where you only need the count.
29
+ * Like `count()` but special tokens (e.g. `<|endoftext|>`) are counted
30
+ * as single tokens instead of being split into sub-word pieces.
30
31
  * @param {string} text
31
32
  * @returns {number}
32
33
  */
33
- count(text) {
34
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
34
+ countWithSpecialTokens(text) {
35
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
35
36
  const len0 = WASM_VECTOR_LEN;
36
- const ret = wasm.encoding_count(this.__wbg_ptr, ptr0, len0);
37
+ const ret = wasm.encoding_countWithSpecialTokens(this.__wbg_ptr, ptr0, len0);
37
38
  return ret >>> 0;
38
39
  }
39
40
  /**
40
- * Count tokens, recognizing special tokens.
41
+ * Count tokens without building the full token id array.
41
42
  *
42
- * Like `count()` but special tokens (e.g. `<|endoftext|>`) are counted
43
- * as single tokens instead of being split into sub-word pieces.
43
+ * Faster than `encode(text).length` for cases where you only need the count.
44
44
  * @param {string} text
45
45
  * @returns {number}
46
46
  */
47
- countWithSpecialTokens(text) {
48
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
47
+ count(text) {
48
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
49
49
  const len0 = WASM_VECTOR_LEN;
50
- const ret = wasm.encoding_countWithSpecialTokens(this.__wbg_ptr, ptr0, len0);
50
+ const ret = wasm.encoding_count(this.__wbg_ptr, ptr0, len0);
51
51
  return ret >>> 0;
52
52
  }
53
53
  /**
54
54
  * Decode token ids back to a UTF-8 string.
55
55
  *
56
56
  * Uses lossy UTF-8 conversion — invalid byte sequences are replaced with U+FFFD.
57
- * @param {Uint32Array} tokens
57
+ * @param {Uint32Array | number[]} tokens
58
58
  * @returns {string}
59
59
  */
60
60
  decode(tokens) {
61
61
  let deferred2_0;
62
62
  let deferred2_1;
63
63
  try {
64
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
65
- const ptr0 = passArray32ToWasm0(tokens, wasm.__wbindgen_export2);
64
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
65
+ const ptr0 = passArray32ToWasm0(tokens, wasm.__wbindgen_export3);
66
66
  const len0 = WASM_VECTOR_LEN;
67
67
  wasm.encoding_decode(retptr, this.__wbg_ptr, ptr0, len0);
68
68
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -72,50 +72,50 @@ export class Encoding {
72
72
  return getStringFromWasm0(r0, r1);
73
73
  } finally {
74
74
  wasm.__wbindgen_add_to_stack_pointer(16);
75
- wasm.__wbindgen_export(deferred2_0, deferred2_1, 1);
75
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
76
76
  }
77
77
  }
78
78
  /**
79
- * Encode text into token ids (returns `Uint32Array` in JS).
79
+ * Encode text into token ids, recognizing special tokens.
80
80
  *
81
- * Special tokens like `<|endoftext|>` are treated as ordinary text.
82
- * Use `encodeWithSpecialTokens()` to recognize them.
81
+ * Special tokens (e.g. `<|endoftext|>`) are encoded as their designated ids
82
+ * instead of being split into sub-word pieces.
83
83
  * @param {string} text
84
84
  * @returns {Uint32Array}
85
85
  */
86
- encode(text) {
86
+ encodeWithSpecialTokens(text) {
87
87
  try {
88
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
89
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
88
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
89
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
90
90
  const len0 = WASM_VECTOR_LEN;
91
- wasm.encoding_encode(retptr, this.__wbg_ptr, ptr0, len0);
91
+ wasm.encoding_encodeWithSpecialTokens(retptr, this.__wbg_ptr, ptr0, len0);
92
92
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
93
93
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
94
94
  var v2 = getArrayU32FromWasm0(r0, r1).slice();
95
- wasm.__wbindgen_export(r0, r1 * 4, 4);
95
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
96
96
  return v2;
97
97
  } finally {
98
98
  wasm.__wbindgen_add_to_stack_pointer(16);
99
99
  }
100
100
  }
101
101
  /**
102
- * Encode text into token ids, recognizing special tokens.
102
+ * Encode text into token ids (returns `Uint32Array` in JS).
103
103
  *
104
- * Special tokens (e.g. `<|endoftext|>`) are encoded as their designated ids
105
- * instead of being split into sub-word pieces.
104
+ * Special tokens like `<|endoftext|>` are treated as ordinary text.
105
+ * Use `encodeWithSpecialTokens()` to recognize them.
106
106
  * @param {string} text
107
107
  * @returns {Uint32Array}
108
108
  */
109
- encodeWithSpecialTokens(text) {
109
+ encode(text) {
110
110
  try {
111
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
112
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
111
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
112
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
113
113
  const len0 = WASM_VECTOR_LEN;
114
- wasm.encoding_encodeWithSpecialTokens(retptr, this.__wbg_ptr, ptr0, len0);
114
+ wasm.encoding_encode(retptr, this.__wbg_ptr, ptr0, len0);
115
115
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
116
116
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
117
117
  var v2 = getArrayU32FromWasm0(r0, r1).slice();
118
- wasm.__wbindgen_export(r0, r1 * 4, 4);
118
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
119
119
  return v2;
120
120
  } finally {
121
121
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -129,7 +129,7 @@ export class Encoding {
129
129
  let deferred1_0;
130
130
  let deferred1_1;
131
131
  try {
132
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
132
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
133
133
  wasm.encoding_name(retptr, this.__wbg_ptr);
134
134
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
135
135
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
@@ -138,7 +138,7 @@ export class Encoding {
138
138
  return getStringFromWasm0(r0, r1);
139
139
  } finally {
140
140
  wasm.__wbindgen_add_to_stack_pointer(16);
141
- wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
141
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
142
142
  }
143
143
  }
144
144
  /**
@@ -185,7 +185,7 @@ export class ModelInfo {
185
185
  */
186
186
  get cachedInputPer1m() {
187
187
  try {
188
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
188
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
189
189
  wasm.modelinfo_cachedInputPer1m(retptr, this.__wbg_ptr);
190
190
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
191
191
  var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true);
@@ -208,7 +208,7 @@ export class ModelInfo {
208
208
  let deferred1_0;
209
209
  let deferred1_1;
210
210
  try {
211
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
211
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
212
212
  wasm.modelinfo_id(retptr, this.__wbg_ptr);
213
213
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
214
214
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
@@ -217,7 +217,7 @@ export class ModelInfo {
217
217
  return getStringFromWasm0(r0, r1);
218
218
  } finally {
219
219
  wasm.__wbindgen_add_to_stack_pointer(16);
220
- wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
220
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
221
221
  }
222
222
  }
223
223
  /**
@@ -248,7 +248,7 @@ export class ModelInfo {
248
248
  let deferred1_0;
249
249
  let deferred1_1;
250
250
  try {
251
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
251
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
252
252
  wasm.modelinfo_provider(retptr, this.__wbg_ptr);
253
253
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
254
254
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
@@ -257,7 +257,7 @@ export class ModelInfo {
257
257
  return getStringFromWasm0(r0, r1);
258
258
  } finally {
259
259
  wasm.__wbindgen_add_to_stack_pointer(16);
260
- wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
260
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
261
261
  }
262
262
  }
263
263
  }
@@ -271,12 +271,12 @@ if (Symbol.dispose) ModelInfo.prototype[Symbol.dispose] = ModelInfo.prototype.fr
271
271
  */
272
272
  export function allModels() {
273
273
  try {
274
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
274
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
275
275
  wasm.allModels(retptr);
276
276
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
277
277
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
278
278
  var v1 = getArrayJsValueFromWasm0(r0, r1);
279
- wasm.__wbindgen_export(r0, r1 * 4, 4);
279
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
280
280
  return v1;
281
281
  } finally {
282
282
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -294,15 +294,15 @@ export function allModels() {
294
294
  */
295
295
  export function encodingForModel(model) {
296
296
  try {
297
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
298
- const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
297
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
298
+ const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
299
299
  const len0 = WASM_VECTOR_LEN;
300
300
  wasm.encodingForModel(retptr, ptr0, len0);
301
301
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
302
302
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
303
303
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
304
304
  if (r2) {
305
- throw takeObject(r1);
305
+ throw takeFromExternrefTable0(r1);
306
306
  }
307
307
  return Encoding.__wrap(r0);
308
308
  } finally {
@@ -322,15 +322,17 @@ export function encodingForModel(model) {
322
322
  */
323
323
  export function estimateCost(model_id, input_tokens, output_tokens) {
324
324
  try {
325
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
326
- const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
325
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
326
+ const val2 = +input_tokens;
327
+ const val3 = +output_tokens;
328
+ const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
327
329
  const len0 = WASM_VECTOR_LEN;
328
- wasm.estimateCost(retptr, ptr0, len0, input_tokens, output_tokens);
330
+ wasm.estimateCost(retptr, ptr0, len0, val2, val3);
329
331
  var r0 = getDataViewMemory0().getFloat64(retptr + 8 * 0, true);
330
332
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
331
333
  var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
332
334
  if (r3) {
333
- throw takeObject(r2);
335
+ throw takeFromExternrefTable0(r2);
334
336
  }
335
337
  return r0;
336
338
  } finally {
@@ -343,16 +345,20 @@ export function estimateCost(model_id, input_tokens, output_tokens) {
343
345
  *
344
346
  * Supported encodings:
345
347
  * - `"cl100k_base"` — GPT-4, GPT-3.5-turbo
346
- * - `"o200k_base"` — GPT-4o, GPT-4.1, o1, o3
348
+ * - `"o200k_base"` — GPT-4o, GPT-4.1, GPT-5.x, GPT-6.x, o1, o3
347
349
  * - `"o200k_harmony"` — gpt-oss (harmony chat format)
348
350
  * - `"p50k_base"` — text-davinci-002/003
349
351
  * - `"p50k_edit"` — text-davinci-edit
350
352
  * - `"r50k_base"` — GPT-3 (davinci, curie, etc.)
351
353
  * - `"gpt2"` — GPT-2 (alias for r50k_base)
352
- * - `"llama3"` — Meta Llama 3/4
354
+ * - `"llama3"` — Meta Llama 3.x
355
+ * - `"llama4"` — Meta Llama 4, Muse
353
356
  * - `"deepseek_v3"` — DeepSeek V3/R1
354
357
  * - `"qwen2"` — Qwen 2/2.5/3
358
+ * - `"qwen3_5"` — Qwen 3.5–3.8
355
359
  * - `"mistral_v3"` — Mistral/Codestral/Pixtral
360
+ * - `"mistral_v15"` — Mistral Large 4
361
+ * - `"deepseek_v4"`, `"kimi_k2"`, `"kimi_k3"`, `"glm4"`, `"glm5"`, `"minimax_m2"`
356
362
  *
357
363
  * Throws `Error` for unknown encoding names.
358
364
  * @param {string} name
@@ -360,15 +366,15 @@ export function estimateCost(model_id, input_tokens, output_tokens) {
360
366
  */
361
367
  export function getEncoding(name) {
362
368
  try {
363
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
364
- const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
369
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
370
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
365
371
  const len0 = WASM_VECTOR_LEN;
366
372
  wasm.getEncoding(retptr, ptr0, len0);
367
373
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
368
374
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
369
375
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
370
376
  if (r2) {
371
- throw takeObject(r1);
377
+ throw takeFromExternrefTable0(r1);
372
378
  }
373
379
  return Encoding.__wrap(r0);
374
380
  } finally {
@@ -393,15 +399,15 @@ export function getEncoding(name) {
393
399
  */
394
400
  export function getModelInfo(model_id) {
395
401
  try {
396
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
397
- const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
402
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
403
+ const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
398
404
  const len0 = WASM_VECTOR_LEN;
399
405
  wasm.getModelInfo(retptr, ptr0, len0);
400
406
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
401
407
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
402
408
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
403
409
  if (r2) {
404
- throw takeObject(r1);
410
+ throw takeFromExternrefTable0(r1);
405
411
  }
406
412
  return ModelInfo.__wrap(r0);
407
413
  } finally {
@@ -417,12 +423,12 @@ export function getModelInfo(model_id) {
417
423
  */
418
424
  export function listEncodings() {
419
425
  try {
420
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
426
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
421
427
  wasm.listEncodings(retptr);
422
428
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
423
429
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
424
430
  var v1 = getArrayJsValueFromWasm0(r0, r1);
425
- wasm.__wbindgen_export(r0, r1 * 4, 4);
431
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
426
432
  return v1;
427
433
  } finally {
428
434
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -438,8 +444,8 @@ export function listEncodings() {
438
444
  */
439
445
  export function modelToEncoding(model) {
440
446
  try {
441
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
442
- const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
447
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
448
+ const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
443
449
  const len0 = WASM_VECTOR_LEN;
444
450
  wasm.modelToEncoding(retptr, ptr0, len0);
445
451
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -447,7 +453,7 @@ export function modelToEncoding(model) {
447
453
  let v2;
448
454
  if (r0 !== 0) {
449
455
  v2 = getStringFromWasm0(r0, r1);
450
- wasm.__wbindgen_export(r0, r1 * 1, 1);
456
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
451
457
  }
452
458
  return v2;
453
459
  } finally {
@@ -466,14 +472,14 @@ export function modelToEncoding(model) {
466
472
  */
467
473
  export function modelsByProvider(provider) {
468
474
  try {
469
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
470
- const ptr0 = passStringToWasm0(provider, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
475
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
476
+ const ptr0 = passStringToWasm0(provider, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
471
477
  const len0 = WASM_VECTOR_LEN;
472
478
  wasm.modelsByProvider(retptr, ptr0, len0);
473
479
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
474
480
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
475
481
  var v2 = getArrayJsValueFromWasm0(r0, r1);
476
- wasm.__wbindgen_export(r0, r1 * 4, 4);
482
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
477
483
  return v2;
478
484
  } finally {
479
485
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -482,21 +488,29 @@ export function modelsByProvider(provider) {
482
488
  function __wbg_get_imports() {
483
489
  const import0 = {
484
490
  __proto__: null,
485
- __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
491
+ __wbg_Error_208446807d0d1e30: function(arg0, arg1) {
486
492
  const ret = Error(getStringFromWasm0(arg0, arg1));
487
- return addHeapObject(ret);
493
+ return ret;
488
494
  },
489
- __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
495
+ __wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
490
496
  throw new Error(getStringFromWasm0(arg0, arg1));
491
497
  },
492
498
  __wbg_modelinfo_new: function(arg0) {
493
499
  const ret = ModelInfo.__wrap(arg0);
494
- return addHeapObject(ret);
500
+ return ret;
495
501
  },
496
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
502
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
497
503
  // Cast intrinsic for `Ref(String) -> Externref`.
498
504
  const ret = getStringFromWasm0(arg0, arg1);
499
- return addHeapObject(ret);
505
+ return ret;
506
+ },
507
+ __wbindgen_init_externref_table: function() {
508
+ const table = wasm.__wbindgen_externrefs;
509
+ table.set(0, undefined);
510
+ table.set(1024, undefined);
511
+ table.set(1025, null);
512
+ table.set(1026, true);
513
+ table.set(1027, false);
500
514
  },
501
515
  };
502
516
  return {
@@ -512,28 +526,14 @@ const ModelInfoFinalization = (typeof FinalizationRegistry === 'undefined')
512
526
  ? { register: () => {}, unregister: () => {} }
513
527
  : new FinalizationRegistry(ptr => wasm.__wbg_modelinfo_free(ptr, 1));
514
528
 
515
- function addHeapObject(obj) {
516
- if (heap_next === heap.length) heap.push(heap.length + 1);
517
- const idx = heap_next;
518
- heap_next = heap[idx];
519
-
520
- heap[idx] = obj;
521
- return idx;
522
- }
523
-
524
- function dropObject(idx) {
525
- if (idx < 1028) return;
526
- heap[idx] = heap_next;
527
- heap_next = idx;
528
- }
529
-
530
529
  function getArrayJsValueFromWasm0(ptr, len) {
531
530
  ptr = ptr >>> 0;
532
531
  const mem = getDataViewMemory0();
533
532
  const result = [];
534
533
  for (let i = ptr; i < ptr + 4 * len; i += 4) {
535
- result.push(takeObject(mem.getUint32(i, true)));
534
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
536
535
  }
536
+ wasm.__wbindgen_export(ptr, len);
537
537
  return result;
538
538
  }
539
539
 
@@ -551,7 +551,8 @@ function getDataViewMemory0() {
551
551
  }
552
552
 
553
553
  function getStringFromWasm0(ptr, len) {
554
- return decodeText(ptr >>> 0, len);
554
+ ptr = ptr >>> 0;
555
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
555
556
  }
556
557
 
557
558
  let cachedUint32ArrayMemory0 = null;
@@ -570,13 +571,6 @@ function getUint8ArrayMemory0() {
570
571
  return cachedUint8ArrayMemory0;
571
572
  }
572
573
 
573
- function getObject(idx) { return heap[idx]; }
574
-
575
- let heap = new Array(1024).fill(undefined);
576
- heap.push(undefined, null, true, false);
577
-
578
- let heap_next = heap.length;
579
-
580
574
  function passArray32ToWasm0(arg, malloc) {
581
575
  const ptr = malloc(arg.length * 4, 4) >>> 0;
582
576
  getUint32ArrayMemory0().set(arg, ptr / 4);
@@ -621,24 +615,24 @@ function passStringToWasm0(arg, malloc, realloc) {
621
615
  return ptr;
622
616
  }
623
617
 
624
- function takeObject(idx) {
625
- const ret = getObject(idx);
626
- dropObject(idx);
627
- return ret;
618
+ function takeFromExternrefTable0(idx) {
619
+ const value = wasm.__wbindgen_externrefs.get(idx);
620
+ wasm.__wbindgen_export5(idx);
621
+ return value;
628
622
  }
629
623
 
630
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
624
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
631
625
  cachedTextDecoder.decode();
632
626
  const MAX_SAFARI_DECODE_BYTES = 2146435072;
633
627
  let numBytesDecoded = 0;
634
- function decodeText(ptr, len) {
635
- numBytesDecoded += len;
628
+ function decodeText(bytes) {
629
+ numBytesDecoded += bytes.length;
636
630
  if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
637
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
631
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
638
632
  cachedTextDecoder.decode();
639
- numBytesDecoded = len;
633
+ numBytesDecoded = bytes.length;
640
634
  }
641
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
635
+ return cachedTextDecoder.decode(bytes);
642
636
  }
643
637
 
644
638
  const cachedTextEncoder = new TextEncoder();
@@ -664,6 +658,7 @@ function __wbg_finalize_init(instance, module) {
664
658
  cachedDataViewMemory0 = null;
665
659
  cachedUint32ArrayMemory0 = null;
666
660
  cachedUint8ArrayMemory0 = null;
661
+ wasm.__wbindgen_start();
667
662
  return wasm;
668
663
  }
669
664
 
@@ -726,9 +721,17 @@ function initSync(module) {
726
721
  return __wbg_finalize_init(instance, module);
727
722
  }
728
723
 
724
+ let __wbg_init_promise;
729
725
  async function __wbg_init(module_or_path) {
730
726
  if (wasm !== undefined) return wasm;
727
+ if (__wbg_init_promise === undefined) {
728
+ __wbg_init_promise = __wbg_init_once(module_or_path);
729
+ __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
730
+ }
731
+ return __wbg_init_promise;
732
+ }
731
733
 
734
+ async function __wbg_init_once(module_or_path) {
732
735
 
733
736
  if (module_or_path !== undefined) {
734
737
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
Binary file