@blockrun/llm 2.13.0 → 3.1.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/README.md +32 -49
- package/dist/index.cjs +262 -528
- package/dist/index.d.cts +127 -347
- package/dist/index.d.ts +127 -347
- package/dist/index.js +261 -526
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -63,7 +63,6 @@ __export(index_exports, {
|
|
|
63
63
|
VoiceClient: () => VoiceClient,
|
|
64
64
|
WALLET_DIR_PATH: () => WALLET_DIR_PATH,
|
|
65
65
|
WALLET_FILE_PATH: () => WALLET_FILE_PATH,
|
|
66
|
-
XClient: () => XClient,
|
|
67
66
|
clearCache: () => clearCache,
|
|
68
67
|
createPaymentPayload: () => createPaymentPayload,
|
|
69
68
|
createSolanaPaymentPayload: () => createSolanaPaymentPayload,
|
|
@@ -1620,205 +1619,6 @@ var LLMClient = class _LLMClient {
|
|
|
1620
1619
|
}
|
|
1621
1620
|
throw lastError || new Error("All RPCs failed");
|
|
1622
1621
|
}
|
|
1623
|
-
// ============================================================
|
|
1624
|
-
// X/Twitter endpoints (powered by AttentionVC)
|
|
1625
|
-
// ============================================================
|
|
1626
|
-
/**
|
|
1627
|
-
* Look up X/Twitter user profiles by username.
|
|
1628
|
-
*
|
|
1629
|
-
* Powered by AttentionVC. $0.002 per user (min $0.02, max $0.20).
|
|
1630
|
-
*
|
|
1631
|
-
* @param usernames - Single username or array of usernames (without @)
|
|
1632
|
-
*/
|
|
1633
|
-
async xUserLookup(usernames) {
|
|
1634
|
-
const names = Array.isArray(usernames) ? usernames : [usernames];
|
|
1635
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/lookup", { usernames: names });
|
|
1636
|
-
return data;
|
|
1637
|
-
}
|
|
1638
|
-
/**
|
|
1639
|
-
* Get followers of an X/Twitter user.
|
|
1640
|
-
*
|
|
1641
|
-
* Powered by AttentionVC. $0.05 per page (~200 accounts).
|
|
1642
|
-
*
|
|
1643
|
-
* @param username - X/Twitter username (without @)
|
|
1644
|
-
* @param cursor - Pagination cursor from previous response
|
|
1645
|
-
*/
|
|
1646
|
-
async xFollowers(username, cursor) {
|
|
1647
|
-
const body = { username };
|
|
1648
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1649
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followers", body);
|
|
1650
|
-
return data;
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Get accounts an X/Twitter user is following.
|
|
1654
|
-
*
|
|
1655
|
-
* Powered by AttentionVC. $0.05 per page (~200 accounts).
|
|
1656
|
-
*
|
|
1657
|
-
* @param username - X/Twitter username (without @)
|
|
1658
|
-
* @param cursor - Pagination cursor from previous response
|
|
1659
|
-
*/
|
|
1660
|
-
async xFollowings(username, cursor) {
|
|
1661
|
-
const body = { username };
|
|
1662
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1663
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followings", body);
|
|
1664
|
-
return data;
|
|
1665
|
-
}
|
|
1666
|
-
/**
|
|
1667
|
-
* Get detailed profile info for a single X/Twitter user.
|
|
1668
|
-
*
|
|
1669
|
-
* Powered by AttentionVC. $0.002 per request.
|
|
1670
|
-
*
|
|
1671
|
-
* @param username - X/Twitter username (without @)
|
|
1672
|
-
*/
|
|
1673
|
-
async xUserInfo(username) {
|
|
1674
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/info", { username });
|
|
1675
|
-
return data;
|
|
1676
|
-
}
|
|
1677
|
-
/**
|
|
1678
|
-
* Get verified (blue-check) followers of an X/Twitter user.
|
|
1679
|
-
*
|
|
1680
|
-
* Powered by AttentionVC. $0.048 per page.
|
|
1681
|
-
*
|
|
1682
|
-
* @param userId - X/Twitter user ID (not username)
|
|
1683
|
-
* @param cursor - Pagination cursor from previous response
|
|
1684
|
-
*/
|
|
1685
|
-
async xVerifiedFollowers(userId, cursor) {
|
|
1686
|
-
const body = { userId };
|
|
1687
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1688
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/verified-followers", body);
|
|
1689
|
-
return data;
|
|
1690
|
-
}
|
|
1691
|
-
/**
|
|
1692
|
-
* Get tweets posted by an X/Twitter user.
|
|
1693
|
-
*
|
|
1694
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1695
|
-
*
|
|
1696
|
-
* @param username - X/Twitter username (without @)
|
|
1697
|
-
* @param includeReplies - Include reply tweets (default: false)
|
|
1698
|
-
* @param cursor - Pagination cursor from previous response
|
|
1699
|
-
*/
|
|
1700
|
-
async xUserTweets(username, includeReplies = false, cursor) {
|
|
1701
|
-
const body = { username, includeReplies };
|
|
1702
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1703
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/tweets", body);
|
|
1704
|
-
return data;
|
|
1705
|
-
}
|
|
1706
|
-
/**
|
|
1707
|
-
* Get tweets that mention an X/Twitter user.
|
|
1708
|
-
*
|
|
1709
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1710
|
-
*
|
|
1711
|
-
* @param username - X/Twitter username (without @)
|
|
1712
|
-
* @param sinceTime - Start time filter (ISO8601 or Unix timestamp)
|
|
1713
|
-
* @param untilTime - End time filter (ISO8601 or Unix timestamp)
|
|
1714
|
-
* @param cursor - Pagination cursor from previous response
|
|
1715
|
-
*/
|
|
1716
|
-
async xUserMentions(username, sinceTime, untilTime, cursor) {
|
|
1717
|
-
const body = { username };
|
|
1718
|
-
if (sinceTime !== void 0) body.sinceTime = sinceTime;
|
|
1719
|
-
if (untilTime !== void 0) body.untilTime = untilTime;
|
|
1720
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1721
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/mentions", body);
|
|
1722
|
-
return data;
|
|
1723
|
-
}
|
|
1724
|
-
/**
|
|
1725
|
-
* Fetch full tweet data for up to 200 tweet IDs.
|
|
1726
|
-
*
|
|
1727
|
-
* Powered by AttentionVC. $0.16 per batch.
|
|
1728
|
-
*
|
|
1729
|
-
* @param tweetIds - Single tweet ID or array of tweet IDs (max 200)
|
|
1730
|
-
*/
|
|
1731
|
-
async xTweetLookup(tweetIds) {
|
|
1732
|
-
const ids = Array.isArray(tweetIds) ? tweetIds : [tweetIds];
|
|
1733
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/lookup", { tweet_ids: ids });
|
|
1734
|
-
return data;
|
|
1735
|
-
}
|
|
1736
|
-
/**
|
|
1737
|
-
* Get replies to a specific tweet.
|
|
1738
|
-
*
|
|
1739
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1740
|
-
*
|
|
1741
|
-
* @param tweetId - The tweet ID to get replies for
|
|
1742
|
-
* @param queryType - Sort order: 'Latest' or 'Default'
|
|
1743
|
-
* @param cursor - Pagination cursor from previous response
|
|
1744
|
-
*/
|
|
1745
|
-
async xTweetReplies(tweetId, queryType = "Latest", cursor) {
|
|
1746
|
-
const body = { tweetId, queryType };
|
|
1747
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1748
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/replies", body);
|
|
1749
|
-
return data;
|
|
1750
|
-
}
|
|
1751
|
-
/**
|
|
1752
|
-
* Get the full thread context for a tweet.
|
|
1753
|
-
*
|
|
1754
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1755
|
-
*
|
|
1756
|
-
* @param tweetId - The tweet ID to get thread for
|
|
1757
|
-
* @param cursor - Pagination cursor from previous response
|
|
1758
|
-
*/
|
|
1759
|
-
async xTweetThread(tweetId, cursor) {
|
|
1760
|
-
const body = { tweetId };
|
|
1761
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1762
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/thread", body);
|
|
1763
|
-
return data;
|
|
1764
|
-
}
|
|
1765
|
-
/**
|
|
1766
|
-
* Search X/Twitter with advanced query operators.
|
|
1767
|
-
*
|
|
1768
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1769
|
-
*
|
|
1770
|
-
* @param query - Search query (supports Twitter search operators)
|
|
1771
|
-
* @param queryType - Sort order: 'Latest', 'Top', or 'Default'
|
|
1772
|
-
* @param cursor - Pagination cursor from previous response
|
|
1773
|
-
*/
|
|
1774
|
-
async xSearch(query, queryType = "Latest", cursor) {
|
|
1775
|
-
const body = { query, queryType };
|
|
1776
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1777
|
-
const data = await this.requestWithPaymentRaw("/v1/x/search", body);
|
|
1778
|
-
return data;
|
|
1779
|
-
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Get current trending topics on X/Twitter.
|
|
1782
|
-
*
|
|
1783
|
-
* Powered by AttentionVC. $0.002 per request.
|
|
1784
|
-
*/
|
|
1785
|
-
async xTrending() {
|
|
1786
|
-
const data = await this.requestWithPaymentRaw("/v1/x/trending", {});
|
|
1787
|
-
return data;
|
|
1788
|
-
}
|
|
1789
|
-
/**
|
|
1790
|
-
* Get rising/viral articles from X/Twitter.
|
|
1791
|
-
*
|
|
1792
|
-
* Powered by AttentionVC intelligence layer. $0.05 per request.
|
|
1793
|
-
*/
|
|
1794
|
-
async xArticlesRising() {
|
|
1795
|
-
const data = await this.requestWithPaymentRaw("/v1/x/articles/rising", {});
|
|
1796
|
-
return data;
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* Get author analytics and intelligence metrics for an X/Twitter user.
|
|
1800
|
-
*
|
|
1801
|
-
* Powered by AttentionVC intelligence layer. $0.02 per request.
|
|
1802
|
-
*
|
|
1803
|
-
* @param handle - X/Twitter handle (without @)
|
|
1804
|
-
*/
|
|
1805
|
-
async xAuthorAnalytics(handle) {
|
|
1806
|
-
const data = await this.requestWithPaymentRaw("/v1/x/authors", { handle });
|
|
1807
|
-
return data;
|
|
1808
|
-
}
|
|
1809
|
-
/**
|
|
1810
|
-
* Compare two X/Twitter authors side-by-side with intelligence metrics.
|
|
1811
|
-
*
|
|
1812
|
-
* Powered by AttentionVC intelligence layer. $0.05 per request.
|
|
1813
|
-
*
|
|
1814
|
-
* @param handle1 - First X/Twitter handle (without @)
|
|
1815
|
-
* @param handle2 - Second X/Twitter handle (without @)
|
|
1816
|
-
*/
|
|
1817
|
-
async xCompareAuthors(handle1, handle2) {
|
|
1818
|
-
const data = await this.requestWithPaymentRaw("/v1/x/compare", { handle1, handle2 });
|
|
1819
|
-
return data;
|
|
1820
|
-
}
|
|
1821
|
-
// ── Prediction Markets (Powered by Predexon) ────────────────────────────
|
|
1822
1622
|
/**
|
|
1823
1623
|
* Query Predexon prediction market data (GET endpoints).
|
|
1824
1624
|
*
|
|
@@ -1903,6 +1703,120 @@ var LLMClient = class _LLMClient {
|
|
|
1903
1703
|
async pmWalletCluster(address) {
|
|
1904
1704
|
return this.pm(`polymarket/wallet/${address}/cluster`);
|
|
1905
1705
|
}
|
|
1706
|
+
// ============================================================
|
|
1707
|
+
// DefiLlama (DeFi protocols / TVL / yields / prices)
|
|
1708
|
+
// ============================================================
|
|
1709
|
+
/**
|
|
1710
|
+
* Query DefiLlama DeFi data (GET passthrough). Powered by DefiLlama.
|
|
1711
|
+
* $0.005/call for protocols / protocol/{slug} / chains / yields;
|
|
1712
|
+
* $0.001/call for prices/{coins}.
|
|
1713
|
+
*
|
|
1714
|
+
* @param path - e.g. "protocols", "protocol/aave", "chains", "yields",
|
|
1715
|
+
* "prices/coingecko:bitcoin,base:0x..."
|
|
1716
|
+
* @param params - Query parameters passed through to DefiLlama
|
|
1717
|
+
*/
|
|
1718
|
+
async defi(path5, params) {
|
|
1719
|
+
return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
|
|
1720
|
+
}
|
|
1721
|
+
/** All DeFi protocols with TVL ($0.005/call). */
|
|
1722
|
+
async defiProtocols() {
|
|
1723
|
+
return this.defi("protocols");
|
|
1724
|
+
}
|
|
1725
|
+
/** Single protocol details + historical TVL ($0.005/call). */
|
|
1726
|
+
async defiProtocol(slug) {
|
|
1727
|
+
return this.defi(`protocol/${slug}`);
|
|
1728
|
+
}
|
|
1729
|
+
/** Current TVL of every chain ($0.005/call). */
|
|
1730
|
+
async defiChains() {
|
|
1731
|
+
return this.defi("chains");
|
|
1732
|
+
}
|
|
1733
|
+
/** Yield pools with APY/TVL ($0.005/call). */
|
|
1734
|
+
async defiYields(params) {
|
|
1735
|
+
return this.defi("yields", params);
|
|
1736
|
+
}
|
|
1737
|
+
/** Token price lookup ($0.001/call). Coins like "coingecko:bitcoin" or "{chain}:{address}". */
|
|
1738
|
+
async defiPrices(coins) {
|
|
1739
|
+
const joined = Array.isArray(coins) ? coins.join(",") : coins;
|
|
1740
|
+
return this.defi(`prices/${joined}`);
|
|
1741
|
+
}
|
|
1742
|
+
// ============================================================
|
|
1743
|
+
// 0x DEX (swap quotes + gasless) — free passthrough
|
|
1744
|
+
// ============================================================
|
|
1745
|
+
/**
|
|
1746
|
+
* Query the 0x Swap / Gasless APIs (free — no x402 payment; BlockRun
|
|
1747
|
+
* takes an on-chain affiliate fee on executed swaps instead).
|
|
1748
|
+
*
|
|
1749
|
+
* @param path - "price", "quote", "gasless/price", "gasless/quote",
|
|
1750
|
+
* "gasless/submit" (POST), "gasless/status/{hash}",
|
|
1751
|
+
* "gasless/approval-tokens", "gasless/chains", "swap/chains"
|
|
1752
|
+
* @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
|
|
1753
|
+
* @param body - JSON body — pass to switch to POST (gasless/submit only)
|
|
1754
|
+
*/
|
|
1755
|
+
async dex(path5, params, body) {
|
|
1756
|
+
if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
|
|
1757
|
+
return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
|
|
1758
|
+
}
|
|
1759
|
+
/** Indicative Permit2 swap price — no commitment (free). */
|
|
1760
|
+
async dexPrice(params) {
|
|
1761
|
+
return this.dex("price", params);
|
|
1762
|
+
}
|
|
1763
|
+
/** Firm Permit2 swap quote with permit2.eip712 + tx data (free). */
|
|
1764
|
+
async dexQuote(params) {
|
|
1765
|
+
return this.dex("quote", params);
|
|
1766
|
+
}
|
|
1767
|
+
/** Gasless indicative price quote (free). */
|
|
1768
|
+
async dexGaslessPrice(params) {
|
|
1769
|
+
return this.dex("gasless/price", params);
|
|
1770
|
+
}
|
|
1771
|
+
/** Gasless firm quote — returns trade.eip712 to sign (free). */
|
|
1772
|
+
async dexGaslessQuote(params) {
|
|
1773
|
+
return this.dex("gasless/quote", params);
|
|
1774
|
+
}
|
|
1775
|
+
/** Submit a signed gasless trade; the 0x relayer pays gas (free). */
|
|
1776
|
+
async dexGaslessSubmit(body) {
|
|
1777
|
+
return this.dex("gasless/submit", void 0, body);
|
|
1778
|
+
}
|
|
1779
|
+
/** Poll a gasless trade's status by tradeHash (free). */
|
|
1780
|
+
async dexGaslessStatus(tradeHash) {
|
|
1781
|
+
return this.dex(`gasless/status/${tradeHash}`);
|
|
1782
|
+
}
|
|
1783
|
+
/** Chains where the Swap API is supported (free). */
|
|
1784
|
+
async dexChains() {
|
|
1785
|
+
return this.dex("swap/chains");
|
|
1786
|
+
}
|
|
1787
|
+
/** Chains where the Gasless API is supported (free). */
|
|
1788
|
+
async dexGaslessChains() {
|
|
1789
|
+
return this.dex("gasless/chains");
|
|
1790
|
+
}
|
|
1791
|
+
// ============================================================
|
|
1792
|
+
// Modal Sandbox (pay-per-call cloud compute)
|
|
1793
|
+
// ============================================================
|
|
1794
|
+
/**
|
|
1795
|
+
* Call the Modal sandbox compute API (POST passthrough).
|
|
1796
|
+
*
|
|
1797
|
+
* @param path - "sandbox/create" ($0.01 CPU / $0.05 GPU), "sandbox/exec",
|
|
1798
|
+
* "sandbox/status", "sandbox/terminate" ($0.001 each)
|
|
1799
|
+
* @param body - JSON body for the endpoint
|
|
1800
|
+
*/
|
|
1801
|
+
async modal(path5, body) {
|
|
1802
|
+
return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
|
|
1803
|
+
}
|
|
1804
|
+
/** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
|
|
1805
|
+
async modalSandboxCreate(body) {
|
|
1806
|
+
return this.modal("sandbox/create", body);
|
|
1807
|
+
}
|
|
1808
|
+
/** Execute a command in a sandbox; returns stdout/stderr ($0.001). */
|
|
1809
|
+
async modalSandboxExec(sandboxId, command, extra) {
|
|
1810
|
+
return this.modal("sandbox/exec", { sandbox_id: sandboxId, command, ...extra });
|
|
1811
|
+
}
|
|
1812
|
+
/** Check a sandbox's status ($0.001). */
|
|
1813
|
+
async modalSandboxStatus(sandboxId) {
|
|
1814
|
+
return this.modal("sandbox/status", { sandbox_id: sandboxId });
|
|
1815
|
+
}
|
|
1816
|
+
/** Terminate a sandbox ($0.001). */
|
|
1817
|
+
async modalSandboxTerminate(sandboxId) {
|
|
1818
|
+
return this.modal("sandbox/terminate", { sandbox_id: sandboxId });
|
|
1819
|
+
}
|
|
1906
1820
|
/**
|
|
1907
1821
|
* Get current session spending.
|
|
1908
1822
|
*
|
|
@@ -3544,217 +3458,10 @@ var SearchClient = class {
|
|
|
3544
3458
|
}
|
|
3545
3459
|
};
|
|
3546
3460
|
|
|
3547
|
-
// src/
|
|
3461
|
+
// src/price.ts
|
|
3548
3462
|
var import_accounts11 = require("viem/accounts");
|
|
3549
3463
|
var DEFAULT_API_URL10 = "https://blockrun.ai/api";
|
|
3550
|
-
var DEFAULT_TIMEOUT10 =
|
|
3551
|
-
var XClient = class _XClient {
|
|
3552
|
-
account;
|
|
3553
|
-
privateKey;
|
|
3554
|
-
apiUrl;
|
|
3555
|
-
timeout;
|
|
3556
|
-
static deprecationWarned = false;
|
|
3557
|
-
constructor(options = {}) {
|
|
3558
|
-
if (!_XClient.deprecationWarned) {
|
|
3559
|
-
console.warn(
|
|
3560
|
-
"[@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."
|
|
3561
|
-
);
|
|
3562
|
-
_XClient.deprecationWarned = true;
|
|
3563
|
-
}
|
|
3564
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
|
|
3565
|
-
const privateKey = options.privateKey || envKey;
|
|
3566
|
-
if (!privateKey) {
|
|
3567
|
-
throw new Error(
|
|
3568
|
-
"Private key required. Pass privateKey in options or set BLOCKRUN_WALLET_KEY environment variable."
|
|
3569
|
-
);
|
|
3570
|
-
}
|
|
3571
|
-
validatePrivateKey(privateKey);
|
|
3572
|
-
this.privateKey = privateKey;
|
|
3573
|
-
this.account = (0, import_accounts11.privateKeyToAccount)(privateKey);
|
|
3574
|
-
const apiUrl = options.apiUrl || DEFAULT_API_URL10;
|
|
3575
|
-
validateApiUrl(apiUrl);
|
|
3576
|
-
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
3577
|
-
this.timeout = options.timeout || DEFAULT_TIMEOUT10;
|
|
3578
|
-
}
|
|
3579
|
-
// ───────── User endpoints ─────────
|
|
3580
|
-
userLookup(usernames) {
|
|
3581
|
-
return this.post("/v1/x/users/lookup", { usernames });
|
|
3582
|
-
}
|
|
3583
|
-
userInfo(username) {
|
|
3584
|
-
return this.post("/v1/x/users/info", { username });
|
|
3585
|
-
}
|
|
3586
|
-
followers(username, cursor) {
|
|
3587
|
-
const body = { username };
|
|
3588
|
-
if (cursor) body.cursor = cursor;
|
|
3589
|
-
return this.post("/v1/x/users/followers", body);
|
|
3590
|
-
}
|
|
3591
|
-
/** `/v1/x/users/following` (singular path variant). */
|
|
3592
|
-
following(username, cursor) {
|
|
3593
|
-
const body = { username };
|
|
3594
|
-
if (cursor) body.cursor = cursor;
|
|
3595
|
-
return this.post("/v1/x/users/following", body);
|
|
3596
|
-
}
|
|
3597
|
-
/** `/v1/x/users/followings` (plural path variant). */
|
|
3598
|
-
followings(username, cursor) {
|
|
3599
|
-
const body = { username };
|
|
3600
|
-
if (cursor) body.cursor = cursor;
|
|
3601
|
-
return this.post("/v1/x/users/followings", body);
|
|
3602
|
-
}
|
|
3603
|
-
verifiedFollowers(userId, cursor) {
|
|
3604
|
-
const body = { userId };
|
|
3605
|
-
if (cursor) body.cursor = cursor;
|
|
3606
|
-
return this.post(
|
|
3607
|
-
"/v1/x/users/verified-followers",
|
|
3608
|
-
body
|
|
3609
|
-
);
|
|
3610
|
-
}
|
|
3611
|
-
userTweets(options) {
|
|
3612
|
-
if (!options.username && !options.userId) {
|
|
3613
|
-
throw new Error("Either username or userId is required");
|
|
3614
|
-
}
|
|
3615
|
-
const body = {};
|
|
3616
|
-
if (options.username) body.username = options.username;
|
|
3617
|
-
if (options.userId) body.userId = options.userId;
|
|
3618
|
-
if (options.cursor) body.cursor = options.cursor;
|
|
3619
|
-
if (options.includeReplies !== void 0) body.includeReplies = options.includeReplies;
|
|
3620
|
-
return this.post("/v1/x/users/tweets", body);
|
|
3621
|
-
}
|
|
3622
|
-
mentions(username, options) {
|
|
3623
|
-
const body = { username };
|
|
3624
|
-
if (options?.sinceTime) body.sinceTime = options.sinceTime;
|
|
3625
|
-
if (options?.untilTime) body.untilTime = options.untilTime;
|
|
3626
|
-
if (options?.cursor) body.cursor = options.cursor;
|
|
3627
|
-
return this.post("/v1/x/users/mentions", body);
|
|
3628
|
-
}
|
|
3629
|
-
// ───────── Tweet endpoints ─────────
|
|
3630
|
-
tweetLookup(tweetIds) {
|
|
3631
|
-
return this.post("/v1/x/tweets/lookup", {
|
|
3632
|
-
tweet_ids: tweetIds
|
|
3633
|
-
});
|
|
3634
|
-
}
|
|
3635
|
-
tweetReplies(tweetId, options) {
|
|
3636
|
-
const body = { tweetId };
|
|
3637
|
-
if (options?.cursor) body.cursor = options.cursor;
|
|
3638
|
-
if (options?.queryType) body.queryType = options.queryType;
|
|
3639
|
-
return this.post("/v1/x/tweets/replies", body);
|
|
3640
|
-
}
|
|
3641
|
-
tweetThread(tweetId, cursor) {
|
|
3642
|
-
const body = { tweetId };
|
|
3643
|
-
if (cursor) body.cursor = cursor;
|
|
3644
|
-
return this.post("/v1/x/tweets/thread", body);
|
|
3645
|
-
}
|
|
3646
|
-
// ───────── Search & discovery ─────────
|
|
3647
|
-
search(query, options) {
|
|
3648
|
-
const body = { query };
|
|
3649
|
-
if (options?.queryType) body.queryType = options.queryType;
|
|
3650
|
-
if (options?.cursor) body.cursor = options.cursor;
|
|
3651
|
-
return this.post("/v1/x/search", body);
|
|
3652
|
-
}
|
|
3653
|
-
trending() {
|
|
3654
|
-
return this.post("/v1/x/trending", {});
|
|
3655
|
-
}
|
|
3656
|
-
articlesRising() {
|
|
3657
|
-
return this.post("/v1/x/articles/rising", {});
|
|
3658
|
-
}
|
|
3659
|
-
// ───────── Internals ─────────
|
|
3660
|
-
async post(endpoint, body) {
|
|
3661
|
-
const url = `${this.apiUrl}${endpoint}`;
|
|
3662
|
-
const response = await this.fetchWithTimeout(url, {
|
|
3663
|
-
method: "POST",
|
|
3664
|
-
headers: { "Content-Type": "application/json" },
|
|
3665
|
-
body: JSON.stringify(body)
|
|
3666
|
-
});
|
|
3667
|
-
if (response.status === 402) {
|
|
3668
|
-
return this.payAndRetry(url, body, response);
|
|
3669
|
-
}
|
|
3670
|
-
if (!response.ok) {
|
|
3671
|
-
let errorBody;
|
|
3672
|
-
try {
|
|
3673
|
-
errorBody = await response.json();
|
|
3674
|
-
} catch {
|
|
3675
|
-
errorBody = { error: "Request failed" };
|
|
3676
|
-
}
|
|
3677
|
-
throw new APIError(
|
|
3678
|
-
`API error: ${response.status}`,
|
|
3679
|
-
response.status,
|
|
3680
|
-
sanitizeErrorResponse(errorBody)
|
|
3681
|
-
);
|
|
3682
|
-
}
|
|
3683
|
-
return response.json();
|
|
3684
|
-
}
|
|
3685
|
-
async payAndRetry(url, body, response) {
|
|
3686
|
-
let paymentHeader = response.headers.get("payment-required");
|
|
3687
|
-
if (!paymentHeader) {
|
|
3688
|
-
try {
|
|
3689
|
-
const respBody = await response.json();
|
|
3690
|
-
if (respBody.x402 || respBody.accepts) {
|
|
3691
|
-
paymentHeader = btoa(JSON.stringify(respBody));
|
|
3692
|
-
}
|
|
3693
|
-
} catch {
|
|
3694
|
-
}
|
|
3695
|
-
}
|
|
3696
|
-
if (!paymentHeader) {
|
|
3697
|
-
throw new PaymentError("402 response but no payment requirements found");
|
|
3698
|
-
}
|
|
3699
|
-
const paymentRequired = parsePaymentRequired(paymentHeader);
|
|
3700
|
-
const details = extractPaymentDetails(paymentRequired);
|
|
3701
|
-
const paymentPayload = await createPaymentPayload(
|
|
3702
|
-
this.privateKey,
|
|
3703
|
-
this.account.address,
|
|
3704
|
-
details.recipient,
|
|
3705
|
-
details.amount,
|
|
3706
|
-
details.network || "eip155:8453",
|
|
3707
|
-
{
|
|
3708
|
-
resourceUrl: details.resource?.url || url,
|
|
3709
|
-
resourceDescription: details.resource?.description || "BlockRun X API",
|
|
3710
|
-
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
3711
|
-
extra: details.extra
|
|
3712
|
-
}
|
|
3713
|
-
);
|
|
3714
|
-
const retry = await this.fetchWithTimeout(url, {
|
|
3715
|
-
method: "POST",
|
|
3716
|
-
headers: {
|
|
3717
|
-
"Content-Type": "application/json",
|
|
3718
|
-
"PAYMENT-SIGNATURE": paymentPayload
|
|
3719
|
-
},
|
|
3720
|
-
body: JSON.stringify(body)
|
|
3721
|
-
});
|
|
3722
|
-
if (retry.status === 402) {
|
|
3723
|
-
throw new PaymentError("Payment was rejected. Check your wallet balance.");
|
|
3724
|
-
}
|
|
3725
|
-
if (!retry.ok) {
|
|
3726
|
-
let errorBody;
|
|
3727
|
-
try {
|
|
3728
|
-
errorBody = await retry.json();
|
|
3729
|
-
} catch {
|
|
3730
|
-
errorBody = { error: "Request failed" };
|
|
3731
|
-
}
|
|
3732
|
-
throw new APIError(
|
|
3733
|
-
`API error after payment: ${retry.status}`,
|
|
3734
|
-
retry.status,
|
|
3735
|
-
sanitizeErrorResponse(errorBody)
|
|
3736
|
-
);
|
|
3737
|
-
}
|
|
3738
|
-
return retry.json();
|
|
3739
|
-
}
|
|
3740
|
-
async fetchWithTimeout(url, init) {
|
|
3741
|
-
const controller = new AbortController();
|
|
3742
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
3743
|
-
try {
|
|
3744
|
-
return await fetch(url, { ...init, signal: controller.signal });
|
|
3745
|
-
} finally {
|
|
3746
|
-
clearTimeout(timeoutId);
|
|
3747
|
-
}
|
|
3748
|
-
}
|
|
3749
|
-
getWalletAddress() {
|
|
3750
|
-
return this.account.address;
|
|
3751
|
-
}
|
|
3752
|
-
};
|
|
3753
|
-
|
|
3754
|
-
// src/price.ts
|
|
3755
|
-
var import_accounts12 = require("viem/accounts");
|
|
3756
|
-
var DEFAULT_API_URL11 = "https://blockrun.ai/api";
|
|
3757
|
-
var DEFAULT_TIMEOUT11 = 3e4;
|
|
3464
|
+
var DEFAULT_TIMEOUT10 = 3e4;
|
|
3758
3465
|
var PriceClient = class {
|
|
3759
3466
|
account = null;
|
|
3760
3467
|
privateKey = null;
|
|
@@ -3772,12 +3479,12 @@ var PriceClient = class {
|
|
|
3772
3479
|
if (privateKey) {
|
|
3773
3480
|
validatePrivateKey(privateKey);
|
|
3774
3481
|
this.privateKey = privateKey;
|
|
3775
|
-
this.account = (0,
|
|
3482
|
+
this.account = (0, import_accounts11.privateKeyToAccount)(privateKey);
|
|
3776
3483
|
}
|
|
3777
|
-
const apiUrl = options.apiUrl ||
|
|
3484
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL10;
|
|
3778
3485
|
validateApiUrl(apiUrl);
|
|
3779
3486
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
3780
|
-
this.timeout = options.timeout ||
|
|
3487
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT10;
|
|
3781
3488
|
}
|
|
3782
3489
|
async price(category, symbol, options) {
|
|
3783
3490
|
if (!symbol) throw new Error("symbol is required");
|
|
@@ -3956,9 +3663,9 @@ function buildUrl(base, query) {
|
|
|
3956
3663
|
}
|
|
3957
3664
|
|
|
3958
3665
|
// src/surf.ts
|
|
3959
|
-
var
|
|
3960
|
-
var
|
|
3961
|
-
var
|
|
3666
|
+
var import_accounts12 = require("viem/accounts");
|
|
3667
|
+
var DEFAULT_API_URL11 = "https://blockrun.ai/api";
|
|
3668
|
+
var DEFAULT_TIMEOUT11 = 6e4;
|
|
3962
3669
|
var SURF_PREFIX = "/v1/surf";
|
|
3963
3670
|
var SurfClient = class {
|
|
3964
3671
|
account;
|
|
@@ -3975,11 +3682,11 @@ var SurfClient = class {
|
|
|
3975
3682
|
}
|
|
3976
3683
|
validatePrivateKey(privateKey);
|
|
3977
3684
|
this.privateKey = privateKey;
|
|
3978
|
-
this.account = (0,
|
|
3979
|
-
const apiUrl = options.apiUrl ||
|
|
3685
|
+
this.account = (0, import_accounts12.privateKeyToAccount)(privateKey);
|
|
3686
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL11;
|
|
3980
3687
|
validateApiUrl(apiUrl);
|
|
3981
3688
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
3982
|
-
this.timeout = options.timeout ||
|
|
3689
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT11;
|
|
3983
3690
|
}
|
|
3984
3691
|
/**
|
|
3985
3692
|
* GET a Surf endpoint. `path` is everything after `/v1/surf` (a leading
|
|
@@ -4111,9 +3818,9 @@ var SurfClient = class {
|
|
|
4111
3818
|
};
|
|
4112
3819
|
|
|
4113
3820
|
// src/rpc.ts
|
|
4114
|
-
var
|
|
4115
|
-
var
|
|
4116
|
-
var
|
|
3821
|
+
var import_accounts13 = require("viem/accounts");
|
|
3822
|
+
var DEFAULT_API_URL12 = "https://blockrun.ai/api";
|
|
3823
|
+
var DEFAULT_TIMEOUT12 = 6e4;
|
|
4117
3824
|
var RPC_PRICE_USD = 2e-3;
|
|
4118
3825
|
var SUPPORTED_NETWORKS = [
|
|
4119
3826
|
// EVM
|
|
@@ -4205,11 +3912,11 @@ var RpcClient = class {
|
|
|
4205
3912
|
}
|
|
4206
3913
|
validatePrivateKey(privateKey);
|
|
4207
3914
|
this.privateKey = privateKey;
|
|
4208
|
-
this.account = (0,
|
|
4209
|
-
const apiUrl = options.apiUrl ||
|
|
3915
|
+
this.account = (0, import_accounts13.privateKeyToAccount)(privateKey);
|
|
3916
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL12;
|
|
4210
3917
|
validateApiUrl(apiUrl);
|
|
4211
3918
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
4212
|
-
this.timeout = options.timeout ||
|
|
3919
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT12;
|
|
4213
3920
|
}
|
|
4214
3921
|
/**
|
|
4215
3922
|
* Make a single JSON-RPC 2.0 call. Flat $0.002.
|
|
@@ -4364,9 +4071,9 @@ var RpcClient = class {
|
|
|
4364
4071
|
};
|
|
4365
4072
|
|
|
4366
4073
|
// src/blockrun.ts
|
|
4367
|
-
var
|
|
4368
|
-
var
|
|
4369
|
-
var
|
|
4074
|
+
var import_accounts14 = require("viem/accounts");
|
|
4075
|
+
var DEFAULT_API_URL13 = "https://blockrun.ai/api";
|
|
4076
|
+
var DEFAULT_TIMEOUT13 = 6e4;
|
|
4370
4077
|
var DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
4371
4078
|
var DEFAULT_POLL_BUDGET_MS = 3e5;
|
|
4372
4079
|
var MAX_SIGNED_AUTH_SECONDS = 600;
|
|
@@ -4387,11 +4094,11 @@ var BlockrunClient = class {
|
|
|
4387
4094
|
}
|
|
4388
4095
|
validatePrivateKey(privateKey);
|
|
4389
4096
|
this.privateKey = privateKey;
|
|
4390
|
-
this.account = (0,
|
|
4391
|
-
const apiUrl = options.apiUrl ||
|
|
4097
|
+
this.account = (0, import_accounts14.privateKeyToAccount)(privateKey);
|
|
4098
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL13;
|
|
4392
4099
|
validateApiUrl(apiUrl);
|
|
4393
4100
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
4394
|
-
this.timeout = options.timeout ||
|
|
4101
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT13;
|
|
4395
4102
|
}
|
|
4396
4103
|
/**
|
|
4397
4104
|
* GET a BlockRun endpoint. `path` is everything after `/api` (a leading
|
|
@@ -4742,7 +4449,7 @@ function sleep(ms) {
|
|
|
4742
4449
|
}
|
|
4743
4450
|
|
|
4744
4451
|
// src/wallet.ts
|
|
4745
|
-
var
|
|
4452
|
+
var import_accounts15 = require("viem/accounts");
|
|
4746
4453
|
var fs2 = __toESM(require("fs"), 1);
|
|
4747
4454
|
var path2 = __toESM(require("path"), 1);
|
|
4748
4455
|
var os2 = __toESM(require("os"), 1);
|
|
@@ -4751,8 +4458,8 @@ var BASE_CHAIN_ID2 = "8453";
|
|
|
4751
4458
|
var WALLET_DIR = path2.join(os2.homedir(), ".blockrun");
|
|
4752
4459
|
var WALLET_FILE = path2.join(WALLET_DIR, ".session");
|
|
4753
4460
|
function createWallet() {
|
|
4754
|
-
const privateKey = (0,
|
|
4755
|
-
const account = (0,
|
|
4461
|
+
const privateKey = (0, import_accounts15.generatePrivateKey)();
|
|
4462
|
+
const account = (0, import_accounts15.privateKeyToAccount)(privateKey);
|
|
4756
4463
|
return {
|
|
4757
4464
|
address: account.address,
|
|
4758
4465
|
privateKey
|
|
@@ -4808,12 +4515,12 @@ function loadWallet() {
|
|
|
4808
4515
|
function getOrCreateWallet() {
|
|
4809
4516
|
const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
|
|
4810
4517
|
if (envKey) {
|
|
4811
|
-
const account = (0,
|
|
4518
|
+
const account = (0, import_accounts15.privateKeyToAccount)(envKey);
|
|
4812
4519
|
return { address: account.address, privateKey: envKey, isNew: false };
|
|
4813
4520
|
}
|
|
4814
4521
|
const fileKey = loadWallet();
|
|
4815
4522
|
if (fileKey) {
|
|
4816
|
-
const account = (0,
|
|
4523
|
+
const account = (0, import_accounts15.privateKeyToAccount)(fileKey);
|
|
4817
4524
|
return { address: account.address, privateKey: fileKey, isNew: false };
|
|
4818
4525
|
}
|
|
4819
4526
|
const { address, privateKey } = createWallet();
|
|
@@ -4823,11 +4530,11 @@ function getOrCreateWallet() {
|
|
|
4823
4530
|
function getWalletAddress() {
|
|
4824
4531
|
const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
|
|
4825
4532
|
if (envKey) {
|
|
4826
|
-
return (0,
|
|
4533
|
+
return (0, import_accounts15.privateKeyToAccount)(envKey).address;
|
|
4827
4534
|
}
|
|
4828
4535
|
const fileKey = loadWallet();
|
|
4829
4536
|
if (fileKey) {
|
|
4830
|
-
return (0,
|
|
4537
|
+
return (0, import_accounts15.privateKeyToAccount)(fileKey).address;
|
|
4831
4538
|
}
|
|
4832
4539
|
return null;
|
|
4833
4540
|
}
|
|
@@ -5007,7 +4714,7 @@ async function getOrCreateSolanaWallet() {
|
|
|
5007
4714
|
// src/solana-client.ts
|
|
5008
4715
|
var SOLANA_API_URL = "https://sol.blockrun.ai/api";
|
|
5009
4716
|
var DEFAULT_MAX_TOKENS2 = 1024;
|
|
5010
|
-
var
|
|
4717
|
+
var DEFAULT_TIMEOUT14 = 6e4;
|
|
5011
4718
|
var SDK_VERSION2 = "0.3.0";
|
|
5012
4719
|
var USER_AGENT2 = `blockrun-ts/${SDK_VERSION2}`;
|
|
5013
4720
|
var DEFAULT_SOLANA_RPC_URL = "https://sol.blockrun.ai/api/v1/solana/rpc";
|
|
@@ -5057,7 +4764,7 @@ var SolanaLLMClient = class {
|
|
|
5057
4764
|
const rpc = resolveRpcConfig(options.rpcUrl, options.rpcHeaders);
|
|
5058
4765
|
this.rpcUrl = rpc.url;
|
|
5059
4766
|
this.rpcHeaders = rpc.headers;
|
|
5060
|
-
this.timeout = options.timeout ||
|
|
4767
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT14;
|
|
5061
4768
|
}
|
|
5062
4769
|
/** Get Solana wallet address (public key in base58). */
|
|
5063
4770
|
async getWalletAddress() {
|
|
@@ -5157,89 +4864,6 @@ var SolanaLLMClient = class {
|
|
|
5157
4864
|
const data = await this.requestWithPaymentRaw("/v1/search", body);
|
|
5158
4865
|
return data;
|
|
5159
4866
|
}
|
|
5160
|
-
// ============================================================
|
|
5161
|
-
// X/Twitter endpoints (powered by AttentionVC)
|
|
5162
|
-
// ============================================================
|
|
5163
|
-
async xUserLookup(usernames) {
|
|
5164
|
-
const names = Array.isArray(usernames) ? usernames : [usernames];
|
|
5165
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/lookup", { usernames: names });
|
|
5166
|
-
return data;
|
|
5167
|
-
}
|
|
5168
|
-
async xFollowers(username, cursor) {
|
|
5169
|
-
const body = { username };
|
|
5170
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5171
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followers", body);
|
|
5172
|
-
return data;
|
|
5173
|
-
}
|
|
5174
|
-
async xFollowings(username, cursor) {
|
|
5175
|
-
const body = { username };
|
|
5176
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5177
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followings", body);
|
|
5178
|
-
return data;
|
|
5179
|
-
}
|
|
5180
|
-
async xUserInfo(username) {
|
|
5181
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/info", { username });
|
|
5182
|
-
return data;
|
|
5183
|
-
}
|
|
5184
|
-
async xVerifiedFollowers(userId, cursor) {
|
|
5185
|
-
const body = { userId };
|
|
5186
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5187
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/verified-followers", body);
|
|
5188
|
-
return data;
|
|
5189
|
-
}
|
|
5190
|
-
async xUserTweets(username, includeReplies = false, cursor) {
|
|
5191
|
-
const body = { username, includeReplies };
|
|
5192
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5193
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/tweets", body);
|
|
5194
|
-
return data;
|
|
5195
|
-
}
|
|
5196
|
-
async xUserMentions(username, sinceTime, untilTime, cursor) {
|
|
5197
|
-
const body = { username };
|
|
5198
|
-
if (sinceTime !== void 0) body.sinceTime = sinceTime;
|
|
5199
|
-
if (untilTime !== void 0) body.untilTime = untilTime;
|
|
5200
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5201
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/mentions", body);
|
|
5202
|
-
return data;
|
|
5203
|
-
}
|
|
5204
|
-
async xTweetLookup(tweetIds) {
|
|
5205
|
-
const ids = Array.isArray(tweetIds) ? tweetIds : [tweetIds];
|
|
5206
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/lookup", { tweet_ids: ids });
|
|
5207
|
-
return data;
|
|
5208
|
-
}
|
|
5209
|
-
async xTweetReplies(tweetId, queryType = "Latest", cursor) {
|
|
5210
|
-
const body = { tweetId, queryType };
|
|
5211
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5212
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/replies", body);
|
|
5213
|
-
return data;
|
|
5214
|
-
}
|
|
5215
|
-
async xTweetThread(tweetId, cursor) {
|
|
5216
|
-
const body = { tweetId };
|
|
5217
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5218
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/thread", body);
|
|
5219
|
-
return data;
|
|
5220
|
-
}
|
|
5221
|
-
async xSearch(query, queryType = "Latest", cursor) {
|
|
5222
|
-
const body = { query, queryType };
|
|
5223
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5224
|
-
const data = await this.requestWithPaymentRaw("/v1/x/search", body);
|
|
5225
|
-
return data;
|
|
5226
|
-
}
|
|
5227
|
-
async xTrending() {
|
|
5228
|
-
const data = await this.requestWithPaymentRaw("/v1/x/trending", {});
|
|
5229
|
-
return data;
|
|
5230
|
-
}
|
|
5231
|
-
async xArticlesRising() {
|
|
5232
|
-
const data = await this.requestWithPaymentRaw("/v1/x/articles/rising", {});
|
|
5233
|
-
return data;
|
|
5234
|
-
}
|
|
5235
|
-
async xAuthorAnalytics(handle) {
|
|
5236
|
-
const data = await this.requestWithPaymentRaw("/v1/x/authors", { handle });
|
|
5237
|
-
return data;
|
|
5238
|
-
}
|
|
5239
|
-
async xCompareAuthors(handle1, handle2) {
|
|
5240
|
-
const data = await this.requestWithPaymentRaw("/v1/x/compare", { handle1, handle2 });
|
|
5241
|
-
return data;
|
|
5242
|
-
}
|
|
5243
4867
|
// ── Prediction Markets (Powered by Predexon) ────────────────────────────
|
|
5244
4868
|
async pm(path5, params) {
|
|
5245
4869
|
return this.getWithPaymentRaw(`/v1/pm/${path5}`, params);
|
|
@@ -5296,6 +4920,120 @@ var SolanaLLMClient = class {
|
|
|
5296
4920
|
async exaAnswer(query, options) {
|
|
5297
4921
|
return this.requestWithPaymentRaw("/v1/exa/answer", { query, ...options });
|
|
5298
4922
|
}
|
|
4923
|
+
// ============================================================
|
|
4924
|
+
// DefiLlama (DeFi protocols / TVL / yields / prices)
|
|
4925
|
+
// ============================================================
|
|
4926
|
+
/**
|
|
4927
|
+
* Query DefiLlama DeFi data (GET passthrough). Powered by DefiLlama.
|
|
4928
|
+
* $0.005/call for protocols / protocol/{slug} / chains / yields;
|
|
4929
|
+
* $0.001/call for prices/{coins}.
|
|
4930
|
+
*
|
|
4931
|
+
* @param path - e.g. "protocols", "protocol/aave", "chains", "yields",
|
|
4932
|
+
* "prices/coingecko:bitcoin,base:0x..."
|
|
4933
|
+
* @param params - Query parameters passed through to DefiLlama
|
|
4934
|
+
*/
|
|
4935
|
+
async defi(path5, params) {
|
|
4936
|
+
return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
|
|
4937
|
+
}
|
|
4938
|
+
/** All DeFi protocols with TVL ($0.005/call). */
|
|
4939
|
+
async defiProtocols() {
|
|
4940
|
+
return this.defi("protocols");
|
|
4941
|
+
}
|
|
4942
|
+
/** Single protocol details + historical TVL ($0.005/call). */
|
|
4943
|
+
async defiProtocol(slug) {
|
|
4944
|
+
return this.defi(`protocol/${slug}`);
|
|
4945
|
+
}
|
|
4946
|
+
/** Current TVL of every chain ($0.005/call). */
|
|
4947
|
+
async defiChains() {
|
|
4948
|
+
return this.defi("chains");
|
|
4949
|
+
}
|
|
4950
|
+
/** Yield pools with APY/TVL ($0.005/call). */
|
|
4951
|
+
async defiYields(params) {
|
|
4952
|
+
return this.defi("yields", params);
|
|
4953
|
+
}
|
|
4954
|
+
/** Token price lookup ($0.001/call). Coins like "coingecko:bitcoin" or "{chain}:{address}". */
|
|
4955
|
+
async defiPrices(coins) {
|
|
4956
|
+
const joined = Array.isArray(coins) ? coins.join(",") : coins;
|
|
4957
|
+
return this.defi(`prices/${joined}`);
|
|
4958
|
+
}
|
|
4959
|
+
// ============================================================
|
|
4960
|
+
// 0x DEX (swap quotes + gasless) — free passthrough
|
|
4961
|
+
// ============================================================
|
|
4962
|
+
/**
|
|
4963
|
+
* Query the 0x Swap / Gasless APIs (free — no x402 payment; BlockRun
|
|
4964
|
+
* takes an on-chain affiliate fee on executed swaps instead).
|
|
4965
|
+
*
|
|
4966
|
+
* @param path - "price", "quote", "gasless/price", "gasless/quote",
|
|
4967
|
+
* "gasless/submit" (POST), "gasless/status/{hash}",
|
|
4968
|
+
* "gasless/approval-tokens", "gasless/chains", "swap/chains"
|
|
4969
|
+
* @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
|
|
4970
|
+
* @param body - JSON body — pass to switch to POST (gasless/submit only)
|
|
4971
|
+
*/
|
|
4972
|
+
async dex(path5, params, body) {
|
|
4973
|
+
if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
|
|
4974
|
+
return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
|
|
4975
|
+
}
|
|
4976
|
+
/** Indicative Permit2 swap price — no commitment (free). */
|
|
4977
|
+
async dexPrice(params) {
|
|
4978
|
+
return this.dex("price", params);
|
|
4979
|
+
}
|
|
4980
|
+
/** Firm Permit2 swap quote with permit2.eip712 + tx data (free). */
|
|
4981
|
+
async dexQuote(params) {
|
|
4982
|
+
return this.dex("quote", params);
|
|
4983
|
+
}
|
|
4984
|
+
/** Gasless indicative price quote (free). */
|
|
4985
|
+
async dexGaslessPrice(params) {
|
|
4986
|
+
return this.dex("gasless/price", params);
|
|
4987
|
+
}
|
|
4988
|
+
/** Gasless firm quote — returns trade.eip712 to sign (free). */
|
|
4989
|
+
async dexGaslessQuote(params) {
|
|
4990
|
+
return this.dex("gasless/quote", params);
|
|
4991
|
+
}
|
|
4992
|
+
/** Submit a signed gasless trade; the 0x relayer pays gas (free). */
|
|
4993
|
+
async dexGaslessSubmit(body) {
|
|
4994
|
+
return this.dex("gasless/submit", void 0, body);
|
|
4995
|
+
}
|
|
4996
|
+
/** Poll a gasless trade's status by tradeHash (free). */
|
|
4997
|
+
async dexGaslessStatus(tradeHash) {
|
|
4998
|
+
return this.dex(`gasless/status/${tradeHash}`);
|
|
4999
|
+
}
|
|
5000
|
+
/** Chains where the Swap API is supported (free). */
|
|
5001
|
+
async dexChains() {
|
|
5002
|
+
return this.dex("swap/chains");
|
|
5003
|
+
}
|
|
5004
|
+
/** Chains where the Gasless API is supported (free). */
|
|
5005
|
+
async dexGaslessChains() {
|
|
5006
|
+
return this.dex("gasless/chains");
|
|
5007
|
+
}
|
|
5008
|
+
// ============================================================
|
|
5009
|
+
// Modal Sandbox (pay-per-call cloud compute)
|
|
5010
|
+
// ============================================================
|
|
5011
|
+
/**
|
|
5012
|
+
* Call the Modal sandbox compute API (POST passthrough).
|
|
5013
|
+
*
|
|
5014
|
+
* @param path - "sandbox/create" ($0.01 CPU / $0.05 GPU), "sandbox/exec",
|
|
5015
|
+
* "sandbox/status", "sandbox/terminate" ($0.001 each)
|
|
5016
|
+
* @param body - JSON body for the endpoint
|
|
5017
|
+
*/
|
|
5018
|
+
async modal(path5, body) {
|
|
5019
|
+
return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
|
|
5020
|
+
}
|
|
5021
|
+
/** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
|
|
5022
|
+
async modalSandboxCreate(body) {
|
|
5023
|
+
return this.modal("sandbox/create", body);
|
|
5024
|
+
}
|
|
5025
|
+
/** Execute a command in a sandbox; returns stdout/stderr ($0.001). */
|
|
5026
|
+
async modalSandboxExec(sandboxId, command, extra) {
|
|
5027
|
+
return this.modal("sandbox/exec", { sandbox_id: sandboxId, command, ...extra });
|
|
5028
|
+
}
|
|
5029
|
+
/** Check a sandbox's status ($0.001). */
|
|
5030
|
+
async modalSandboxStatus(sandboxId) {
|
|
5031
|
+
return this.modal("sandbox/status", { sandbox_id: sandboxId });
|
|
5032
|
+
}
|
|
5033
|
+
/** Terminate a sandbox ($0.001). */
|
|
5034
|
+
async modalSandboxTerminate(sandboxId) {
|
|
5035
|
+
return this.modal("sandbox/terminate", { sandbox_id: sandboxId });
|
|
5036
|
+
}
|
|
5299
5037
|
/** Get session spending. */
|
|
5300
5038
|
getSpending() {
|
|
5301
5039
|
return { totalUsd: this.sessionTotalUsd, calls: this.sessionCalls };
|
|
@@ -5603,7 +5341,6 @@ var CACHE_DIR = path4.join(os4.homedir(), ".blockrun", "cache");
|
|
|
5603
5341
|
var DATA_DIR = path4.join(os4.homedir(), ".blockrun", "data");
|
|
5604
5342
|
var COST_LOG_FILE2 = path4.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
|
|
5605
5343
|
var DEFAULT_TTL = {
|
|
5606
|
-
"/v1/x/": 3600 * 1e3,
|
|
5607
5344
|
"/v1/partner/": 3600 * 1e3,
|
|
5608
5345
|
"/v1/pm/": 1800 * 1e3,
|
|
5609
5346
|
"/v1/chat/": 0,
|
|
@@ -5672,8 +5409,6 @@ function readableFilename(endpoint, body) {
|
|
|
5672
5409
|
let ep = endpoint.replace(/\/+$/, "").split("/").pop() || "";
|
|
5673
5410
|
if (endpoint.includes("/v1/chat/")) {
|
|
5674
5411
|
ep = "chat";
|
|
5675
|
-
} else if (endpoint.includes("/v1/x/")) {
|
|
5676
|
-
ep = "x_" + ep;
|
|
5677
5412
|
} else if (endpoint.includes("/v1/search")) {
|
|
5678
5413
|
ep = "search";
|
|
5679
5414
|
} else if (endpoint.includes("/v1/image")) {
|
|
@@ -5971,7 +5706,7 @@ var OpenAI = class {
|
|
|
5971
5706
|
};
|
|
5972
5707
|
|
|
5973
5708
|
// src/anthropic-compat.ts
|
|
5974
|
-
var
|
|
5709
|
+
var import_accounts16 = require("viem/accounts");
|
|
5975
5710
|
var AnthropicClient = class {
|
|
5976
5711
|
_client = null;
|
|
5977
5712
|
_clientPromise = null;
|
|
@@ -5984,7 +5719,7 @@ var AnthropicClient = class {
|
|
|
5984
5719
|
const key = options.privateKey ?? wallet.privateKey;
|
|
5985
5720
|
validatePrivateKey(key);
|
|
5986
5721
|
this._privateKey = key;
|
|
5987
|
-
this._account = (0,
|
|
5722
|
+
this._account = (0, import_accounts16.privateKeyToAccount)(this._privateKey);
|
|
5988
5723
|
const apiUrl = options.apiUrl ?? "https://blockrun.ai/api";
|
|
5989
5724
|
validateApiUrl(apiUrl);
|
|
5990
5725
|
this._apiUrl = apiUrl.replace(/\/$/, "");
|
|
@@ -6113,7 +5848,6 @@ var AnthropicClient = class {
|
|
|
6113
5848
|
VoiceClient,
|
|
6114
5849
|
WALLET_DIR_PATH,
|
|
6115
5850
|
WALLET_FILE_PATH,
|
|
6116
|
-
XClient,
|
|
6117
5851
|
clearCache,
|
|
6118
5852
|
createPaymentPayload,
|
|
6119
5853
|
createSolanaPaymentPayload,
|