@blockrun/clawrouter 0.12.316 → 0.12.318

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
@@ -571,6 +571,41 @@ Live per-model prices: [blockrun.ai/pricing](https://blockrun.ai/pricing) (agent
571
571
 
572
572
  ---
573
573
 
574
+ ### Shared model catalog
575
+
576
+ ClawRouter refreshes model metadata through `@blockrun/model-catalog`, pinned to
577
+ an immutable commit and bundled into the plugin. The active Base, Solana or
578
+ API-key gateway supplies live chat model IDs, prices and limits. A background
579
+ refresh at startup and every five minutes updates `/v1/models`, price estimates,
580
+ and the plugin's OpenClaw provider/allowlist and per-agent model caches. Newly discovered chat models become
581
+ explicit picker choices without rebuilding ClawRouter. OpenClaw must reload its
582
+ provider configuration to display a changed list; the proxy serves the updated
583
+ list immediately.
584
+
585
+ Restart an already-running proxy once after installing this integration. Reusing
586
+ an older external proxy cannot give that process the new refresh behavior.
587
+
588
+ The public picker policy defaults to
589
+ `https://raw.githubusercontent.com/BlockRunAI/model-catalog/main/dist/snapshot.v1.json`.
590
+ Set `BLOCKRUN_MODEL_CATALOG_URL` to another policy URL, or an empty string to use
591
+ the bundled policy with live gateway rows. Policy requests never receive the API
592
+ key; catalog redirects are refused. Each proxy owns its cache. Network failures
593
+ retain the last complete view, and offline startup retains the existing bundled
594
+ ClawRouter catalog. Invalid policy keeps the last good policy while valid gateway
595
+ rows can still refresh.
596
+
597
+ Existing aliases, curated legacy entries, virtual routes, free fallback order,
598
+ and Auto routing candidates remain product policy. Live rows update prices for
599
+ known models and add new chat choices; they do not promote a new model into Auto
600
+ or assume that a `coding` category proves structured tool support. Known
601
+ capability overrides remain in place. A gateway update cannot reclassify a pinned
602
+ `free/` choice as paid. Models absent from a later refresh lose newly discovered
603
+ picker entries; legacy pinned IDs remain available for gateway redirects.
604
+
605
+ This integrates metadata, not payment signing or upstream protocol support.
606
+ New protocols still require gateway compatibility. Gateway payment quotes and
607
+ account settlement remain authoritative; catalog prices are estimates.
608
+
574
609
  ## Payment
575
610
 
576
611
  Two rails. This section covers the wallet one; the card/API-key one is
@@ -967,6 +1002,14 @@ wallet, no key, no signup. See [Paying with a credit card](#paying-with-a-credit
967
1002
 
968
1003
  ClawRouter itself is free and MIT licensed. You pay only for the LLM API calls routed through it — and several open-weight models (`nemotron-3.5-lightning`, `laguna-xs-2.1`, `north-mini-code`, `nemotron-3.5-bolt`, `nemotron-3-nano-omni-30b-a3b-reasoning`, `nemotron-3-super-120b`, `nemotron-3-ultra-550b`, `muse-glimmer-30b`) are completely free, and Bolt also reads images. Use `/model free` for the free default, or pick any by name.
969
1004
 
1005
+ ## Thanks
1006
+
1007
+ Thanks to [@Tyagiquamar](https://github.com/Tyagiquamar) for a run of careful fixes:
1008
+ SSRF guard hardening for IPv6 link-local and IPv4-embedded addresses (#534, #547),
1009
+ a `/stats` window fallback for invalid day counts (#535), prerelease-aware semver
1010
+ comparison in the updater (#617), and full-content deduplication in the
1011
+ observation compression layer (#621).
1012
+
970
1013
  ---
971
1014
 
972
1015
  <div align="center">
@@ -976,38 +1019,3 @@ ClawRouter itself is free and MIT licensed. You pay only for the LLM API calls r
976
1019
  ⭐ If ClawRouter powers your agents, consider starring the repo!
977
1020
 
978
1021
  </div>
979
-
980
- ### Shared model catalog
981
-
982
- ClawRouter refreshes model metadata through `@blockrun/model-catalog`, pinned to
983
- an immutable commit and bundled into the plugin. The active Base, Solana or
984
- API-key gateway supplies live chat model IDs, prices and limits. A background
985
- refresh at startup and every five minutes updates `/v1/models`, price estimates,
986
- and the plugin's OpenClaw provider/allowlist and per-agent model caches. Newly discovered chat models become
987
- explicit picker choices without rebuilding ClawRouter. OpenClaw must reload its
988
- provider configuration to display a changed list; the proxy serves the updated
989
- list immediately.
990
-
991
- Restart an already-running proxy once after installing this integration. Reusing
992
- an older external proxy cannot give that process the new refresh behavior.
993
-
994
- The public picker policy defaults to
995
- `https://raw.githubusercontent.com/BlockRunAI/model-catalog/main/dist/snapshot.v1.json`.
996
- Set `BLOCKRUN_MODEL_CATALOG_URL` to another policy URL, or an empty string to use
997
- the bundled policy with live gateway rows. Policy requests never receive the API
998
- key; catalog redirects are refused. Each proxy owns its cache. Network failures
999
- retain the last complete view, and offline startup retains the existing bundled
1000
- ClawRouter catalog. Invalid policy keeps the last good policy while valid gateway
1001
- rows can still refresh.
1002
-
1003
- Existing aliases, curated legacy entries, virtual routes, free fallback order,
1004
- and Auto routing candidates remain product policy. Live rows update prices for
1005
- known models and add new chat choices; they do not promote a new model into Auto
1006
- or assume that a `coding` category proves structured tool support. Known
1007
- capability overrides remain in place. A gateway update cannot reclassify a pinned
1008
- `free/` choice as paid. Models absent from a later refresh lose newly discovered
1009
- picker entries; legacy pinned IDs remain available for gateway redirects.
1010
-
1011
- This integrates metadata, not payment signing or upstream protocol support.
1012
- New protocols still require gateway compatibility. Gateway payment quotes and
1013
- account settlement remain authoritative; catalog prices are estimates.
package/dist/cli.js CHANGED
@@ -10048,6 +10048,25 @@ var init_models = __esm({
10048
10048
  }
10049
10049
  });
10050
10050
 
10051
+ // src/platform-fee.ts
10052
+ function validPercent(value) {
10053
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
10054
+ }
10055
+ function platformFeePercentOf(row) {
10056
+ if (row.billing_mode !== "paid") return 0;
10057
+ const pricing = row.pricing && typeof row.pricing === "object" ? row.pricing : void 0;
10058
+ return validPercent(pricing?.platform_fee_percent) ?? validPercent(row.platform_fee_percent) ?? 0;
10059
+ }
10060
+ function withPlatformFee(tokenCostUsd, platformFeePercent) {
10061
+ const percent = validPercent(platformFeePercent) ?? 0;
10062
+ return tokenCostUsd * (1 + percent / 100);
10063
+ }
10064
+ var init_platform_fee = __esm({
10065
+ "src/platform-fee.ts"() {
10066
+ "use strict";
10067
+ }
10068
+ });
10069
+
10051
10070
  // src/model-catalog.ts
10052
10071
  function fallbackCatalog() {
10053
10072
  return {
@@ -10098,7 +10117,10 @@ function projectClawCatalog(state) {
10098
10117
  model.outputPrice = row.billing_mode === "paid" ? row.pricing.output : 0;
10099
10118
  delete model.promo;
10100
10119
  delete model.flatPrice;
10120
+ delete model.platformFeePercent;
10101
10121
  if (row.billing_mode === "flat") model.flatPrice = row.pricing.flat;
10122
+ const feePercent = platformFeePercentOf(row);
10123
+ if (feePercent > 0) model.platformFeePercent = feePercent;
10102
10124
  if (row.context_window) model.contextWindow = row.context_window;
10103
10125
  if (row.max_output) model.maxOutput = row.max_output;
10104
10126
  if (!old) {
@@ -10180,6 +10202,7 @@ function fingerprint(view) {
10180
10202
  m.inputPrice,
10181
10203
  m.outputPrice,
10182
10204
  m.flatPrice ?? null,
10205
+ m.platformFeePercent ?? 0,
10183
10206
  m.contextWindow,
10184
10207
  m.maxOutput
10185
10208
  ]),
@@ -10193,6 +10216,7 @@ var init_model_catalog = __esm({
10193
10216
  init_runtime();
10194
10217
  init_api_key();
10195
10218
  init_models();
10219
+ init_platform_fee();
10196
10220
  }
10197
10221
  });
10198
10222
 
@@ -60319,14 +60343,30 @@ function cloneLimits(limits) {
60319
60343
  }
60320
60344
  return clone2;
60321
60345
  }
60322
- function recordKey(r2) {
60323
- return r2.id ?? `${r2.timestamp}|${r2.amount}|${r2.model ?? ""}|${r2.action ?? ""}`;
60324
- }
60325
60346
  function mergeSpendHistory(a, b) {
60326
- const byKey = /* @__PURE__ */ new Map();
60327
- for (const r2 of a) byKey.set(recordKey(r2), r2);
60328
- for (const r2 of b) if (!byKey.has(recordKey(r2))) byKey.set(recordKey(r2), r2);
60329
- return [...byKey.values()].sort((x, y) => x.timestamp - y.timestamp);
60347
+ const merged = [];
60348
+ const ids = /* @__PURE__ */ new Set();
60349
+ const legacyKept = /* @__PURE__ */ new Map();
60350
+ for (const ledger2 of [a, b]) {
60351
+ const legacySeen = /* @__PURE__ */ new Map();
60352
+ for (const r2 of ledger2) {
60353
+ if (r2.id !== void 0) {
60354
+ if (!ids.has(r2.id)) {
60355
+ ids.add(r2.id);
60356
+ merged.push(r2);
60357
+ }
60358
+ continue;
60359
+ }
60360
+ const key3 = `${r2.timestamp}|${r2.amount}|${r2.model ?? ""}|${r2.action ?? ""}`;
60361
+ const nth = (legacySeen.get(key3) ?? 0) + 1;
60362
+ legacySeen.set(key3, nth);
60363
+ if (nth > (legacyKept.get(key3) ?? 0)) {
60364
+ legacyKept.set(key3, nth);
60365
+ merged.push(r2);
60366
+ }
60367
+ }
60368
+ }
60369
+ return merged.sort((x, y) => x.timestamp - y.timestamp);
60330
60370
  }
60331
60371
  function canonicalLimits(limits) {
60332
60372
  return JSON.stringify(
@@ -91184,7 +91224,7 @@ function deduplicateLargeBlocks(messages) {
91184
91224
  if (!msg.content || typeof msg.content !== "string" || msg.content.length < 500) {
91185
91225
  return msg;
91186
91226
  }
91187
- const blockKey = msg.content.slice(0, 200);
91227
+ const blockKey = msg.content;
91188
91228
  if (blockHashes.has(blockKey)) {
91189
91229
  const firstIdx = blockHashes.get(blockKey);
91190
91230
  const original = msg.content;
@@ -91788,12 +91828,19 @@ var init_session = __esm({
91788
91828
  });
91789
91829
 
91790
91830
  // src/updater.ts
91831
+ function versionCore(version31) {
91832
+ const core = version31.split(/[+-]/, 1)[0] ?? "";
91833
+ return core.split(".").map((part) => {
91834
+ const value = Number(part);
91835
+ return Number.isFinite(value) ? value : 0;
91836
+ });
91837
+ }
91791
91838
  function compareSemver(a, b) {
91792
- const pa = a.split(".").map(Number);
91793
- const pb = b.split(".").map(Number);
91839
+ const pa = versionCore(a);
91840
+ const pb = versionCore(b);
91794
91841
  for (let i = 0; i < 3; i++) {
91795
- if ((pa[i] || 0) > (pb[i] || 0)) return 1;
91796
- if ((pa[i] || 0) < (pb[i] || 0)) return -1;
91842
+ if ((pa[i] ?? 0) > (pb[i] ?? 0)) return 1;
91843
+ if ((pa[i] ?? 0) < (pb[i] ?? 0)) return -1;
91797
91844
  }
91798
91845
  return 0;
91799
91846
  }
@@ -157333,7 +157380,10 @@ function estimateAmount(modelId, bodyLength, maxTokens, models = BLOCKRUN_MODEL_
157333
157380
  } else {
157334
157381
  const estimatedInputTokens = Math.ceil(bodyLength / 4);
157335
157382
  const estimatedOutputTokens = maxTokens || model.maxOutput || 4096;
157336
- costUsd = estimatedInputTokens / 1e6 * model.inputPrice + estimatedOutputTokens / 1e6 * model.outputPrice;
157383
+ costUsd = withPlatformFee(
157384
+ estimatedInputTokens / 1e6 * model.inputPrice + estimatedOutputTokens / 1e6 * model.outputPrice,
157385
+ model.platformFeePercent
157386
+ );
157337
157387
  }
157338
157388
  if (costUsd > 0) costUsd += 1e-3;
157339
157389
  const amountMicros = Math.max(1e3, Math.ceil(costUsd * 1.2 * 1e6));
@@ -161741,7 +161791,10 @@ data: [DONE]
161741
161791
  } else if (apiKeyPricing) {
161742
161792
  const inTokens = responseInputTokens ?? chargedInputTokens;
161743
161793
  const outTokens = responseOutputTokens ?? 0;
161744
- logCost2 = (inTokens * (apiKeyPricing.inputPrice ?? 0) + outTokens * (apiKeyPricing.outputPrice ?? 0)) / 1e6;
161794
+ logCost2 = withPlatformFee(
161795
+ (inTokens * (apiKeyPricing.inputPrice ?? 0) + outTokens * (apiKeyPricing.outputPrice ?? 0)) / 1e6,
161796
+ modelsById.get(logModel)?.platformFeePercent
161797
+ );
161745
161798
  logSavings = costs.baselineCost > 0 ? Math.max(0, (costs.baselineCost - logCost2) / costs.baselineCost) : 0;
161746
161799
  } else {
161747
161800
  logCost2 = costs.costEstimate;
@@ -161783,6 +161836,7 @@ var init_proxy = __esm({
161783
161836
  init_router();
161784
161837
  init_models();
161785
161838
  init_max_tokens();
161839
+ init_platform_fee();
161786
161840
  init_logger();
161787
161841
  init_stats();
161788
161842
  init_dedup();
@@ -312730,6 +312784,16 @@ var init_redeem = __esm({
312730
312784
  }
312731
312785
  });
312732
312786
 
312787
+ // src/polymarket/units.ts
312788
+ function usdToBaseUnits(usd2, decimals) {
312789
+ return BigInt(Math.round(usd2 * 10 ** decimals));
312790
+ }
312791
+ var init_units = __esm({
312792
+ "src/polymarket/units.ts"() {
312793
+ "use strict";
312794
+ }
312795
+ });
312796
+
312733
312797
  // src/polymarket/withdraw.ts
312734
312798
  async function rawPusdBalance(owner) {
312735
312799
  return getPublicClient().readContract({
@@ -312762,7 +312826,7 @@ async function withdrawFunds(input2, deps) {
312762
312826
  isError: true
312763
312827
  };
312764
312828
  }
312765
- const amountRaw = input2.amount_usd !== void 0 ? BigInt(Math.floor(input2.amount_usd * 10 ** PUSD_DECIMALS)) : balanceRaw;
312829
+ const amountRaw = input2.amount_usd !== void 0 ? usdToBaseUnits(input2.amount_usd, PUSD_DECIMALS) : balanceRaw;
312766
312830
  if (amountRaw > balanceRaw) {
312767
312831
  return {
312768
312832
  text: `Requested $${input2.amount_usd} exceeds the pUSD balance of $${balanceUsd.toFixed(2)}.`,
@@ -312885,6 +312949,7 @@ var init_withdraw = __esm({
312885
312949
  init_relayer();
312886
312950
  init_setup();
312887
312951
  init_spend_policy();
312952
+ init_units();
312888
312953
  }
312889
312954
  });
312890
312955
 
@@ -312956,7 +313021,7 @@ async function fundVault(input2, deps) {
312956
313021
  };
312957
313022
  }
312958
313023
  const privateKey = getOrCreateWalletKey();
312959
- const amountMicro = String(Math.floor(amountUsd * 10 ** USDC_DECIMALS));
313024
+ const amountMicro = String(usdToBaseUnits(amountUsd, USDC_DECIMALS));
312960
313025
  const network = `eip155:${BASE_CHAIN_ID3}`;
312961
313026
  const depositAuthorization = await signUnderSpendPolicy(
312962
313027
  deps,
@@ -313013,6 +313078,7 @@ var init_fund = __esm({
313013
313078
  init_positions();
313014
313079
  init_setup();
313015
313080
  init_spend_policy();
313081
+ init_units();
313016
313082
  FUND_FEE_USD = 0.01;
313017
313083
  USDC_DECIMALS = 6;
313018
313084
  FUND_MIN_USD = Number(process.env.POLYMARKET_FUND_MIN_USD || "2");
package/dist/index.d.ts CHANGED
@@ -422,6 +422,13 @@ type BlockRunModel = {
422
422
  * Unlike promo, this never expires. Takes precedence over promo.
423
423
  */
424
424
  flatPrice?: number;
425
+ /**
426
+ * Platform fee percent the gateway adds to this model's per-token cost
427
+ * (`platform_fee_percent` on its `/v1/models` row; see platform-fee.ts).
428
+ * Set only from a live catalog; absent means 0. The bundled list below never
429
+ * carries it, so the fee is never a number typed here.
430
+ */
431
+ platformFeePercent?: number;
425
432
  };
426
433
  declare const BLOCKRUN_MODELS: BlockRunModel[];
427
434
  /**
package/dist/index.js CHANGED
@@ -278216,6 +278216,20 @@ var HINTS = {
278216
278216
  404: `api.blockrun.ai does not serve this endpoint. Chat, Anthropic-shaped messages, images, speech, video and the partner APIs (Exa, prediction markets, phone lookup) all work on an API key. The wallet-only exceptions are the routes that bind a lease or a position to a payer address \u2014 buying/renewing/releasing phone numbers, and Polymarket trading \u2014 which need a wallet to own the thing being bought. For those, unset BLOCKRUN_API_KEY and run "clawrouter logout".`
278217
278217
  };
278218
278218
 
278219
+ // src/platform-fee.ts
278220
+ function validPercent(value) {
278221
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
278222
+ }
278223
+ function platformFeePercentOf(row) {
278224
+ if (row.billing_mode !== "paid") return 0;
278225
+ const pricing = row.pricing && typeof row.pricing === "object" ? row.pricing : void 0;
278226
+ return validPercent(pricing?.platform_fee_percent) ?? validPercent(row.platform_fee_percent) ?? 0;
278227
+ }
278228
+ function withPlatformFee(tokenCostUsd, platformFeePercent) {
278229
+ const percent = validPercent(platformFeePercent) ?? 0;
278230
+ return tokenCostUsd * (1 + percent / 100);
278231
+ }
278232
+
278219
278233
  // src/model-catalog.ts
278220
278234
  function fallbackCatalog() {
278221
278235
  return {
@@ -278266,7 +278280,10 @@ function projectClawCatalog(state) {
278266
278280
  model.outputPrice = row.billing_mode === "paid" ? row.pricing.output : 0;
278267
278281
  delete model.promo;
278268
278282
  delete model.flatPrice;
278283
+ delete model.platformFeePercent;
278269
278284
  if (row.billing_mode === "flat") model.flatPrice = row.pricing.flat;
278285
+ const feePercent = platformFeePercentOf(row);
278286
+ if (feePercent > 0) model.platformFeePercent = feePercent;
278270
278287
  if (row.context_window) model.contextWindow = row.context_window;
278271
278288
  if (row.max_output) model.maxOutput = row.max_output;
278272
278289
  if (!old) {
@@ -278348,6 +278365,7 @@ function fingerprint(view) {
278348
278365
  m.inputPrice,
278349
278366
  m.outputPrice,
278350
278367
  m.flatPrice ?? null,
278368
+ m.platformFeePercent ?? 0,
278351
278369
  m.contextWindow,
278352
278370
  m.maxOutput
278353
278371
  ]),
@@ -282618,14 +282636,30 @@ function cloneLimits(limits) {
282618
282636
  }
282619
282637
  return clone2;
282620
282638
  }
282621
- function recordKey(r2) {
282622
- return r2.id ?? `${r2.timestamp}|${r2.amount}|${r2.model ?? ""}|${r2.action ?? ""}`;
282623
- }
282624
282639
  function mergeSpendHistory(a, b) {
282625
- const byKey = /* @__PURE__ */ new Map();
282626
- for (const r2 of a) byKey.set(recordKey(r2), r2);
282627
- for (const r2 of b) if (!byKey.has(recordKey(r2))) byKey.set(recordKey(r2), r2);
282628
- return [...byKey.values()].sort((x, y) => x.timestamp - y.timestamp);
282640
+ const merged = [];
282641
+ const ids = /* @__PURE__ */ new Set();
282642
+ const legacyKept = /* @__PURE__ */ new Map();
282643
+ for (const ledger2 of [a, b]) {
282644
+ const legacySeen = /* @__PURE__ */ new Map();
282645
+ for (const r2 of ledger2) {
282646
+ if (r2.id !== void 0) {
282647
+ if (!ids.has(r2.id)) {
282648
+ ids.add(r2.id);
282649
+ merged.push(r2);
282650
+ }
282651
+ continue;
282652
+ }
282653
+ const key3 = `${r2.timestamp}|${r2.amount}|${r2.model ?? ""}|${r2.action ?? ""}`;
282654
+ const nth = (legacySeen.get(key3) ?? 0) + 1;
282655
+ legacySeen.set(key3, nth);
282656
+ if (nth > (legacyKept.get(key3) ?? 0)) {
282657
+ legacyKept.set(key3, nth);
282658
+ merged.push(r2);
282659
+ }
282660
+ }
282661
+ }
282662
+ return merged.sort((x, y) => x.timestamp - y.timestamp);
282629
282663
  }
282630
282664
  function canonicalLimits(limits) {
282631
282665
  return JSON.stringify(
@@ -290656,7 +290690,7 @@ function deduplicateLargeBlocks(messages) {
290656
290690
  if (!msg.content || typeof msg.content !== "string" || msg.content.length < 500) {
290657
290691
  return msg;
290658
290692
  }
290659
- const blockKey = msg.content.slice(0, 200);
290693
+ const blockKey = msg.content;
290660
290694
  if (blockHashes.has(blockKey)) {
290661
290695
  const firstIdx = blockHashes.get(blockKey);
290662
290696
  const original = msg.content;
@@ -291226,12 +291260,19 @@ function hashRequestContent(lastUserContent, toolCallNames) {
291226
291260
  // src/updater.ts
291227
291261
  var NPM_REGISTRY = "https://registry.npmjs.org/@blockrun/clawrouter/latest";
291228
291262
  var CHECK_TIMEOUT_MS = 5e3;
291263
+ function versionCore(version31) {
291264
+ const core = version31.split(/[+-]/, 1)[0] ?? "";
291265
+ return core.split(".").map((part) => {
291266
+ const value = Number(part);
291267
+ return Number.isFinite(value) ? value : 0;
291268
+ });
291269
+ }
291229
291270
  function compareSemver(a, b) {
291230
- const pa = a.split(".").map(Number);
291231
- const pb = b.split(".").map(Number);
291271
+ const pa = versionCore(a);
291272
+ const pb = versionCore(b);
291232
291273
  for (let i = 0; i < 3; i++) {
291233
- if ((pa[i] || 0) > (pb[i] || 0)) return 1;
291234
- if ((pa[i] || 0) < (pb[i] || 0)) return -1;
291274
+ if ((pa[i] ?? 0) > (pb[i] ?? 0)) return 1;
291275
+ if ((pa[i] ?? 0) < (pb[i] ?? 0)) return -1;
291235
291276
  }
291236
291277
  return 0;
291237
291278
  }
@@ -293542,7 +293583,10 @@ function estimateAmount(modelId, bodyLength, maxTokens, models = BLOCKRUN_MODEL_
293542
293583
  } else {
293543
293584
  const estimatedInputTokens = Math.ceil(bodyLength / 4);
293544
293585
  const estimatedOutputTokens = maxTokens || model.maxOutput || 4096;
293545
- costUsd = estimatedInputTokens / 1e6 * model.inputPrice + estimatedOutputTokens / 1e6 * model.outputPrice;
293586
+ costUsd = withPlatformFee(
293587
+ estimatedInputTokens / 1e6 * model.inputPrice + estimatedOutputTokens / 1e6 * model.outputPrice,
293588
+ model.platformFeePercent
293589
+ );
293546
293590
  }
293547
293591
  if (costUsd > 0) costUsd += 1e-3;
293548
293592
  const amountMicros = Math.max(1e3, Math.ceil(costUsd * 1.2 * 1e6));
@@ -298090,7 +298134,10 @@ data: [DONE]
298090
298134
  } else if (apiKeyPricing) {
298091
298135
  const inTokens = responseInputTokens ?? chargedInputTokens;
298092
298136
  const outTokens = responseOutputTokens ?? 0;
298093
- logCost2 = (inTokens * (apiKeyPricing.inputPrice ?? 0) + outTokens * (apiKeyPricing.outputPrice ?? 0)) / 1e6;
298137
+ logCost2 = withPlatformFee(
298138
+ (inTokens * (apiKeyPricing.inputPrice ?? 0) + outTokens * (apiKeyPricing.outputPrice ?? 0)) / 1e6,
298139
+ modelsById.get(logModel)?.platformFeePercent
298140
+ );
298094
298141
  logSavings = costs.baselineCost > 0 ? Math.max(0, (costs.baselineCost - logCost2) / costs.baselineCost) : 0;
298095
298142
  } else {
298096
298143
  logCost2 = costs.costEstimate;
@@ -309784,6 +309831,11 @@ async function redeemPosition(input2, deps) {
309784
309831
  }
309785
309832
  }
309786
309833
 
309834
+ // src/polymarket/units.ts
309835
+ function usdToBaseUnits(usd, decimals) {
309836
+ return BigInt(Math.round(usd * 10 ** decimals));
309837
+ }
309838
+
309787
309839
  // src/polymarket/withdraw.ts
309788
309840
  async function rawPusdBalance(owner) {
309789
309841
  return getPublicClient().readContract({
@@ -309816,7 +309868,7 @@ async function withdrawFunds(input2, deps) {
309816
309868
  isError: true
309817
309869
  };
309818
309870
  }
309819
- const amountRaw = input2.amount_usd !== void 0 ? BigInt(Math.floor(input2.amount_usd * 10 ** PUSD_DECIMALS)) : balanceRaw;
309871
+ const amountRaw = input2.amount_usd !== void 0 ? usdToBaseUnits(input2.amount_usd, PUSD_DECIMALS) : balanceRaw;
309820
309872
  if (amountRaw > balanceRaw) {
309821
309873
  return {
309822
309874
  text: `Requested $${input2.amount_usd} exceeds the pUSD balance of $${balanceUsd.toFixed(2)}.`,
@@ -309999,7 +310051,7 @@ async function fundVault(input2, deps) {
309999
310051
  };
310000
310052
  }
310001
310053
  const privateKey = getOrCreateWalletKey();
310002
- const amountMicro = String(Math.floor(amountUsd * 10 ** USDC_DECIMALS));
310054
+ const amountMicro = String(usdToBaseUnits(amountUsd, USDC_DECIMALS));
310003
310055
  const network = `eip155:${BASE_CHAIN_ID3}`;
310004
310056
  const depositAuthorization = await signUnderSpendPolicy(
310005
310057
  deps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/clawrouter",
3
- "version": "0.12.316",
3
+ "version": "0.12.318",
4
4
  "description": "Smart LLM router — save 84% on inference costs. 91 models (8 free). Pay by credit card (API key) or USDC (x402 wallet).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",