poe-code 3.0.274 → 3.0.276

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "3.0.274",
3
+ "version": "3.0.276",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14185,12 +14185,28 @@ var DEFAULT_ENCODING = "cl100k_base";
14185
14185
  function createTokenizer(options = {}) {
14186
14186
  const encoding = options.encoding ?? DEFAULT_ENCODING;
14187
14187
  const tokenizer = get_encoding(encoding);
14188
- const utf8Decoder = new TextDecoder();
14189
14188
  const strictUtf8Decoder = new TextDecoder("utf-8", { fatal: true });
14190
14189
  const encode = (text4) => tokenizer.encode(text4);
14190
+ const normalizeDecodeTokens = (tokens) => {
14191
+ if (tokens instanceof Uint32Array) {
14192
+ return tokens;
14193
+ }
14194
+ const tokenArray = new Uint32Array(tokens.length);
14195
+ tokens.forEach((token, index) => {
14196
+ if (!Number.isFinite(token) || !Number.isInteger(token) || token < 0 || token > 4294967295) {
14197
+ throw new TypeError(`token id at index ${index} must be a finite non-negative integer.`);
14198
+ }
14199
+ tokenArray[index] = token;
14200
+ });
14201
+ return tokenArray;
14202
+ };
14191
14203
  const decode = (tokens) => {
14192
- const tokenArray = tokens instanceof Uint32Array ? tokens : Uint32Array.from(tokens);
14193
- return utf8Decoder.decode(tokenizer.decode(tokenArray));
14204
+ const tokenArray = normalizeDecodeTokens(tokens);
14205
+ try {
14206
+ return strictUtf8Decoder.decode(tokenizer.decode(tokenArray));
14207
+ } catch {
14208
+ throw new Error("Cannot decode tokens without corrupting UTF-8 text.");
14209
+ }
14194
14210
  };
14195
14211
  const count = (text4) => encode(text4).length;
14196
14212
  const truncate2 = (text4, tokenCount) => {