@blockrun/llm 2.12.0 → 3.0.0

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
@@ -1512,205 +1512,6 @@ var LLMClient = class _LLMClient {
1512
1512
  }
1513
1513
  throw lastError || new Error("All RPCs failed");
1514
1514
  }
1515
- // ============================================================
1516
- // X/Twitter endpoints (powered by AttentionVC)
1517
- // ============================================================
1518
- /**
1519
- * Look up X/Twitter user profiles by username.
1520
- *
1521
- * Powered by AttentionVC. $0.002 per user (min $0.02, max $0.20).
1522
- *
1523
- * @param usernames - Single username or array of usernames (without @)
1524
- */
1525
- async xUserLookup(usernames) {
1526
- const names = Array.isArray(usernames) ? usernames : [usernames];
1527
- const data = await this.requestWithPaymentRaw("/v1/x/users/lookup", { usernames: names });
1528
- return data;
1529
- }
1530
- /**
1531
- * Get followers of an X/Twitter user.
1532
- *
1533
- * Powered by AttentionVC. $0.05 per page (~200 accounts).
1534
- *
1535
- * @param username - X/Twitter username (without @)
1536
- * @param cursor - Pagination cursor from previous response
1537
- */
1538
- async xFollowers(username, cursor) {
1539
- const body = { username };
1540
- if (cursor !== void 0) body.cursor = cursor;
1541
- const data = await this.requestWithPaymentRaw("/v1/x/users/followers", body);
1542
- return data;
1543
- }
1544
- /**
1545
- * Get accounts an X/Twitter user is following.
1546
- *
1547
- * Powered by AttentionVC. $0.05 per page (~200 accounts).
1548
- *
1549
- * @param username - X/Twitter username (without @)
1550
- * @param cursor - Pagination cursor from previous response
1551
- */
1552
- async xFollowings(username, cursor) {
1553
- const body = { username };
1554
- if (cursor !== void 0) body.cursor = cursor;
1555
- const data = await this.requestWithPaymentRaw("/v1/x/users/followings", body);
1556
- return data;
1557
- }
1558
- /**
1559
- * Get detailed profile info for a single X/Twitter user.
1560
- *
1561
- * Powered by AttentionVC. $0.002 per request.
1562
- *
1563
- * @param username - X/Twitter username (without @)
1564
- */
1565
- async xUserInfo(username) {
1566
- const data = await this.requestWithPaymentRaw("/v1/x/users/info", { username });
1567
- return data;
1568
- }
1569
- /**
1570
- * Get verified (blue-check) followers of an X/Twitter user.
1571
- *
1572
- * Powered by AttentionVC. $0.048 per page.
1573
- *
1574
- * @param userId - X/Twitter user ID (not username)
1575
- * @param cursor - Pagination cursor from previous response
1576
- */
1577
- async xVerifiedFollowers(userId, cursor) {
1578
- const body = { userId };
1579
- if (cursor !== void 0) body.cursor = cursor;
1580
- const data = await this.requestWithPaymentRaw("/v1/x/users/verified-followers", body);
1581
- return data;
1582
- }
1583
- /**
1584
- * Get tweets posted by an X/Twitter user.
1585
- *
1586
- * Powered by AttentionVC. $0.032 per page.
1587
- *
1588
- * @param username - X/Twitter username (without @)
1589
- * @param includeReplies - Include reply tweets (default: false)
1590
- * @param cursor - Pagination cursor from previous response
1591
- */
1592
- async xUserTweets(username, includeReplies = false, cursor) {
1593
- const body = { username, includeReplies };
1594
- if (cursor !== void 0) body.cursor = cursor;
1595
- const data = await this.requestWithPaymentRaw("/v1/x/users/tweets", body);
1596
- return data;
1597
- }
1598
- /**
1599
- * Get tweets that mention an X/Twitter user.
1600
- *
1601
- * Powered by AttentionVC. $0.032 per page.
1602
- *
1603
- * @param username - X/Twitter username (without @)
1604
- * @param sinceTime - Start time filter (ISO8601 or Unix timestamp)
1605
- * @param untilTime - End time filter (ISO8601 or Unix timestamp)
1606
- * @param cursor - Pagination cursor from previous response
1607
- */
1608
- async xUserMentions(username, sinceTime, untilTime, cursor) {
1609
- const body = { username };
1610
- if (sinceTime !== void 0) body.sinceTime = sinceTime;
1611
- if (untilTime !== void 0) body.untilTime = untilTime;
1612
- if (cursor !== void 0) body.cursor = cursor;
1613
- const data = await this.requestWithPaymentRaw("/v1/x/users/mentions", body);
1614
- return data;
1615
- }
1616
- /**
1617
- * Fetch full tweet data for up to 200 tweet IDs.
1618
- *
1619
- * Powered by AttentionVC. $0.16 per batch.
1620
- *
1621
- * @param tweetIds - Single tweet ID or array of tweet IDs (max 200)
1622
- */
1623
- async xTweetLookup(tweetIds) {
1624
- const ids = Array.isArray(tweetIds) ? tweetIds : [tweetIds];
1625
- const data = await this.requestWithPaymentRaw("/v1/x/tweets/lookup", { tweet_ids: ids });
1626
- return data;
1627
- }
1628
- /**
1629
- * Get replies to a specific tweet.
1630
- *
1631
- * Powered by AttentionVC. $0.032 per page.
1632
- *
1633
- * @param tweetId - The tweet ID to get replies for
1634
- * @param queryType - Sort order: 'Latest' or 'Default'
1635
- * @param cursor - Pagination cursor from previous response
1636
- */
1637
- async xTweetReplies(tweetId, queryType = "Latest", cursor) {
1638
- const body = { tweetId, queryType };
1639
- if (cursor !== void 0) body.cursor = cursor;
1640
- const data = await this.requestWithPaymentRaw("/v1/x/tweets/replies", body);
1641
- return data;
1642
- }
1643
- /**
1644
- * Get the full thread context for a tweet.
1645
- *
1646
- * Powered by AttentionVC. $0.032 per page.
1647
- *
1648
- * @param tweetId - The tweet ID to get thread for
1649
- * @param cursor - Pagination cursor from previous response
1650
- */
1651
- async xTweetThread(tweetId, cursor) {
1652
- const body = { tweetId };
1653
- if (cursor !== void 0) body.cursor = cursor;
1654
- const data = await this.requestWithPaymentRaw("/v1/x/tweets/thread", body);
1655
- return data;
1656
- }
1657
- /**
1658
- * Search X/Twitter with advanced query operators.
1659
- *
1660
- * Powered by AttentionVC. $0.032 per page.
1661
- *
1662
- * @param query - Search query (supports Twitter search operators)
1663
- * @param queryType - Sort order: 'Latest', 'Top', or 'Default'
1664
- * @param cursor - Pagination cursor from previous response
1665
- */
1666
- async xSearch(query, queryType = "Latest", cursor) {
1667
- const body = { query, queryType };
1668
- if (cursor !== void 0) body.cursor = cursor;
1669
- const data = await this.requestWithPaymentRaw("/v1/x/search", body);
1670
- return data;
1671
- }
1672
- /**
1673
- * Get current trending topics on X/Twitter.
1674
- *
1675
- * Powered by AttentionVC. $0.002 per request.
1676
- */
1677
- async xTrending() {
1678
- const data = await this.requestWithPaymentRaw("/v1/x/trending", {});
1679
- return data;
1680
- }
1681
- /**
1682
- * Get rising/viral articles from X/Twitter.
1683
- *
1684
- * Powered by AttentionVC intelligence layer. $0.05 per request.
1685
- */
1686
- async xArticlesRising() {
1687
- const data = await this.requestWithPaymentRaw("/v1/x/articles/rising", {});
1688
- return data;
1689
- }
1690
- /**
1691
- * Get author analytics and intelligence metrics for an X/Twitter user.
1692
- *
1693
- * Powered by AttentionVC intelligence layer. $0.02 per request.
1694
- *
1695
- * @param handle - X/Twitter handle (without @)
1696
- */
1697
- async xAuthorAnalytics(handle) {
1698
- const data = await this.requestWithPaymentRaw("/v1/x/authors", { handle });
1699
- return data;
1700
- }
1701
- /**
1702
- * Compare two X/Twitter authors side-by-side with intelligence metrics.
1703
- *
1704
- * Powered by AttentionVC intelligence layer. $0.05 per request.
1705
- *
1706
- * @param handle1 - First X/Twitter handle (without @)
1707
- * @param handle2 - Second X/Twitter handle (without @)
1708
- */
1709
- async xCompareAuthors(handle1, handle2) {
1710
- const data = await this.requestWithPaymentRaw("/v1/x/compare", { handle1, handle2 });
1711
- return data;
1712
- }
1713
- // ── Prediction Markets (Powered by Predexon) ────────────────────────────
1714
1515
  /**
1715
1516
  * Query Predexon prediction market data (GET endpoints).
1716
1517
  *
@@ -2546,11 +2347,33 @@ var VideoClient = class {
2546
2347
  "realFaceAssetId must be a Token360 asset id matching 'ta_[A-Za-z0-9]+' (e.g. 'ta_abc123xyz')"
2547
2348
  );
2548
2349
  }
2350
+ if (options?.lastFrameUrl && !options?.imageUrl) {
2351
+ throw new Error(
2352
+ "lastFrameUrl requires imageUrl: imageUrl seeds the FIRST frame and lastFrameUrl the FINAL frame \u2014 send both."
2353
+ );
2354
+ }
2355
+ if (options?.lastFrameUrl && options?.realFaceAssetId) {
2356
+ throw new Error(
2357
+ "lastFrameUrl and realFaceAssetId are mutually exclusive; first-and-last-frame uses imageUrl + lastFrameUrl."
2358
+ );
2359
+ }
2360
+ if (options?.referenceImageUrls?.length) {
2361
+ if (options.imageUrl || options.lastFrameUrl || options.realFaceAssetId) {
2362
+ throw new Error(
2363
+ "referenceImageUrls is mutually exclusive with imageUrl, lastFrameUrl, and realFaceAssetId."
2364
+ );
2365
+ }
2366
+ if (options.referenceImageUrls.length > 9) {
2367
+ throw new Error("referenceImageUrls accepts at most 9 images.");
2368
+ }
2369
+ }
2549
2370
  const body = {
2550
2371
  model: options?.model || DEFAULT_MODEL4,
2551
2372
  prompt
2552
2373
  };
2553
2374
  if (options?.imageUrl) body.image_url = options.imageUrl;
2375
+ if (options?.lastFrameUrl) body.last_frame_url = options.lastFrameUrl;
2376
+ if (options?.referenceImageUrls?.length) body.reference_image_urls = options.referenceImageUrls;
2554
2377
  if (options?.realFaceAssetId) body.real_face_asset_id = options.realFaceAssetId;
2555
2378
  if (options?.durationSeconds !== void 0) body.duration_seconds = options.durationSeconds;
2556
2379
  if (options?.aspectRatio) body.aspect_ratio = options.aspectRatio;
@@ -3414,217 +3237,10 @@ var SearchClient = class {
3414
3237
  }
3415
3238
  };
3416
3239
 
3417
- // src/x-client.ts
3240
+ // src/price.ts
3418
3241
  import { privateKeyToAccount as privateKeyToAccount10 } from "viem/accounts";
3419
3242
  var DEFAULT_API_URL10 = "https://blockrun.ai/api";
3420
- var DEFAULT_TIMEOUT10 = 6e4;
3421
- var XClient = class _XClient {
3422
- account;
3423
- privateKey;
3424
- apiUrl;
3425
- timeout;
3426
- static deprecationWarned = false;
3427
- constructor(options = {}) {
3428
- if (!_XClient.deprecationWarned) {
3429
- console.warn(
3430
- "[@blockrun/llm] XClient: BlockRun's /v1/x/* (AttentionVC) integration was removed 2026-04-30. All calls will return HTTP 404 until a replacement X data upstream is reintroduced."
3431
- );
3432
- _XClient.deprecationWarned = true;
3433
- }
3434
- const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
3435
- const privateKey = options.privateKey || envKey;
3436
- if (!privateKey) {
3437
- throw new Error(
3438
- "Private key required. Pass privateKey in options or set BLOCKRUN_WALLET_KEY environment variable."
3439
- );
3440
- }
3441
- validatePrivateKey(privateKey);
3442
- this.privateKey = privateKey;
3443
- this.account = privateKeyToAccount10(privateKey);
3444
- const apiUrl = options.apiUrl || DEFAULT_API_URL10;
3445
- validateApiUrl(apiUrl);
3446
- this.apiUrl = apiUrl.replace(/\/$/, "");
3447
- this.timeout = options.timeout || DEFAULT_TIMEOUT10;
3448
- }
3449
- // ───────── User endpoints ─────────
3450
- userLookup(usernames) {
3451
- return this.post("/v1/x/users/lookup", { usernames });
3452
- }
3453
- userInfo(username) {
3454
- return this.post("/v1/x/users/info", { username });
3455
- }
3456
- followers(username, cursor) {
3457
- const body = { username };
3458
- if (cursor) body.cursor = cursor;
3459
- return this.post("/v1/x/users/followers", body);
3460
- }
3461
- /** `/v1/x/users/following` (singular path variant). */
3462
- following(username, cursor) {
3463
- const body = { username };
3464
- if (cursor) body.cursor = cursor;
3465
- return this.post("/v1/x/users/following", body);
3466
- }
3467
- /** `/v1/x/users/followings` (plural path variant). */
3468
- followings(username, cursor) {
3469
- const body = { username };
3470
- if (cursor) body.cursor = cursor;
3471
- return this.post("/v1/x/users/followings", body);
3472
- }
3473
- verifiedFollowers(userId, cursor) {
3474
- const body = { userId };
3475
- if (cursor) body.cursor = cursor;
3476
- return this.post(
3477
- "/v1/x/users/verified-followers",
3478
- body
3479
- );
3480
- }
3481
- userTweets(options) {
3482
- if (!options.username && !options.userId) {
3483
- throw new Error("Either username or userId is required");
3484
- }
3485
- const body = {};
3486
- if (options.username) body.username = options.username;
3487
- if (options.userId) body.userId = options.userId;
3488
- if (options.cursor) body.cursor = options.cursor;
3489
- if (options.includeReplies !== void 0) body.includeReplies = options.includeReplies;
3490
- return this.post("/v1/x/users/tweets", body);
3491
- }
3492
- mentions(username, options) {
3493
- const body = { username };
3494
- if (options?.sinceTime) body.sinceTime = options.sinceTime;
3495
- if (options?.untilTime) body.untilTime = options.untilTime;
3496
- if (options?.cursor) body.cursor = options.cursor;
3497
- return this.post("/v1/x/users/mentions", body);
3498
- }
3499
- // ───────── Tweet endpoints ─────────
3500
- tweetLookup(tweetIds) {
3501
- return this.post("/v1/x/tweets/lookup", {
3502
- tweet_ids: tweetIds
3503
- });
3504
- }
3505
- tweetReplies(tweetId, options) {
3506
- const body = { tweetId };
3507
- if (options?.cursor) body.cursor = options.cursor;
3508
- if (options?.queryType) body.queryType = options.queryType;
3509
- return this.post("/v1/x/tweets/replies", body);
3510
- }
3511
- tweetThread(tweetId, cursor) {
3512
- const body = { tweetId };
3513
- if (cursor) body.cursor = cursor;
3514
- return this.post("/v1/x/tweets/thread", body);
3515
- }
3516
- // ───────── Search & discovery ─────────
3517
- search(query, options) {
3518
- const body = { query };
3519
- if (options?.queryType) body.queryType = options.queryType;
3520
- if (options?.cursor) body.cursor = options.cursor;
3521
- return this.post("/v1/x/search", body);
3522
- }
3523
- trending() {
3524
- return this.post("/v1/x/trending", {});
3525
- }
3526
- articlesRising() {
3527
- return this.post("/v1/x/articles/rising", {});
3528
- }
3529
- // ───────── Internals ─────────
3530
- async post(endpoint, body) {
3531
- const url = `${this.apiUrl}${endpoint}`;
3532
- const response = await this.fetchWithTimeout(url, {
3533
- method: "POST",
3534
- headers: { "Content-Type": "application/json" },
3535
- body: JSON.stringify(body)
3536
- });
3537
- if (response.status === 402) {
3538
- return this.payAndRetry(url, body, response);
3539
- }
3540
- if (!response.ok) {
3541
- let errorBody;
3542
- try {
3543
- errorBody = await response.json();
3544
- } catch {
3545
- errorBody = { error: "Request failed" };
3546
- }
3547
- throw new APIError(
3548
- `API error: ${response.status}`,
3549
- response.status,
3550
- sanitizeErrorResponse(errorBody)
3551
- );
3552
- }
3553
- return response.json();
3554
- }
3555
- async payAndRetry(url, body, response) {
3556
- let paymentHeader = response.headers.get("payment-required");
3557
- if (!paymentHeader) {
3558
- try {
3559
- const respBody = await response.json();
3560
- if (respBody.x402 || respBody.accepts) {
3561
- paymentHeader = btoa(JSON.stringify(respBody));
3562
- }
3563
- } catch {
3564
- }
3565
- }
3566
- if (!paymentHeader) {
3567
- throw new PaymentError("402 response but no payment requirements found");
3568
- }
3569
- const paymentRequired = parsePaymentRequired(paymentHeader);
3570
- const details = extractPaymentDetails(paymentRequired);
3571
- const paymentPayload = await createPaymentPayload(
3572
- this.privateKey,
3573
- this.account.address,
3574
- details.recipient,
3575
- details.amount,
3576
- details.network || "eip155:8453",
3577
- {
3578
- resourceUrl: details.resource?.url || url,
3579
- resourceDescription: details.resource?.description || "BlockRun X API",
3580
- maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
3581
- extra: details.extra
3582
- }
3583
- );
3584
- const retry = await this.fetchWithTimeout(url, {
3585
- method: "POST",
3586
- headers: {
3587
- "Content-Type": "application/json",
3588
- "PAYMENT-SIGNATURE": paymentPayload
3589
- },
3590
- body: JSON.stringify(body)
3591
- });
3592
- if (retry.status === 402) {
3593
- throw new PaymentError("Payment was rejected. Check your wallet balance.");
3594
- }
3595
- if (!retry.ok) {
3596
- let errorBody;
3597
- try {
3598
- errorBody = await retry.json();
3599
- } catch {
3600
- errorBody = { error: "Request failed" };
3601
- }
3602
- throw new APIError(
3603
- `API error after payment: ${retry.status}`,
3604
- retry.status,
3605
- sanitizeErrorResponse(errorBody)
3606
- );
3607
- }
3608
- return retry.json();
3609
- }
3610
- async fetchWithTimeout(url, init) {
3611
- const controller = new AbortController();
3612
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
3613
- try {
3614
- return await fetch(url, { ...init, signal: controller.signal });
3615
- } finally {
3616
- clearTimeout(timeoutId);
3617
- }
3618
- }
3619
- getWalletAddress() {
3620
- return this.account.address;
3621
- }
3622
- };
3623
-
3624
- // src/price.ts
3625
- import { privateKeyToAccount as privateKeyToAccount11 } from "viem/accounts";
3626
- var DEFAULT_API_URL11 = "https://blockrun.ai/api";
3627
- var DEFAULT_TIMEOUT11 = 3e4;
3243
+ var DEFAULT_TIMEOUT10 = 3e4;
3628
3244
  var PriceClient = class {
3629
3245
  account = null;
3630
3246
  privateKey = null;
@@ -3642,12 +3258,12 @@ var PriceClient = class {
3642
3258
  if (privateKey) {
3643
3259
  validatePrivateKey(privateKey);
3644
3260
  this.privateKey = privateKey;
3645
- this.account = privateKeyToAccount11(privateKey);
3261
+ this.account = privateKeyToAccount10(privateKey);
3646
3262
  }
3647
- const apiUrl = options.apiUrl || DEFAULT_API_URL11;
3263
+ const apiUrl = options.apiUrl || DEFAULT_API_URL10;
3648
3264
  validateApiUrl(apiUrl);
3649
3265
  this.apiUrl = apiUrl.replace(/\/$/, "");
3650
- this.timeout = options.timeout || DEFAULT_TIMEOUT11;
3266
+ this.timeout = options.timeout || DEFAULT_TIMEOUT10;
3651
3267
  }
3652
3268
  async price(category, symbol, options) {
3653
3269
  if (!symbol) throw new Error("symbol is required");
@@ -3826,9 +3442,9 @@ function buildUrl(base, query) {
3826
3442
  }
3827
3443
 
3828
3444
  // src/surf.ts
3829
- import { privateKeyToAccount as privateKeyToAccount12 } from "viem/accounts";
3830
- var DEFAULT_API_URL12 = "https://blockrun.ai/api";
3831
- var DEFAULT_TIMEOUT12 = 6e4;
3445
+ import { privateKeyToAccount as privateKeyToAccount11 } from "viem/accounts";
3446
+ var DEFAULT_API_URL11 = "https://blockrun.ai/api";
3447
+ var DEFAULT_TIMEOUT11 = 6e4;
3832
3448
  var SURF_PREFIX = "/v1/surf";
3833
3449
  var SurfClient = class {
3834
3450
  account;
@@ -3845,11 +3461,11 @@ var SurfClient = class {
3845
3461
  }
3846
3462
  validatePrivateKey(privateKey);
3847
3463
  this.privateKey = privateKey;
3848
- this.account = privateKeyToAccount12(privateKey);
3849
- const apiUrl = options.apiUrl || DEFAULT_API_URL12;
3464
+ this.account = privateKeyToAccount11(privateKey);
3465
+ const apiUrl = options.apiUrl || DEFAULT_API_URL11;
3850
3466
  validateApiUrl(apiUrl);
3851
3467
  this.apiUrl = apiUrl.replace(/\/$/, "");
3852
- this.timeout = options.timeout || DEFAULT_TIMEOUT12;
3468
+ this.timeout = options.timeout || DEFAULT_TIMEOUT11;
3853
3469
  }
3854
3470
  /**
3855
3471
  * GET a Surf endpoint. `path` is everything after `/v1/surf` (a leading
@@ -3980,6 +3596,259 @@ var SurfClient = class {
3980
3596
  }
3981
3597
  };
3982
3598
 
3599
+ // src/rpc.ts
3600
+ import { privateKeyToAccount as privateKeyToAccount12 } from "viem/accounts";
3601
+ var DEFAULT_API_URL12 = "https://blockrun.ai/api";
3602
+ var DEFAULT_TIMEOUT12 = 6e4;
3603
+ var RPC_PRICE_USD = 2e-3;
3604
+ var SUPPORTED_NETWORKS = [
3605
+ // EVM
3606
+ "ethereum",
3607
+ "base",
3608
+ "arbitrum",
3609
+ "arbitrum-nova",
3610
+ "optimism",
3611
+ "polygon",
3612
+ "bsc",
3613
+ "avalanche",
3614
+ "fantom",
3615
+ "cronos",
3616
+ "celo",
3617
+ "gnosis",
3618
+ "zksync",
3619
+ "berachain",
3620
+ "unichain",
3621
+ "monad",
3622
+ "chiliz",
3623
+ "moonbeam",
3624
+ "aurora",
3625
+ "flare",
3626
+ "oasis",
3627
+ "kaia",
3628
+ "sonic",
3629
+ "xdc",
3630
+ "abstract",
3631
+ "hyperevm",
3632
+ "plume",
3633
+ "ronin",
3634
+ "rootstock",
3635
+ // Non-EVM (JSON-RPC-compatible)
3636
+ "solana",
3637
+ "bitcoin",
3638
+ "litecoin",
3639
+ "dogecoin",
3640
+ "bitcoin-cash",
3641
+ "near",
3642
+ "sui",
3643
+ "ripple",
3644
+ "polkadot",
3645
+ "kusama",
3646
+ "zcash"
3647
+ ];
3648
+ var NETWORK_ALIASES = {
3649
+ eth: "ethereum",
3650
+ arb: "arbitrum",
3651
+ "arbitrum-one": "arbitrum",
3652
+ "arb-one": "arbitrum",
3653
+ "arb-nova": "arbitrum-nova",
3654
+ op: "optimism",
3655
+ matic: "polygon",
3656
+ pol: "polygon",
3657
+ bnb: "bsc",
3658
+ binance: "bsc",
3659
+ "binance-smart-chain": "bsc",
3660
+ avax: "avalanche",
3661
+ ftm: "fantom",
3662
+ bera: "berachain",
3663
+ klaytn: "kaia",
3664
+ chz: "chiliz",
3665
+ hyperliquid: "hyperevm",
3666
+ rsk: "rootstock",
3667
+ sol: "solana",
3668
+ btc: "bitcoin",
3669
+ ltc: "litecoin",
3670
+ doge: "dogecoin",
3671
+ bch: "bitcoin-cash",
3672
+ xrp: "ripple",
3673
+ xrpl: "ripple",
3674
+ dot: "polkadot",
3675
+ zec: "zcash"
3676
+ };
3677
+ var RpcClient = class {
3678
+ account;
3679
+ privateKey;
3680
+ apiUrl;
3681
+ timeout;
3682
+ sessionTotalUsd = 0;
3683
+ sessionCalls = 0;
3684
+ constructor(options = {}) {
3685
+ const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
3686
+ const privateKey = options.privateKey || envKey;
3687
+ if (!privateKey) {
3688
+ throw new Error(
3689
+ "Private key required. Pass privateKey in options or set BLOCKRUN_WALLET_KEY environment variable."
3690
+ );
3691
+ }
3692
+ validatePrivateKey(privateKey);
3693
+ this.privateKey = privateKey;
3694
+ this.account = privateKeyToAccount12(privateKey);
3695
+ const apiUrl = options.apiUrl || DEFAULT_API_URL12;
3696
+ validateApiUrl(apiUrl);
3697
+ this.apiUrl = apiUrl.replace(/\/$/, "");
3698
+ this.timeout = options.timeout || DEFAULT_TIMEOUT12;
3699
+ }
3700
+ /**
3701
+ * Make a single JSON-RPC 2.0 call. Flat $0.002.
3702
+ *
3703
+ * @param network - Chain name (e.g. "ethereum", "base", "solana") or a
3704
+ * common alias ("eth", "sol", "matic", ...). See
3705
+ * SUPPORTED_NETWORKS / NETWORK_ALIASES.
3706
+ * @param method - Chain RPC method, e.g. "eth_blockNumber", "eth_call",
3707
+ * "eth_getBalance" (EVM) or "getSlot", "getAccountInfo"
3708
+ * (Solana).
3709
+ * @param params - Method-specific params array (optional).
3710
+ * @returns RpcResponse with `result` (or JSON-RPC `error`), plus
3711
+ * `network`, `cacheHit` and `txHash` metadata.
3712
+ *
3713
+ * @example
3714
+ * const block = await client.call('ethereum', 'eth_blockNumber');
3715
+ * console.log(parseInt(block.result as string, 16));
3716
+ */
3717
+ async call(network, method, params) {
3718
+ const body = { jsonrpc: "2.0", id: 1, method };
3719
+ if (params !== void 0) body.params = params;
3720
+ const { data, headers } = await this.requestWithPayment(network, body);
3721
+ return this.toResponse(data, headers);
3722
+ }
3723
+ /**
3724
+ * Make a JSON-RPC 2.0 batch call. Priced per element ($0.002 x N).
3725
+ *
3726
+ * @param network - Chain name or alias (see {@link call}).
3727
+ * @param requests - Requests, each with a `method` and optional
3728
+ * `params` / `id`. `jsonrpc` and missing ids are
3729
+ * filled in automatically.
3730
+ * @returns Array of RpcResponse, in upstream order.
3731
+ *
3732
+ * @example
3733
+ * const out = await client.batch('base', [
3734
+ * { method: 'eth_blockNumber' },
3735
+ * { method: 'eth_gasPrice' },
3736
+ * ]);
3737
+ */
3738
+ async batch(network, requests) {
3739
+ if (!requests.length) {
3740
+ throw new Error("batch requires at least one request");
3741
+ }
3742
+ const body = requests.map((req, i) => {
3743
+ if (!req.method) throw new Error(`batch request ${i} is missing 'method'`);
3744
+ return { jsonrpc: "2.0", id: i + 1, ...req };
3745
+ });
3746
+ const { data, headers } = await this.requestWithPayment(network, body);
3747
+ const items = Array.isArray(data) ? data : [data];
3748
+ return items.map((item) => this.toResponse(item, headers));
3749
+ }
3750
+ toResponse(data, headers) {
3751
+ const base = data !== null && typeof data === "object" && !Array.isArray(data) ? { ...data } : { result: data };
3752
+ const network = headers.get("x-network");
3753
+ if (network) base.network = network;
3754
+ base.cacheHit = (headers.get("x-cache") || "").toUpperCase() === "HIT";
3755
+ const txHash = headers.get("x-payment-receipt") || headers.get("X-Payment-Receipt");
3756
+ if (txHash) base.txHash = txHash;
3757
+ return base;
3758
+ }
3759
+ async requestWithPayment(network, body) {
3760
+ const endpoint = `/v1/rpc/${network}`;
3761
+ const url = `${this.apiUrl}${endpoint}`;
3762
+ const response = await this.fetchWithTimeout(url, {
3763
+ method: "POST",
3764
+ headers: { "Content-Type": "application/json" },
3765
+ body: JSON.stringify(body)
3766
+ });
3767
+ if (response.status === 402) {
3768
+ return this.handlePaymentAndRetry(url, endpoint, body, response);
3769
+ }
3770
+ if (!response.ok) {
3771
+ let errorBody;
3772
+ try {
3773
+ errorBody = await response.json();
3774
+ } catch {
3775
+ errorBody = { error: "Request failed" };
3776
+ }
3777
+ throw new APIError(`API error: ${response.status}`, response.status, sanitizeErrorResponse(errorBody));
3778
+ }
3779
+ return { data: await response.json(), headers: response.headers };
3780
+ }
3781
+ async handlePaymentAndRetry(url, endpoint, body, response) {
3782
+ let paymentHeader = response.headers.get("payment-required");
3783
+ if (!paymentHeader) {
3784
+ try {
3785
+ const respBody = await response.json();
3786
+ if (respBody.x402 || respBody.accepts) {
3787
+ paymentHeader = btoa(JSON.stringify(respBody));
3788
+ }
3789
+ } catch {
3790
+ }
3791
+ }
3792
+ if (!paymentHeader) {
3793
+ throw new PaymentError("402 response but no payment requirements found");
3794
+ }
3795
+ const paymentRequired = parsePaymentRequired(paymentHeader);
3796
+ const details = extractPaymentDetails(paymentRequired);
3797
+ const paymentPayload = await createPaymentPayload(
3798
+ this.privateKey,
3799
+ this.account.address,
3800
+ details.recipient,
3801
+ details.amount,
3802
+ details.network || "eip155:8453",
3803
+ {
3804
+ resourceUrl: details.resource?.url || `${this.apiUrl}${endpoint}`,
3805
+ resourceDescription: details.resource?.description || "BlockRun Multi-chain RPC",
3806
+ maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
3807
+ extra: details.extra
3808
+ }
3809
+ );
3810
+ const retryResponse = await this.fetchWithTimeout(url, {
3811
+ method: "POST",
3812
+ headers: {
3813
+ "Content-Type": "application/json",
3814
+ "PAYMENT-SIGNATURE": paymentPayload
3815
+ },
3816
+ body: JSON.stringify(body)
3817
+ });
3818
+ if (retryResponse.status === 402) {
3819
+ throw new PaymentError("Payment was rejected. Check your wallet balance.");
3820
+ }
3821
+ if (!retryResponse.ok) {
3822
+ let errorBody;
3823
+ try {
3824
+ errorBody = await retryResponse.json();
3825
+ } catch {
3826
+ errorBody = { error: "Request failed" };
3827
+ }
3828
+ throw new APIError(`API error after payment: ${retryResponse.status}`, retryResponse.status, sanitizeErrorResponse(errorBody));
3829
+ }
3830
+ this.sessionCalls++;
3831
+ const paidUsd = Number(details.amount) / 1e6;
3832
+ if (Number.isFinite(paidUsd)) this.sessionTotalUsd += paidUsd;
3833
+ return { data: await retryResponse.json(), headers: retryResponse.headers };
3834
+ }
3835
+ async fetchWithTimeout(url, options) {
3836
+ const controller = new AbortController();
3837
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
3838
+ try {
3839
+ return await fetch(url, { ...options, signal: controller.signal });
3840
+ } finally {
3841
+ clearTimeout(timeoutId);
3842
+ }
3843
+ }
3844
+ getWalletAddress() {
3845
+ return this.account.address;
3846
+ }
3847
+ getSpending() {
3848
+ return { totalUsd: this.sessionTotalUsd, calls: this.sessionCalls };
3849
+ }
3850
+ };
3851
+
3983
3852
  // src/blockrun.ts
3984
3853
  import { privateKeyToAccount as privateKeyToAccount13 } from "viem/accounts";
3985
3854
  var DEFAULT_API_URL13 = "https://blockrun.ai/api";
@@ -4774,89 +4643,6 @@ var SolanaLLMClient = class {
4774
4643
  const data = await this.requestWithPaymentRaw("/v1/search", body);
4775
4644
  return data;
4776
4645
  }
4777
- // ============================================================
4778
- // X/Twitter endpoints (powered by AttentionVC)
4779
- // ============================================================
4780
- async xUserLookup(usernames) {
4781
- const names = Array.isArray(usernames) ? usernames : [usernames];
4782
- const data = await this.requestWithPaymentRaw("/v1/x/users/lookup", { usernames: names });
4783
- return data;
4784
- }
4785
- async xFollowers(username, cursor) {
4786
- const body = { username };
4787
- if (cursor !== void 0) body.cursor = cursor;
4788
- const data = await this.requestWithPaymentRaw("/v1/x/users/followers", body);
4789
- return data;
4790
- }
4791
- async xFollowings(username, cursor) {
4792
- const body = { username };
4793
- if (cursor !== void 0) body.cursor = cursor;
4794
- const data = await this.requestWithPaymentRaw("/v1/x/users/followings", body);
4795
- return data;
4796
- }
4797
- async xUserInfo(username) {
4798
- const data = await this.requestWithPaymentRaw("/v1/x/users/info", { username });
4799
- return data;
4800
- }
4801
- async xVerifiedFollowers(userId, cursor) {
4802
- const body = { userId };
4803
- if (cursor !== void 0) body.cursor = cursor;
4804
- const data = await this.requestWithPaymentRaw("/v1/x/users/verified-followers", body);
4805
- return data;
4806
- }
4807
- async xUserTweets(username, includeReplies = false, cursor) {
4808
- const body = { username, includeReplies };
4809
- if (cursor !== void 0) body.cursor = cursor;
4810
- const data = await this.requestWithPaymentRaw("/v1/x/users/tweets", body);
4811
- return data;
4812
- }
4813
- async xUserMentions(username, sinceTime, untilTime, cursor) {
4814
- const body = { username };
4815
- if (sinceTime !== void 0) body.sinceTime = sinceTime;
4816
- if (untilTime !== void 0) body.untilTime = untilTime;
4817
- if (cursor !== void 0) body.cursor = cursor;
4818
- const data = await this.requestWithPaymentRaw("/v1/x/users/mentions", body);
4819
- return data;
4820
- }
4821
- async xTweetLookup(tweetIds) {
4822
- const ids = Array.isArray(tweetIds) ? tweetIds : [tweetIds];
4823
- const data = await this.requestWithPaymentRaw("/v1/x/tweets/lookup", { tweet_ids: ids });
4824
- return data;
4825
- }
4826
- async xTweetReplies(tweetId, queryType = "Latest", cursor) {
4827
- const body = { tweetId, queryType };
4828
- if (cursor !== void 0) body.cursor = cursor;
4829
- const data = await this.requestWithPaymentRaw("/v1/x/tweets/replies", body);
4830
- return data;
4831
- }
4832
- async xTweetThread(tweetId, cursor) {
4833
- const body = { tweetId };
4834
- if (cursor !== void 0) body.cursor = cursor;
4835
- const data = await this.requestWithPaymentRaw("/v1/x/tweets/thread", body);
4836
- return data;
4837
- }
4838
- async xSearch(query, queryType = "Latest", cursor) {
4839
- const body = { query, queryType };
4840
- if (cursor !== void 0) body.cursor = cursor;
4841
- const data = await this.requestWithPaymentRaw("/v1/x/search", body);
4842
- return data;
4843
- }
4844
- async xTrending() {
4845
- const data = await this.requestWithPaymentRaw("/v1/x/trending", {});
4846
- return data;
4847
- }
4848
- async xArticlesRising() {
4849
- const data = await this.requestWithPaymentRaw("/v1/x/articles/rising", {});
4850
- return data;
4851
- }
4852
- async xAuthorAnalytics(handle) {
4853
- const data = await this.requestWithPaymentRaw("/v1/x/authors", { handle });
4854
- return data;
4855
- }
4856
- async xCompareAuthors(handle1, handle2) {
4857
- const data = await this.requestWithPaymentRaw("/v1/x/compare", { handle1, handle2 });
4858
- return data;
4859
- }
4860
4646
  // ── Prediction Markets (Powered by Predexon) ────────────────────────────
4861
4647
  async pm(path5, params) {
4862
4648
  return this.getWithPaymentRaw(`/v1/pm/${path5}`, params);
@@ -5220,7 +5006,6 @@ var CACHE_DIR = path4.join(os4.homedir(), ".blockrun", "cache");
5220
5006
  var DATA_DIR = path4.join(os4.homedir(), ".blockrun", "data");
5221
5007
  var COST_LOG_FILE2 = path4.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
5222
5008
  var DEFAULT_TTL = {
5223
- "/v1/x/": 3600 * 1e3,
5224
5009
  "/v1/partner/": 3600 * 1e3,
5225
5010
  "/v1/pm/": 1800 * 1e3,
5226
5011
  "/v1/chat/": 0,
@@ -5289,8 +5074,6 @@ function readableFilename(endpoint, body) {
5289
5074
  let ep = endpoint.replace(/\/+$/, "").split("/").pop() || "";
5290
5075
  if (endpoint.includes("/v1/chat/")) {
5291
5076
  ep = "chat";
5292
- } else if (endpoint.includes("/v1/x/")) {
5293
- ep = "x_" + ep;
5294
5077
  } else if (endpoint.includes("/v1/search")) {
5295
5078
  ep = "search";
5296
5079
  } else if (endpoint.includes("/v1/image")) {
@@ -5705,6 +5488,7 @@ export {
5705
5488
  KNOWN_PROVIDERS,
5706
5489
  LLMClient,
5707
5490
  MusicClient,
5491
+ NETWORK_ALIASES,
5708
5492
  OpenAI,
5709
5493
  PHONE_PRICES,
5710
5494
  PORTRAIT_ENROLLMENT_PRICE_USD,
@@ -5712,8 +5496,11 @@ export {
5712
5496
  PhoneClient,
5713
5497
  PortraitClient,
5714
5498
  PriceClient,
5499
+ RPC_PRICE_USD,
5500
+ RpcClient,
5715
5501
  SOLANA_NETWORK,
5716
5502
  SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH,
5503
+ SUPPORTED_NETWORKS,
5717
5504
  SearchClient,
5718
5505
  SolanaLLMClient,
5719
5506
  SpeechClient,
@@ -5725,7 +5512,6 @@ export {
5725
5512
  VoiceClient,
5726
5513
  WALLET_DIR_PATH,
5727
5514
  WALLET_FILE_PATH,
5728
- XClient,
5729
5515
  clearCache,
5730
5516
  createPaymentPayload,
5731
5517
  createSolanaPaymentPayload,