mtok-relay 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/mtok-relay.mjs +44 -25
  2. package/package.json +1 -1
@@ -2016,14 +2016,14 @@ function weierstrass(curveDef) {
2016
2016
  const sg = signature;
2017
2017
  msgHash = ensureBytes("msgHash", msgHash);
2018
2018
  publicKey = ensureBytes("publicKey", publicKey);
2019
- const { lowS, prehash, format } = opts;
2019
+ const { lowS, prehash, format: format2 } = opts;
2020
2020
  validateSigVerOpts(opts);
2021
2021
  if ("strict" in opts)
2022
2022
  throw new Error("options.strict was renamed to lowS");
2023
- if (format !== void 0 && format !== "compact" && format !== "der")
2023
+ if (format2 !== void 0 && format2 !== "compact" && format2 !== "der")
2024
2024
  throw new Error("format must be compact or der");
2025
2025
  const isHex2 = typeof sg === "string" || isBytes2(sg);
2026
- const isObj = !isHex2 && !format && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
2026
+ const isObj = !isHex2 && !format2 && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
2027
2027
  if (!isHex2 && !isObj)
2028
2028
  throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
2029
2029
  let _sig = void 0;
@@ -2033,13 +2033,13 @@ function weierstrass(curveDef) {
2033
2033
  _sig = new Signature(sg.r, sg.s);
2034
2034
  if (isHex2) {
2035
2035
  try {
2036
- if (format !== "compact")
2036
+ if (format2 !== "compact")
2037
2037
  _sig = Signature.fromDER(sg);
2038
2038
  } catch (derError) {
2039
2039
  if (!(derError instanceof DER.Err))
2040
2040
  throw derError;
2041
2041
  }
2042
- if (!_sig && format !== "der")
2042
+ if (!_sig && format2 !== "der")
2043
2043
  _sig = Signature.fromCompact(sg);
2044
2044
  }
2045
2045
  P = Point.fromHex(publicKey);
@@ -2157,7 +2157,7 @@ var secp256k1 = createCurve({
2157
2157
  }, sha256);
2158
2158
 
2159
2159
  // node_modules/viem/_esm/errors/version.js
2160
- var version = "2.55.1";
2160
+ var version = "2.55.10";
2161
2161
 
2162
2162
  // node_modules/viem/_esm/errors/base.js
2163
2163
  var errorConfig = {
@@ -3215,14 +3215,17 @@ async function signMessage({ message, privateKey }) {
3215
3215
  return await sign({ hash: hashMessage(message), privateKey, to: "hex" });
3216
3216
  }
3217
3217
 
3218
- // node_modules/viem/_esm/constants/unit.js
3219
- var gweiUnits = {
3220
- ether: -9,
3221
- wei: 9
3218
+ // node_modules/viem/_esm/utils/unit/Value.js
3219
+ var exponents = {
3220
+ wei: 0,
3221
+ gwei: 9,
3222
+ szabo: 12,
3223
+ finney: 15,
3224
+ ether: 18
3222
3225
  };
3223
-
3224
- // node_modules/viem/_esm/utils/unit/formatUnits.js
3225
- function formatUnits(value, decimals) {
3226
+ function format(value, decimals = 0) {
3227
+ if (!Number.isInteger(decimals) || decimals < 0)
3228
+ throw new InvalidDecimalsError({ decimals });
3226
3229
  let display = value.toString();
3227
3230
  const negative = display.startsWith("-");
3228
3231
  if (negative)
@@ -3235,10 +3238,24 @@ function formatUnits(value, decimals) {
3235
3238
  fraction = fraction.replace(/(0+)$/, "");
3236
3239
  return `${negative ? "-" : ""}${integer || "0"}${fraction ? `.${fraction}` : ""}`;
3237
3240
  }
3241
+ function formatGwei(wei, unit = "wei") {
3242
+ return format(wei, exponents.gwei - exponents[unit]);
3243
+ }
3244
+ var InvalidDecimalsError = class extends Error {
3245
+ constructor({ decimals }) {
3246
+ super(`\`decimals\` must be a non-negative integer. Got \`${decimals}\`.`);
3247
+ Object.defineProperty(this, "name", {
3248
+ enumerable: true,
3249
+ configurable: true,
3250
+ writable: true,
3251
+ value: "Value.InvalidDecimalsError"
3252
+ });
3253
+ }
3254
+ };
3238
3255
 
3239
3256
  // node_modules/viem/_esm/utils/unit/formatGwei.js
3240
- function formatGwei(wei, unit = "wei") {
3241
- return formatUnits(wei, gweiUnits[unit]);
3257
+ function formatGwei2(wei, unit = "wei") {
3258
+ return formatGwei(wei, unit);
3242
3259
  }
3243
3260
 
3244
3261
  // node_modules/viem/_esm/errors/transaction.js
@@ -3591,7 +3608,7 @@ Object.defineProperty(ExecutionRevertedError, "nodeMessage", {
3591
3608
  });
3592
3609
  var FeeCapTooHighError = class extends BaseError {
3593
3610
  constructor({ cause, maxFeePerGas } = {}) {
3594
- super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`, {
3611
+ super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei2(maxFeePerGas)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`, {
3595
3612
  cause,
3596
3613
  name: "FeeCapTooHighError"
3597
3614
  });
@@ -3605,7 +3622,7 @@ Object.defineProperty(FeeCapTooHighError, "nodeMessage", {
3605
3622
  });
3606
3623
  var FeeCapTooLowError = class extends BaseError {
3607
3624
  constructor({ cause, maxFeePerGas } = {}) {
3608
- super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)}` : ""} gwei) cannot be lower than the block base fee.`, {
3625
+ super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei2(maxFeePerGas)}` : ""} gwei) cannot be lower than the block base fee.`, {
3609
3626
  cause,
3610
3627
  name: "FeeCapTooLowError"
3611
3628
  });
@@ -3724,7 +3741,7 @@ Object.defineProperty(TransactionTypeNotSupportedError, "nodeMessage", {
3724
3741
  var TipAboveFeeCapError = class extends BaseError {
3725
3742
  constructor({ cause, maxPriorityFeePerGas, maxFeePerGas } = {}) {
3726
3743
  super([
3727
- `The provided tip (\`maxPriorityFeePerGas\`${maxPriorityFeePerGas ? ` = ${formatGwei(maxPriorityFeePerGas)} gwei` : ""}) cannot be higher than the fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}).`
3744
+ `The provided tip (\`maxPriorityFeePerGas\`${maxPriorityFeePerGas ? ` = ${formatGwei2(maxPriorityFeePerGas)} gwei` : ""}) cannot be higher than the fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei2(maxFeePerGas)} gwei` : ""}).`
3728
3745
  ].join("\n"), {
3729
3746
  cause,
3730
3747
  name: "TipAboveFeeCapError"
@@ -5267,8 +5284,8 @@ function validateRequest(request, model, { legacy = false } = {}) {
5267
5284
  }
5268
5285
  let validResponseFormat = false;
5269
5286
  if (request.response_format != null) {
5270
- const format = request.response_format;
5271
- validResponseFormat = !!format && typeof format === "object" && !Array.isArray(format) && Object.keys(format).length === 1 && ["json_object", "text"].includes(format.type);
5287
+ const format2 = request.response_format;
5288
+ validResponseFormat = !!format2 && typeof format2 === "object" && !Array.isArray(format2) && Object.keys(format2).length === 1 && ["json_object", "text"].includes(format2.type);
5272
5289
  if (!legacy && !validResponseFormat) {
5273
5290
  return { error: 'response_format must be exactly { type: "json_object" } or { type: "text" }' };
5274
5291
  }
@@ -5293,15 +5310,17 @@ function configuredFeeAtomic({ sellerUsdAtomic, feeAddress, feeBps }) {
5293
5310
  return (BigInt(sellerUsdAtomic || 0) * bps + 5000n) / 10000n;
5294
5311
  }
5295
5312
  var MESSAGE_OVERHEAD_TOKENS = 4;
5313
+ var BYTES_PER_TOKEN_EST = 3.2;
5296
5314
  function estimateInputTokens(messages) {
5297
5315
  const utf8 = new TextEncoder();
5298
- let tokens = 3;
5316
+ let bytes = 0;
5317
+ let envelope = 3;
5299
5318
  for (const m of messages ?? []) {
5300
- tokens += MESSAGE_OVERHEAD_TOKENS;
5301
- tokens += utf8.encode(String(m?.role ?? "")).length;
5302
- tokens += utf8.encode(typeof m?.content === "string" ? m.content : JSON.stringify(m?.content ?? null)).length;
5319
+ envelope += MESSAGE_OVERHEAD_TOKENS;
5320
+ bytes += utf8.encode(String(m?.role ?? "")).length;
5321
+ bytes += utf8.encode(typeof m?.content === "string" ? m.content : JSON.stringify(m?.content ?? null)).length;
5303
5322
  }
5304
- return tokens;
5323
+ return envelope + Math.ceil(bytes / BYTES_PER_TOKEN_EST);
5305
5324
  }
5306
5325
  function boundServe({ messages, budgetUsd, inPrice, outPrice, reqMax, contextCeil = 4096 }) {
5307
5326
  const estIn = estimateInputTokens(messages);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mtok-relay",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Reference seller relay for mtok.market — accepts on-chain-prepaid chunk draws and serves inference from an upstream you control.",
5
5
  "type": "module",
6
6
  "bin": {