@blockrun/clawrouter 0.12.297 → 0.12.299

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
@@ -37680,7 +37680,7 @@ var require_websocket = __commonJS({
37680
37680
  var net3 = __require("net");
37681
37681
  var tls2 = __require("tls");
37682
37682
  var { randomBytes: randomBytes9, createHash: createHash6 } = __require("crypto");
37683
- var { Duplex, Readable: Readable3 } = __require("stream");
37683
+ var { Duplex, Readable: Readable4 } = __require("stream");
37684
37684
  var { URL: URL3 } = __require("url");
37685
37685
  var PerMessageDeflate2 = require_permessage_deflate();
37686
37686
  var Receiver2 = require_receiver();
@@ -76444,13 +76444,13 @@ var require_util2 = __commonJS({
76444
76444
  function TAOCheck() {
76445
76445
  return "success";
76446
76446
  }
76447
- function appendFetchMetadata(httpRequest) {
76448
- if (!isURLPotentiallyTrustworthy(requestCurrentURL(httpRequest))) {
76447
+ function appendFetchMetadata(httpRequest2) {
76448
+ if (!isURLPotentiallyTrustworthy(requestCurrentURL(httpRequest2))) {
76449
76449
  return;
76450
76450
  }
76451
76451
  let header = null;
76452
- header = httpRequest.mode;
76453
- httpRequest.headersList.set("sec-fetch-mode", header, true);
76452
+ header = httpRequest2.mode;
76453
+ httpRequest2.headersList.set("sec-fetch-mode", header, true);
76454
76454
  }
76455
76455
  function appendRequestOriginHeader(request2) {
76456
76456
  let serializedOrigin = request2.origin;
@@ -88329,7 +88329,7 @@ var require_readable = __commonJS({
88329
88329
  "use strict";
88330
88330
  var assert10 = __require("assert");
88331
88331
  var { addAbortListener } = __require("events");
88332
- var { Readable: Readable3 } = __require("stream");
88332
+ var { Readable: Readable4 } = __require("stream");
88333
88333
  var { RequestAbortedError, NotSupportedError, InvalidArgumentError, AbortError } = require_errors();
88334
88334
  var util5 = require_util();
88335
88335
  var kConsume = /* @__PURE__ */ Symbol("kConsume");
@@ -88342,7 +88342,7 @@ var require_readable = __commonJS({
88342
88342
  var kBytesRead = /* @__PURE__ */ Symbol("kBytesRead");
88343
88343
  var noop2 = () => {
88344
88344
  };
88345
- var BodyReadable = class extends Readable3 {
88345
+ var BodyReadable = class extends Readable4 {
88346
88346
  /**
88347
88347
  * @param {object} opts
88348
88348
  * @param {(this: Readable, size: number) => void} opts.resume
@@ -88741,7 +88741,7 @@ var require_api_request = __commonJS({
88741
88741
  "use strict";
88742
88742
  var assert10 = __require("assert");
88743
88743
  var { AsyncResource } = __require("async_hooks");
88744
- var { Readable: Readable3 } = require_readable();
88744
+ var { Readable: Readable4 } = require_readable();
88745
88745
  var { InvalidArgumentError, RequestAbortedError } = require_errors();
88746
88746
  var util5 = require_util();
88747
88747
  function noop2() {
@@ -88827,7 +88827,7 @@ var require_api_request = __commonJS({
88827
88827
  const parsedHeaders = headers;
88828
88828
  const contentType = parsedHeaders?.["content-type"];
88829
88829
  const contentLength = parsedHeaders?.["content-length"];
88830
- const res = new Readable3({
88830
+ const res = new Readable4({
88831
88831
  resume: () => controller.resume(),
88832
88832
  abort: (reason) => controller.abort(reason),
88833
88833
  contentType,
@@ -89203,7 +89203,7 @@ var require_api_pipeline = __commonJS({
89203
89203
  "node_modules/undici/lib/api/api-pipeline.js"(exports, module) {
89204
89204
  "use strict";
89205
89205
  var {
89206
- Readable: Readable3,
89206
+ Readable: Readable4,
89207
89207
  Duplex,
89208
89208
  PassThrough
89209
89209
  } = __require("stream");
@@ -89220,7 +89220,7 @@ var require_api_pipeline = __commonJS({
89220
89220
  function noop2() {
89221
89221
  }
89222
89222
  var kResume = /* @__PURE__ */ Symbol("resume");
89223
- var PipelineRequest = class extends Readable3 {
89223
+ var PipelineRequest = class extends Readable4 {
89224
89224
  constructor() {
89225
89225
  super({ autoDestroy: true });
89226
89226
  this[kResume] = null;
@@ -89238,7 +89238,7 @@ var require_api_pipeline = __commonJS({
89238
89238
  callback(err);
89239
89239
  }
89240
89240
  };
89241
- var PipelineResponse = class extends Readable3 {
89241
+ var PipelineResponse = class extends Readable4 {
89242
89242
  constructor(resume2) {
89243
89243
  super({ autoDestroy: true });
89244
89244
  this[kResume] = resume2;
@@ -92292,7 +92292,7 @@ var require_dump = __commonJS({
92292
92292
  var require_dns = __commonJS({
92293
92293
  "node_modules/undici/lib/interceptor/dns.js"(exports, module) {
92294
92294
  "use strict";
92295
- var { isIP: isIP2 } = __require("net");
92295
+ var { isIP: isIP3 } = __require("net");
92296
92296
  var { lookup } = __require("dns");
92297
92297
  var DecoratorHandler = require_decorator_handler();
92298
92298
  var { InvalidArgumentError, InformationalError } = require_errors();
@@ -92709,7 +92709,7 @@ var require_dns = __commonJS({
92709
92709
  return dispatch(origDispatchOpts, handler);
92710
92710
  }
92711
92711
  const origin2 = origDispatchOpts.origin.constructor === URL ? origDispatchOpts.origin : new URL(origDispatchOpts.origin);
92712
- if (isIP2(origin2.hostname) !== 0) {
92712
+ if (isIP3(origin2.hostname) !== 0) {
92713
92713
  return dispatch(origDispatchOpts, handler);
92714
92714
  }
92715
92715
  instance.runLookup(origin2, origDispatchOpts, (err, newOrigin) => {
@@ -94780,7 +94780,7 @@ var require_cache2 = __commonJS({
94780
94780
  "node_modules/undici/lib/interceptor/cache.js"(exports, module) {
94781
94781
  "use strict";
94782
94782
  var assert10 = __require("assert");
94783
- var { Readable: Readable3 } = __require("stream");
94783
+ var { Readable: Readable4 } = __require("stream");
94784
94784
  var util5 = require_util();
94785
94785
  var CacheHandler = require_cache_handler();
94786
94786
  var MemoryCacheStore = require_memory_cache_store();
@@ -94976,7 +94976,7 @@ var require_cache2 = __commonJS({
94976
94976
  return dispatch(opts, new CacheHandler(globalOpts, cacheKey3, handler));
94977
94977
  }
94978
94978
  function sendCachedValue(handler, opts, result, age, context, isStale2) {
94979
- const stream4 = util5.isStream(result.body) ? result.body : Readable3.from(result.body ?? []);
94979
+ const stream4 = util5.isStream(result.body) ? result.body : Readable4.from(result.body ?? []);
94980
94980
  assert10(!stream4.destroyed, "stream should not be destroyed");
94981
94981
  assert10(!stream4.readableDidRead, "stream should not be readableDidRead");
94982
94982
  let aborted = false;
@@ -98441,7 +98441,7 @@ var require_fetch = __commonJS({
98441
98441
  subresourceSet
98442
98442
  } = require_constants3();
98443
98443
  var EE = __require("events");
98444
- var { Readable: Readable3, pipeline: pipeline2, finished: finished2, isErrored, isReadable } = __require("stream");
98444
+ var { Readable: Readable4, pipeline: pipeline2, finished: finished2, isErrored, isReadable } = __require("stream");
98445
98445
  var { addAbortListener, bufferToLowerCasedHeaderName } = require_util();
98446
98446
  var { SocketError } = require_errors();
98447
98447
  var { dataURLProcessor, serializeAMimeType, minimizeSupportedMimeType } = require_data_url();
@@ -99070,90 +99070,90 @@ var require_fetch = __commonJS({
99070
99070
  async function httpNetworkOrCacheFetch(fetchParams, isAuthenticationFetch = false, isNewConnectionFetch = false) {
99071
99071
  const request2 = fetchParams.request;
99072
99072
  let httpFetchParams = null;
99073
- let httpRequest = null;
99073
+ let httpRequest2 = null;
99074
99074
  let response = null;
99075
99075
  const httpCache = null;
99076
99076
  const revalidatingFlag = false;
99077
99077
  if (request2.window === "no-window" && request2.redirect === "error") {
99078
99078
  httpFetchParams = fetchParams;
99079
- httpRequest = request2;
99079
+ httpRequest2 = request2;
99080
99080
  } else {
99081
99081
  if (request2.body?.source != null) {
99082
- httpRequest = cloneRequest(request2);
99082
+ httpRequest2 = cloneRequest(request2);
99083
99083
  } else {
99084
- httpRequest = cloneRequest({ ...request2, body: null });
99085
- httpRequest.body = request2.body;
99084
+ httpRequest2 = cloneRequest({ ...request2, body: null });
99085
+ httpRequest2.body = request2.body;
99086
99086
  }
99087
99087
  httpFetchParams = { ...fetchParams };
99088
- httpFetchParams.request = httpRequest;
99088
+ httpFetchParams.request = httpRequest2;
99089
99089
  }
99090
99090
  const includeCredentials = request2.credentials === "include" || request2.credentials === "same-origin" && request2.responseTainting === "basic";
99091
- const contentLength = httpRequest.body ? httpRequest.body.length : null;
99091
+ const contentLength = httpRequest2.body ? httpRequest2.body.length : null;
99092
99092
  let contentLengthHeaderValue = null;
99093
- if (httpRequest.body == null && ["POST", "PUT"].includes(httpRequest.method)) {
99093
+ if (httpRequest2.body == null && ["POST", "PUT"].includes(httpRequest2.method)) {
99094
99094
  contentLengthHeaderValue = "0";
99095
99095
  }
99096
99096
  if (contentLength != null) {
99097
99097
  contentLengthHeaderValue = isomorphicEncode(`${contentLength}`);
99098
99098
  }
99099
- if (contentLengthHeaderValue != null && !httpRequest.headersList.contains("content-length", true)) {
99100
- httpRequest.headersList.append("content-length", contentLengthHeaderValue, true);
99099
+ if (contentLengthHeaderValue != null && !httpRequest2.headersList.contains("content-length", true)) {
99100
+ httpRequest2.headersList.append("content-length", contentLengthHeaderValue, true);
99101
99101
  }
99102
- if (contentLength != null && httpRequest.keepalive) {
99102
+ if (contentLength != null && httpRequest2.keepalive) {
99103
99103
  }
99104
- if (webidl.is.URL(httpRequest.referrer)) {
99105
- httpRequest.headersList.append("referer", isomorphicEncode(httpRequest.referrer.href), true);
99104
+ if (webidl.is.URL(httpRequest2.referrer)) {
99105
+ httpRequest2.headersList.append("referer", isomorphicEncode(httpRequest2.referrer.href), true);
99106
99106
  }
99107
- appendRequestOriginHeader(httpRequest);
99108
- appendFetchMetadata(httpRequest);
99109
- if (!httpRequest.headersList.contains("user-agent", true)) {
99110
- httpRequest.headersList.append("user-agent", defaultUserAgent, true);
99107
+ appendRequestOriginHeader(httpRequest2);
99108
+ appendFetchMetadata(httpRequest2);
99109
+ if (!httpRequest2.headersList.contains("user-agent", true)) {
99110
+ httpRequest2.headersList.append("user-agent", defaultUserAgent, true);
99111
99111
  }
99112
- if (httpRequest.cache === "default" && (httpRequest.headersList.contains("if-modified-since", true) || httpRequest.headersList.contains("if-none-match", true) || httpRequest.headersList.contains("if-unmodified-since", true) || httpRequest.headersList.contains("if-match", true) || httpRequest.headersList.contains("if-range", true))) {
99113
- httpRequest.cache = "no-store";
99112
+ if (httpRequest2.cache === "default" && (httpRequest2.headersList.contains("if-modified-since", true) || httpRequest2.headersList.contains("if-none-match", true) || httpRequest2.headersList.contains("if-unmodified-since", true) || httpRequest2.headersList.contains("if-match", true) || httpRequest2.headersList.contains("if-range", true))) {
99113
+ httpRequest2.cache = "no-store";
99114
99114
  }
99115
- if (httpRequest.cache === "no-cache" && !httpRequest.preventNoCacheCacheControlHeaderModification && !httpRequest.headersList.contains("cache-control", true)) {
99116
- httpRequest.headersList.append("cache-control", "max-age=0", true);
99115
+ if (httpRequest2.cache === "no-cache" && !httpRequest2.preventNoCacheCacheControlHeaderModification && !httpRequest2.headersList.contains("cache-control", true)) {
99116
+ httpRequest2.headersList.append("cache-control", "max-age=0", true);
99117
99117
  }
99118
- if (httpRequest.cache === "no-store" || httpRequest.cache === "reload") {
99119
- if (!httpRequest.headersList.contains("pragma", true)) {
99120
- httpRequest.headersList.append("pragma", "no-cache", true);
99118
+ if (httpRequest2.cache === "no-store" || httpRequest2.cache === "reload") {
99119
+ if (!httpRequest2.headersList.contains("pragma", true)) {
99120
+ httpRequest2.headersList.append("pragma", "no-cache", true);
99121
99121
  }
99122
- if (!httpRequest.headersList.contains("cache-control", true)) {
99123
- httpRequest.headersList.append("cache-control", "no-cache", true);
99122
+ if (!httpRequest2.headersList.contains("cache-control", true)) {
99123
+ httpRequest2.headersList.append("cache-control", "no-cache", true);
99124
99124
  }
99125
99125
  }
99126
- if (httpRequest.headersList.contains("range", true)) {
99127
- httpRequest.headersList.append("accept-encoding", "identity", true);
99126
+ if (httpRequest2.headersList.contains("range", true)) {
99127
+ httpRequest2.headersList.append("accept-encoding", "identity", true);
99128
99128
  }
99129
- if (!httpRequest.headersList.contains("accept-encoding", true)) {
99130
- if (urlHasHttpsScheme(requestCurrentURL(httpRequest))) {
99131
- httpRequest.headersList.append("accept-encoding", "br, gzip, deflate, zstd", true);
99129
+ if (!httpRequest2.headersList.contains("accept-encoding", true)) {
99130
+ if (urlHasHttpsScheme(requestCurrentURL(httpRequest2))) {
99131
+ httpRequest2.headersList.append("accept-encoding", "br, gzip, deflate, zstd", true);
99132
99132
  } else {
99133
- httpRequest.headersList.append("accept-encoding", "gzip, deflate", true);
99133
+ httpRequest2.headersList.append("accept-encoding", "gzip, deflate", true);
99134
99134
  }
99135
99135
  }
99136
- httpRequest.headersList.delete("host", true);
99136
+ httpRequest2.headersList.delete("host", true);
99137
99137
  if (includeCredentials) {
99138
- if (!httpRequest.headersList.contains("authorization", true)) {
99138
+ if (!httpRequest2.headersList.contains("authorization", true)) {
99139
99139
  let authorizationValue = null;
99140
- if (hasAuthenticationEntry(httpRequest) && (httpRequest.useURLCredentials === void 0 || !includesCredentials(requestCurrentURL(httpRequest)))) {
99141
- } else if (includesCredentials(requestCurrentURL(httpRequest)) && isAuthenticationFetch) {
99142
- const { username, password } = requestCurrentURL(httpRequest);
99140
+ if (hasAuthenticationEntry(httpRequest2) && (httpRequest2.useURLCredentials === void 0 || !includesCredentials(requestCurrentURL(httpRequest2)))) {
99141
+ } else if (includesCredentials(requestCurrentURL(httpRequest2)) && isAuthenticationFetch) {
99142
+ const { username, password } = requestCurrentURL(httpRequest2);
99143
99143
  authorizationValue = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
99144
99144
  }
99145
99145
  if (authorizationValue !== null) {
99146
- httpRequest.headersList.append("Authorization", authorizationValue, false);
99146
+ httpRequest2.headersList.append("Authorization", authorizationValue, false);
99147
99147
  }
99148
99148
  }
99149
99149
  }
99150
99150
  if (httpCache == null) {
99151
- httpRequest.cache = "no-store";
99151
+ httpRequest2.cache = "no-store";
99152
99152
  }
99153
- if (httpRequest.cache !== "no-store" && httpRequest.cache !== "reload") {
99153
+ if (httpRequest2.cache !== "no-store" && httpRequest2.cache !== "reload") {
99154
99154
  }
99155
99155
  if (response == null) {
99156
- if (httpRequest.cache === "only-if-cached") {
99156
+ if (httpRequest2.cache === "only-if-cached") {
99157
99157
  return makeNetworkError("only if cached");
99158
99158
  }
99159
99159
  const forwardResponse = await httpNetworkFetch(
@@ -99161,7 +99161,7 @@ var require_fetch = __commonJS({
99161
99161
  includeCredentials,
99162
99162
  isNewConnectionFetch
99163
99163
  );
99164
- if (!safeMethodsSet.has(httpRequest.method) && forwardResponse.status >= 200 && forwardResponse.status <= 399) {
99164
+ if (!safeMethodsSet.has(httpRequest2.method) && forwardResponse.status >= 200 && forwardResponse.status <= 399) {
99165
99165
  }
99166
99166
  if (revalidatingFlag && forwardResponse.status === 304) {
99167
99167
  }
@@ -99169,12 +99169,12 @@ var require_fetch = __commonJS({
99169
99169
  response = forwardResponse;
99170
99170
  }
99171
99171
  }
99172
- response.urlList = [...httpRequest.urlList];
99173
- if (httpRequest.headersList.contains("range", true)) {
99172
+ response.urlList = [...httpRequest2.urlList];
99173
+ if (httpRequest2.headersList.contains("range", true)) {
99174
99174
  response.rangeRequested = true;
99175
99175
  }
99176
99176
  response.requestIncludesCredentials = includeCredentials;
99177
- if (response.status === 401 && httpRequest.responseTainting !== "cors" && includeCredentials && (request2.useURLCredentials !== void 0 || isTraversableNavigable(request2.traversableForUserPrompts))) {
99177
+ if (response.status === 401 && httpRequest2.responseTainting !== "cors" && includeCredentials && (request2.useURLCredentials !== void 0 || isTraversableNavigable(request2.traversableForUserPrompts))) {
99178
99178
  if (request2.body != null) {
99179
99179
  if (request2.body.source == null) {
99180
99180
  return response;
@@ -99471,7 +99471,7 @@ var require_fetch = __commonJS({
99471
99471
  }
99472
99472
  }
99473
99473
  }
99474
- this.body = new Readable3({ read: () => controller.resume() });
99474
+ this.body = new Readable4({ read: () => controller.resume() });
99475
99475
  const onError = (err) => this.onResponseError(controller, err);
99476
99476
  resolve2({
99477
99477
  status: status2,
@@ -243215,7 +243215,7 @@ async function explainApiKeyFailure(response) {
243215
243215
  var HINTS = {
243216
243216
  401: `Check BLOCKRUN_API_KEY, or mint a new key at ${PORTAL_KEYS_URL}.`,
243217
243217
  402: `Top up your BlockRun credit at ${PORTAL_CREDITS_URL}.`,
243218
- 404: `api.blockrun.ai does not serve this endpoint. Chat, Anthropic-shaped messages, images, speech, video and the partner APIs (Surf, 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".`
243218
+ 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".`
243219
243219
  };
243220
243220
 
243221
243221
  // src/model-catalog.ts
@@ -243362,7 +243362,7 @@ function fingerprint(view) {
243362
243362
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
243363
243363
  import { createHmac } from "crypto";
243364
243364
  import { createServer } from "http";
243365
- import { finished, Readable } from "stream";
243365
+ import { finished, Readable as Readable2 } from "stream";
243366
243366
  import { pipeline } from "stream/promises";
243367
243367
  import { homedir as homedir13 } from "os";
243368
243368
  import { join as join17 } from "path";
@@ -263515,6 +263515,11 @@ ${lines.join("\n")}`;
263515
263515
  };
263516
263516
 
263517
263517
  // src/local-guard.ts
263518
+ import { request as httpRequest } from "http";
263519
+ import { request as httpsRequest } from "https";
263520
+ import { lookup as dnsLookup } from "dns/promises";
263521
+ import { isIP } from "net";
263522
+ import { Readable } from "stream";
263518
263523
  import { closeSync as closeSync3, fstatSync as fstatSync2, openSync as openSync3, readSync as readSync2, realpathSync } from "fs";
263519
263524
  import { homedir as homedir11 } from "os";
263520
263525
  import { join as join15 } from "path";
@@ -263592,18 +263597,86 @@ function isBlockedSsrfHost(hostname) {
263592
263597
  }
263593
263598
  return false;
263594
263599
  }
263600
+ var systemResolver = (hostname) => dnsLookup(hostname, { all: true, verbatim: true });
263601
+ async function resolvePublicAddresses(hostname, resolve2 = systemResolver) {
263602
+ const h = hostname.replace(/^\[/, "").replace(/\]$/, "");
263603
+ const family = isIP(h);
263604
+ const addrs = family ? [{ address: h, family }] : await resolve2(h);
263605
+ if (addrs.length === 0) throw new Error(`could not resolve ${hostname}`);
263606
+ const blocked = addrs.find((a) => isBlockedSsrfHost(a.address));
263607
+ if (blocked) {
263608
+ throw new Error(
263609
+ `refusing to fetch ${hostname}: it resolves to a private/loopback/metadata address (${blocked.address})`
263610
+ );
263611
+ }
263612
+ return addrs;
263613
+ }
263614
+ function pinnedLookup(addrs) {
263615
+ return (_hostname, options, callback) => {
263616
+ if (options.all) {
263617
+ callback(null, addrs);
263618
+ } else {
263619
+ callback(null, addrs[0].address, addrs[0].family);
263620
+ }
263621
+ };
263622
+ }
263623
+ var NULL_BODY_STATUSES = /* @__PURE__ */ new Set([101, 103, 204, 205, 304]);
263624
+ function pinnedFetch(url2, addrs, init2 = {}) {
263625
+ const method = (init2.method ?? "GET").toUpperCase();
263626
+ const body = init2.body;
263627
+ if (body != null && typeof body !== "string" && !(body instanceof Uint8Array)) {
263628
+ return Promise.reject(new TypeError("pinnedFetch supports only string or byte bodies"));
263629
+ }
263630
+ const headers = Object.fromEntries(new Headers(init2.headers));
263631
+ const send = url2.protocol === "https:" ? httpsRequest : httpRequest;
263632
+ return new Promise((resolve2, reject) => {
263633
+ const req = send(
263634
+ url2,
263635
+ { method, headers, lookup: pinnedLookup(addrs), signal: init2.signal ?? void 0 },
263636
+ (res) => {
263637
+ const status2 = res.statusCode ?? 0;
263638
+ if (status2 < 200 || status2 > 599) {
263639
+ res.destroy();
263640
+ reject(new Error(`unexpected HTTP status ${status2} from ${url2.host}`));
263641
+ return;
263642
+ }
263643
+ const resHeaders = new Headers();
263644
+ for (let i = 0; i + 1 < res.rawHeaders.length; i += 2) {
263645
+ resHeaders.append(res.rawHeaders[i], res.rawHeaders[i + 1]);
263646
+ }
263647
+ const noBody = method === "HEAD" || NULL_BODY_STATUSES.has(status2);
263648
+ if (noBody) res.resume();
263649
+ resolve2(
263650
+ new Response(noBody ? null : Readable.toWeb(res), {
263651
+ status: status2,
263652
+ statusText: res.statusMessage,
263653
+ headers: resHeaders
263654
+ })
263655
+ );
263656
+ }
263657
+ );
263658
+ req.on("error", reject);
263659
+ req.end(body ?? void 0);
263660
+ });
263661
+ }
263595
263662
  async function ssrfSafeFetch(url2, init2 = {}, maxHops = 5) {
263596
- const { allowPrivate, ...fetchInit } = init2;
263663
+ const { allowPrivate, viaUpstreamProxy, resolve: resolve2, ...fetchInit } = init2;
263597
263664
  let current = url2;
263598
263665
  for (let hop = 0; hop <= maxHops; hop++) {
263599
263666
  const u = new URL(current);
263600
263667
  if (u.protocol !== "http:" && u.protocol !== "https:") {
263601
263668
  throw new Error(`refusing to fetch non-http(s) URL (${u.protocol})`);
263602
263669
  }
263603
- if (!allowPrivate && isBlockedSsrfHost(u.hostname)) {
263604
- throw new Error(`refusing to fetch a private/loopback/metadata address: ${u.hostname}`);
263670
+ let res;
263671
+ if (allowPrivate) {
263672
+ res = await fetch(current, { ...fetchInit, redirect: "manual" });
263673
+ } else {
263674
+ if (isBlockedSsrfHost(u.hostname)) {
263675
+ throw new Error(`refusing to fetch a private/loopback/metadata address: ${u.hostname}`);
263676
+ }
263677
+ const addrs = await resolvePublicAddresses(u.hostname, resolve2);
263678
+ res = viaUpstreamProxy ? await fetch(current, { ...fetchInit, redirect: "manual" }) : await pinnedFetch(u, addrs, fetchInit);
263605
263679
  }
263606
- const res = await fetch(current, { ...fetchInit, redirect: "manual" });
263607
263680
  if (res.status >= 300 && res.status < 400) {
263608
263681
  const loc = res.headers.get("location");
263609
263682
  if (!loc) return res;
@@ -265580,8 +265653,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
265580
265653
  const isBlockrunExa = req.url?.startsWith("/v1/exa/") ?? false;
265581
265654
  const isModalSandbox = req.url?.startsWith("/v1/modal/") ?? false;
265582
265655
  const isPhone = (req.url?.startsWith("/v1/phone/") ?? false) || (req.url?.startsWith("/v1/voice/") ?? false);
265583
- const isSurf = req.url?.startsWith("/v1/surf/") ?? false;
265584
- const requestLabel = isBlockrunExa ? "BlockRun Exa" : isModalSandbox ? "Modal Sandbox" : isPhone ? "Phone/Voice" : isSurf ? "Surf" : "Partner";
265656
+ const requestLabel = isBlockrunExa ? "BlockRun Exa" : isModalSandbox ? "Modal Sandbox" : isPhone ? "Phone/Voice" : "Partner";
265585
265657
  const bodyChunks = [];
265586
265658
  for await (const chunk of req) {
265587
265659
  bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
@@ -265621,7 +265693,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
265621
265693
  if (accountPassthrough) {
265622
265694
  if (upstream.body) {
265623
265695
  await pipeline(
265624
- Readable.fromWeb(upstream.body),
265696
+ Readable2.fromWeb(upstream.body),
265625
265697
  res,
265626
265698
  { signal: clientAbort.signal }
265627
265699
  );
@@ -265652,14 +265724,14 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
265652
265724
  logUsage({
265653
265725
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
265654
265726
  ...blockrunRequestId(upstream) ? { requestId: blockrunRequestId(upstream) } : {},
265655
- model: isBlockrunExa ? "blockrun-exa" : isModalSandbox ? "modal-sandbox" : isPhone ? (req.url ?? "").replace(/^\/v1\//, "").split("?")[0] : isSurf ? (req.url ?? "").replace(/^\/v1\//, "").split("?")[0] : "partner",
265656
- tier: isPhone ? "PHONE" : isSurf ? "SURF" : "PARTNER",
265727
+ model: isBlockrunExa ? "blockrun-exa" : isModalSandbox ? "modal-sandbox" : isPhone ? (req.url ?? "").replace(/^\/v1\//, "").split("?")[0] : "partner",
265728
+ tier: isPhone ? "PHONE" : "PARTNER",
265657
265729
  cost: requestCost,
265658
265730
  baselineCost: requestCost,
265659
265731
  savings: 0,
265660
265732
  latencyMs,
265661
265733
  partnerId: (req.url?.split("?")[0] ?? "").replace(/^\/v1\//, "").replace(/\//g, "_") || "unknown",
265662
- service: isBlockrunExa ? "web_search" : isModalSandbox ? "modal" : isPhone ? "phone" : isSurf ? "surf" : "partner"
265734
+ service: isBlockrunExa ? "web_search" : isModalSandbox ? "modal" : isPhone ? "phone" : "partner"
265663
265735
  }).catch(() => {
265664
265736
  });
265665
265737
  }
@@ -266557,7 +266629,8 @@ async function startProxy(options) {
266557
266629
  } else if (val.startsWith("https://") || val.startsWith("http://")) {
266558
266630
  const imgResp = await ssrfSafeFetch(val, {
266559
266631
  signal: clientAbort.signal,
266560
- allowPrivate: process.env.CLAWROUTER_ALLOW_PRIVATE_FETCH === "1"
266632
+ allowPrivate: process.env.CLAWROUTER_ALLOW_PRIVATE_FETCH === "1",
266633
+ viaUpstreamProxy: Boolean(upstreamProxy)
266561
266634
  });
266562
266635
  if (!imgResp.ok)
266563
266636
  throw new Error(`Failed to download ${field} from ${val}: HTTP ${imgResp.status}`);
@@ -266934,7 +267007,7 @@ async function startProxy(options) {
266934
267007
  }
266935
267008
  const isVerbatimGatewayPath = req.url === "/v1/messages" || (req.url?.startsWith("/v1/messages?") ?? false) || req.url === "/v1/audio/speech" || (req.url?.startsWith("/v1/audio/speech?") ?? false);
266936
267009
  if (isVerbatimGatewayPath || req.url?.match(
266937
- /^\/v1\/(?:partner|pm|exa|modal|stocks|usstock|crypto|fx|commodity|phone|voice|surf)\//
267010
+ /^\/v1\/(?:partner|pm|exa|modal|stocks|usstock|crypto|fx|commodity|phone|voice)\//
266938
267011
  )) {
266939
267012
  try {
266940
267013
  await proxyPaidApiRequest(
@@ -266999,7 +267072,7 @@ async function startProxy(options) {
266999
267072
  res.end(
267000
267073
  JSON.stringify({
267001
267074
  error: {
267002
- message: `ClawRouter does not proxy ${req.url}. It serves /v1/chat/completions, /v1/messages, /v1/models, /v1/images/generations, /v1/images/image2image, /v1/videos/generations, /v1/audio/generations, /v1/audio/speech, and the partner prefixes /v1/{partner,pm,exa,modal,stocks,usstock,crypto,fx,commodity,phone,voice,surf}/. If BlockRun serves this endpoint, call it directly against the gateway.`,
267075
+ message: `ClawRouter does not proxy ${req.url}. It serves /v1/chat/completions, /v1/messages, /v1/models, /v1/images/generations, /v1/images/image2image, /v1/videos/generations, /v1/audio/generations, /v1/audio/speech, and the partner prefixes /v1/{partner,pm,exa,modal,stocks,usstock,crypto,fx,commodity,phone,voice}/. If BlockRun serves this endpoint, call it directly against the gateway.`,
267003
267076
  type: "invalid_request_error",
267004
267077
  code: "unsupported_endpoint"
267005
267078
  }
@@ -274238,7 +274311,7 @@ import { EventEmitter } from "events";
274238
274311
 
274239
274312
  // node_modules/axios/lib/helpers/formDataToStream.js
274240
274313
  import util2 from "util";
274241
- import { Readable as Readable2 } from "stream";
274314
+ import { Readable as Readable3 } from "stream";
274242
274315
 
274243
274316
  // node_modules/axios/lib/helpers/readBlob.js
274244
274317
  var { asyncIterator } = Symbol;
@@ -274328,7 +274401,7 @@ var formDataToStream = (form, headersHandler, options) => {
274328
274401
  computedHeaders["Content-Length"] = contentLength;
274329
274402
  }
274330
274403
  headersHandler && headersHandler(computedHeaders);
274331
- return Readable2.from(
274404
+ return Readable3.from(
274332
274405
  (async function* () {
274333
274406
  for (const part of parts) {
274334
274407
  yield boundaryBytes;
@@ -50,7 +50,7 @@ This is where you're paying for real value:
50
50
 
51
51
  ## The Solution: ClawRouter
52
52
 
53
- [ClawRouter](https://github.com/BlockRunAI/ClawRouter) is an open-source local proxy that sits between your app and <!-- br:models.chatVisible -->88<!-- /br:models.chatVisible --> AI models. It saves you money in three ways: **smart routing**, **token optimization**, and **response caching**.
53
+ [ClawRouter](https://github.com/BlockRunAI/ClawRouter) is an open-source local proxy that sits between your app and <!-- br:models.chatVisible -->90<!-- /br:models.chatVisible --> AI models. It saves you money in three ways: **smart routing**, **token optimization**, and **response caching**.
54
54
 
55
55
  ```
56
56
  ┌─────────────┐ ┌──────────────────────────────┐ ┌──────────────────┐
@@ -31,7 +31,7 @@ This is exactly the problem [ClawRouter](https://github.com/BlockRunAI/ClawRoute
31
31
 
32
32
  ## ClawRouter: Smart Routing for Agents
33
33
 
34
- ClawRouter is an open-source local proxy that sits between your agent and <!-- br:models.chatVisible -->88<!-- /br:models.chatVisible --> LLM models across 9 providers. It analyzes every request across 15 dimensions and routes it to the cheapest model that can handle it — in under 1ms, entirely locally.
34
+ ClawRouter is an open-source local proxy that sits between your agent and <!-- br:models.chatVisible -->90<!-- /br:models.chatVisible --> LLM models across 9 providers. It analyzes every request across 15 dimensions and routes it to the cheapest model that can handle it — in under 1ms, entirely locally.
35
35
 
36
36
  ```
37
37
  Your Agent → ClawRouter (localhost:8402) → Best model for the job
@@ -74,7 +74,7 @@ Then point your agent at `http://localhost:8402/v1/` with any OpenAI-compatible
74
74
 
75
75
  - **No API keys to manage** — wallet-based cryptographic auth
76
76
  - **No subscriptions** — pay per request in USDC (Base or Solana)
77
- - **No vendor lock-in** — <!-- br:models.chatVisible -->88<!-- /br:models.chatVisible --> models, switch anytime
77
+ - **No vendor lock-in** — <!-- br:models.chatVisible -->90<!-- /br:models.chatVisible --> models, switch anytime
78
78
  - **You control your wallet** — non-custodial, funds never held by a third party
79
79
  - **Budget caps** — set a max spend per session, ClawRouter gracefully downgrades when budget runs low
80
80
  - **Token compression** — 7-layer pipeline reduces token costs by 7–40% before they hit any provider
@@ -222,7 +222,7 @@ OpenRouter doesn't always pass through provider-specific features correctly. Ima
222
222
 
223
223
  **Direct provider routing.** ClawRouter routes through BlockRun's API directly to providers — not through a second aggregator. One hop, not two. Provider-specific features work because there's no middleman translating them.
224
224
 
225
- ![Guaranteed Feature Parity & Direct Connectivity — Three-panel diagram: Vision (image_url auto-detected → vision-capable models only), Tool Calling (toolCalling flag → agentic models only), Catalog (curated <!-- br:models.chatVisible -->88<!-- /br:models.chatVisible --> models with automatic legacy-to-modern redirects). Direct provider routing means no dropped payloads.](./assets/clawrouter-feature-parity-direct-connectivity.png)
225
+ ![Guaranteed Feature Parity & Direct Connectivity — Three-panel diagram: Vision (image_url auto-detected → vision-capable models only), Tool Calling (toolCalling flag → agentic models only), Catalog (curated <!-- br:models.chatVisible -->90<!-- /br:models.chatVisible --> models with automatic legacy-to-modern redirects). Direct provider routing means no dropped payloads.](./assets/clawrouter-feature-parity-direct-connectivity.png)
226
226
 
227
227
  ---
228
228
 
@@ -240,7 +240,7 @@ When new models launch, OpenRouter's catalog lags. Users configure a model that
240
240
 
241
241
  ### How ClawRouter Solves This
242
242
 
243
- ClawRouter maintains a curated catalog of <!-- br:models.chatVisible -->88<!-- /br:models.chatVisible --> models across 9 providers (including <!-- br:models.free -->7<!-- /br:models.free --> free models), updated with each release. Delisted models have automatic redirect aliases:
243
+ ClawRouter maintains a curated catalog of <!-- br:models.chatVisible -->90<!-- /br:models.chatVisible --> models across 9 providers (including <!-- br:models.free -->7<!-- /br:models.free --> free models), updated with each release. Delisted models have automatic redirect aliases:
244
244
 
245
245
  ```typescript
246
246
  // Delisted models redirect automatically
@@ -268,7 +268,7 @@ No silent drops. No stale catalog. Models are benchmarked for speed, quality, an
268
268
  | **Rate limits** | Per-key, shared | Per-wallet, independent |
269
269
  | **Vision support** | Images sometimes dropped | Auto-detected, vision-only fallback |
270
270
  | **Tool calling** | Silent failures with some models | Flag-based filtering, guaranteed support |
271
- | **Model catalog** | Laggy, silent drops | Curated <!-- br:models.chatVisible -->88<!-- /br:models.chatVisible --> models, redirect aliases |
271
+ | **Model catalog** | Laggy, silent drops | Curated <!-- br:models.chatVisible -->90<!-- /br:models.chatVisible --> models, redirect aliases |
272
272
  | **Budget control** | Monthly invoice | Per-session cap (`maxCostPerRun`) |
273
273
  | **Setup** | Create account, paste key | Agent generates wallet, auto-configured |
274
274
  | **Average cost** | $25/M tokens (Opus direct) | auto-routed = **<!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->% savings** |
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "blockrun-clawrouter",
3
3
  "name": "BlockRun ClawRouter",
4
- "description": "Smart LLM router \u2014 82 models, x402 micropayments, 84% cost savings. Phone lookup + AI voice calls (Twilio + Bland.ai). Surf crypto-data API (84 endpoints, on-chain SQL, 100M+ labeled wallets) via skill.",
4
+ "description": "Smart LLM router \u2014 x402 micropayments, 84% cost savings. Phone lookup + AI voice calls (Twilio + Bland.ai).",
5
5
  "skills": ["./skills"],
6
6
  "activation": {
7
7
  "onStartup": true
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blockrun/clawrouter",
3
- "version": "0.12.297",
4
- "description": "Smart LLM router — save 84% on inference costs. 88 models (7 free). Pay by credit card (API key) or USDC (x402 wallet).",
3
+ "version": "0.12.299",
4
+ "description": "Smart LLM router — save 84% on inference costs. 90 models (7 free). Pay by credit card (API key) or USDC (x402 wallet).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",