poe-code 3.0.274 → 3.0.275

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/dist/index.js CHANGED
@@ -100945,12 +100945,28 @@ import { get_encoding } from "tiktoken";
100945
100945
  function createTokenizer(options = {}) {
100946
100946
  const encoding = options.encoding ?? DEFAULT_ENCODING;
100947
100947
  const tokenizer = get_encoding(encoding);
100948
- const utf8Decoder = new TextDecoder();
100949
100948
  const strictUtf8Decoder = new TextDecoder("utf-8", { fatal: true });
100950
100949
  const encode = (text5) => tokenizer.encode(text5);
100950
+ const normalizeDecodeTokens = (tokens) => {
100951
+ if (tokens instanceof Uint32Array) {
100952
+ return tokens;
100953
+ }
100954
+ const tokenArray = new Uint32Array(tokens.length);
100955
+ tokens.forEach((token, index) => {
100956
+ if (!Number.isFinite(token) || !Number.isInteger(token) || token < 0 || token > 4294967295) {
100957
+ throw new TypeError(`token id at index ${index} must be a finite non-negative integer.`);
100958
+ }
100959
+ tokenArray[index] = token;
100960
+ });
100961
+ return tokenArray;
100962
+ };
100951
100963
  const decode = (tokens) => {
100952
- const tokenArray = tokens instanceof Uint32Array ? tokens : Uint32Array.from(tokens);
100953
- return utf8Decoder.decode(tokenizer.decode(tokenArray));
100964
+ const tokenArray = normalizeDecodeTokens(tokens);
100965
+ try {
100966
+ return strictUtf8Decoder.decode(tokenizer.decode(tokenArray));
100967
+ } catch {
100968
+ throw new Error("Cannot decode tokens without corrupting UTF-8 text.");
100969
+ }
100954
100970
  };
100955
100971
  const count = (text5) => encode(text5).length;
100956
100972
  const truncate4 = (text5, tokenCount) => {
@@ -136474,7 +136490,7 @@ var init_package2 = __esm({
136474
136490
  "package.json"() {
136475
136491
  package_default2 = {
136476
136492
  name: "poe-code",
136477
- version: "3.0.274",
136493
+ version: "3.0.275",
136478
136494
  description: "CLI tool to configure Poe API for developer workflows.",
136479
136495
  type: "module",
136480
136496
  main: "./dist/index.js",