@blockrun/llm 3.12.0 → 3.13.1

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
@@ -3850,7 +3850,7 @@ function getCostSummary() {
3850
3850
  }
3851
3851
 
3852
3852
  // src/version.ts
3853
- var SDK_VERSION = "3.12.0";
3853
+ var SDK_VERSION = "3.13.1";
3854
3854
  var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
3855
3855
 
3856
3856
  // src/client.ts
@@ -4940,8 +4940,8 @@ var LLMClient = class _LLMClient {
4940
4940
  * @example
4941
4941
  * const results = await client.exa("search", { query: "latest AI research", numResults: 5 });
4942
4942
  */
4943
- async exa(path5, body) {
4944
- return this.requestWithPaymentRaw(`/v1/exa/${path5}`, body);
4943
+ async exa(path6, body) {
4944
+ return this.requestWithPaymentRaw(`/v1/exa/${path6}`, body);
4945
4945
  }
4946
4946
  /**
4947
4947
  * Neural web search via Exa. Returns semantically relevant URLs and metadata.
@@ -5089,8 +5089,8 @@ var LLMClient = class _LLMClient {
5089
5089
  * const market = await client.pm("kalshi/markets/KXBTC-25MAR14");
5090
5090
  * const results = await client.pm("polymarket/search", { q: "bitcoin" });
5091
5091
  */
5092
- async pm(path5, params) {
5093
- return this.getWithPaymentRaw(`/v1/pm/${path5}`, params);
5092
+ async pm(path6, params) {
5093
+ return this.getWithPaymentRaw(`/v1/pm/${path6}`, params);
5094
5094
  }
5095
5095
  /**
5096
5096
  * Structured query for Predexon prediction market data (POST endpoints).
@@ -5106,8 +5106,8 @@ var LLMClient = class _LLMClient {
5106
5106
  * addresses: ["0xabc...", "0xdef..."],
5107
5107
  * });
5108
5108
  */
5109
- async pmQuery(path5, query) {
5110
- return this.requestWithPaymentRaw(`/v1/pm/${path5}`, query);
5109
+ async pmQuery(path6, query) {
5110
+ return this.requestWithPaymentRaw(`/v1/pm/${path6}`, query);
5111
5111
  }
5112
5112
  // ── PM convenience helpers (Predexon v2) ─────────────────────────────────
5113
5113
  // Thin wrappers over pm() / pmQuery() for the most common v2 endpoints.
@@ -5195,8 +5195,8 @@ var LLMClient = class _LLMClient {
5195
5195
  * "prices/coingecko:bitcoin,base:0x..."
5196
5196
  * @param params - Query parameters passed through to DefiLlama
5197
5197
  */
5198
- async defi(path5, params) {
5199
- return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
5198
+ async defi(path6, params) {
5199
+ return this.getWithPaymentRaw(`/v1/defillama/${path6}`, params);
5200
5200
  }
5201
5201
  /** All DeFi protocols with TVL ($0.005/call). */
5202
5202
  async defiProtocols() {
@@ -5232,9 +5232,9 @@ var LLMClient = class _LLMClient {
5232
5232
  * @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
5233
5233
  * @param body - JSON body — pass to switch to POST (gasless/submit only)
5234
5234
  */
5235
- async dex(path5, params, body) {
5236
- if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
5237
- return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
5235
+ async dex(path6, params, body) {
5236
+ if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path6}`, body);
5237
+ return this.getWithPaymentRaw(`/v1/zerox/${path6}`, params);
5238
5238
  }
5239
5239
  /** Indicative Permit2 swap price — no commitment (free). */
5240
5240
  async dexPrice(params) {
@@ -5278,8 +5278,8 @@ var LLMClient = class _LLMClient {
5278
5278
  * "sandbox/status", "sandbox/terminate" ($0.001 each)
5279
5279
  * @param body - JSON body for the endpoint
5280
5280
  */
5281
- async modal(path5, body) {
5282
- return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
5281
+ async modal(path6, body) {
5282
+ return this.requestWithPaymentRaw(`/v1/modal/${path6}`, body ?? {});
5283
5283
  }
5284
5284
  /** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
5285
5285
  async modalSandboxCreate(body) {
@@ -6641,8 +6641,8 @@ var PhoneClient = class {
6641
6641
  return data;
6642
6642
  }
6643
6643
  // ─── Internals ─────────────────────────────────────────────────────────
6644
- async request(path5, body) {
6645
- const url = `${this.apiUrl}/v1/phone/${path5}`;
6644
+ async request(path6, body) {
6645
+ const url = `${this.apiUrl}/v1/phone/${path6}`;
6646
6646
  const response = await this.fetchWithTimeout(url, {
6647
6647
  method: "POST",
6648
6648
  headers: { "Content-Type": "application/json" },
@@ -7049,10 +7049,10 @@ var PriceClient = class {
7049
7049
  }
7050
7050
  async price(category, symbol, options) {
7051
7051
  if (!symbol) throw new Error("symbol is required");
7052
- const path5 = categoryPath(category, options?.market, "price", symbol);
7052
+ const path6 = categoryPath(category, options?.market, "price", symbol);
7053
7053
  const query = {};
7054
7054
  if (options?.session) query.session = options.session;
7055
- const data = await this.getWithPayment(path5, query);
7055
+ const data = await this.getWithPayment(path6, query);
7056
7056
  return {
7057
7057
  symbol: data.symbol ?? symbol.toUpperCase(),
7058
7058
  price: data.price,
@@ -7071,14 +7071,14 @@ var PriceClient = class {
7071
7071
  if (!options.from || options.from <= 0) {
7072
7072
  throw new Error("history requires options.from (unix seconds)");
7073
7073
  }
7074
- const path5 = categoryPath(category, options.market, "history", symbol);
7074
+ const path6 = categoryPath(category, options.market, "history", symbol);
7075
7075
  const query = {
7076
7076
  resolution: options.resolution ?? "D",
7077
7077
  from: String(options.from)
7078
7078
  };
7079
7079
  if (options.to) query.to = String(options.to);
7080
7080
  if (options.session) query.session = options.session;
7081
- const data = await this.getWithPayment(path5, query);
7081
+ const data = await this.getWithPayment(path6, query);
7082
7082
  return {
7083
7083
  symbol: data.symbol ?? symbol.toUpperCase(),
7084
7084
  resolution: data.resolution ?? (options.resolution ?? "D"),
@@ -7090,12 +7090,12 @@ var PriceClient = class {
7090
7090
  };
7091
7091
  }
7092
7092
  async listSymbols(category, options) {
7093
- const path5 = categoryPath(category, options?.market, "list");
7093
+ const path6 = categoryPath(category, options?.market, "list");
7094
7094
  const query = {
7095
7095
  limit: String(options?.limit && options.limit > 0 ? options.limit : 100)
7096
7096
  };
7097
7097
  if (options?.query) query.q = options.query;
7098
- const data = await this.getWithPayment(path5, query);
7098
+ const data = await this.getWithPayment(path6, query);
7099
7099
  if (Array.isArray(data)) {
7100
7100
  return { symbols: data, count: data.length };
7101
7101
  }
@@ -7254,19 +7254,19 @@ var SurfClient = class {
7254
7254
  * `/v1/surf` is tolerated and stripped). Query params are URL-encoded;
7255
7255
  * arrays become repeated keys (`?a=1&a=2`).
7256
7256
  */
7257
- async get(path5, params) {
7258
- const url = this.buildUrl(path5, params);
7257
+ async get(path6, params) {
7258
+ const url = this.buildUrl(path6, params);
7259
7259
  return this.requestWithPayment(url, "GET");
7260
7260
  }
7261
7261
  /**
7262
7262
  * POST a Surf endpoint with a JSON body. Same path normalization as `get`.
7263
7263
  */
7264
- async post(path5, body) {
7265
- const url = this.buildUrl(path5);
7264
+ async post(path6, body) {
7265
+ const url = this.buildUrl(path6);
7266
7266
  return this.requestWithPayment(url, "POST", body);
7267
7267
  }
7268
- buildUrl(path5, params) {
7269
- let normalized = path5.startsWith("/") ? path5 : `/${path5}`;
7268
+ buildUrl(path6, params) {
7269
+ let normalized = path6.startsWith("/") ? path6 : `/${path6}`;
7270
7270
  if (!normalized.startsWith(SURF_PREFIX)) {
7271
7271
  normalized = `${SURF_PREFIX}${normalized}`;
7272
7272
  }
@@ -7666,15 +7666,15 @@ var BlockrunClient = class {
7666
7666
  * `/api` is tolerated and stripped). Query params are URL-encoded; arrays
7667
7667
  * become repeated keys (`?a=1&a=2`); undefined/null are dropped.
7668
7668
  */
7669
- async get(path5, params) {
7670
- const url = this.buildUrl(path5, params);
7669
+ async get(path6, params) {
7670
+ const url = this.buildUrl(path6, params);
7671
7671
  return this.requestWithPayment(url, "GET");
7672
7672
  }
7673
7673
  /**
7674
7674
  * POST a BlockRun endpoint with a JSON body.
7675
7675
  */
7676
- async post(path5, body) {
7677
- const url = this.buildUrl(path5);
7676
+ async post(path6, body) {
7677
+ const url = this.buildUrl(path6);
7678
7678
  return this.requestWithPayment(url, "POST", body);
7679
7679
  }
7680
7680
  /**
@@ -7689,8 +7689,8 @@ var BlockrunClient = class {
7689
7689
  * short-circuits and returns the body. Most long-running endpoints (image,
7690
7690
  * video, music, voice) return 202 with a poll_url.
7691
7691
  */
7692
- async poll(path5, body, options) {
7693
- const submitUrl = this.buildUrl(path5);
7692
+ async poll(path6, body, options) {
7693
+ const submitUrl = this.buildUrl(path6);
7694
7694
  const budgetMs = options?.budgetMs ?? DEFAULT_POLL_BUDGET_MS;
7695
7695
  const intervalMs = options?.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
7696
7696
  const resp402 = await this.fetchWithTimeout(submitUrl, {
@@ -7789,8 +7789,8 @@ var BlockrunClient = class {
7789
7789
  * process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "");
7790
7790
  * }
7791
7791
  */
7792
- async *stream(path5, body) {
7793
- const url = this.buildUrl(path5);
7792
+ async *stream(path6, body) {
7793
+ const url = this.buildUrl(path6);
7794
7794
  const requestBody = JSON.stringify(body ?? {});
7795
7795
  const resp402 = await this.fetchWithTimeout(url, {
7796
7796
  method: "POST",
@@ -7856,8 +7856,8 @@ var BlockrunClient = class {
7856
7856
  // --------------------------------------------------------------------
7857
7857
  // Internal: shared infrastructure
7858
7858
  // --------------------------------------------------------------------
7859
- buildUrl(path5, params) {
7860
- let normalized = path5.startsWith("/") ? path5 : `/${path5}`;
7859
+ buildUrl(path6, params) {
7860
+ let normalized = path6.startsWith("/") ? path6 : `/${path6}`;
7861
7861
  if (normalized.startsWith("/api/")) {
7862
7862
  normalized = normalized.slice(4);
7863
7863
  }
@@ -8010,46 +8010,64 @@ function sleep(ms) {
8010
8010
  }
8011
8011
 
8012
8012
  // src/wallet.ts
8013
- import { privateKeyToAccount as privateKeyToAccount14, generatePrivateKey } from "viem/accounts";
8013
+ import { privateKeyToAccount as privateKeyToAccount15, generatePrivateKey as generatePrivateKey2 } from "viem/accounts";
8014
+
8015
+ // node_modules/.pnpm/@blockrun+core@0.1.1_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@3.25.76/node_modules/@blockrun/core/dist/config.js
8014
8016
  import * as fs2 from "fs";
8015
- import * as path2 from "path";
8016
8017
  import * as os2 from "os";
8017
- var USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
8018
- var BASE_CHAIN_ID2 = "8453";
8019
- var WALLET_DIR = path2.join(os2.homedir(), ".blockrun");
8020
- var WALLET_FILE = path2.join(WALLET_DIR, ".session");
8021
- function createWallet() {
8022
- const privateKey = generatePrivateKey();
8023
- const account = privateKeyToAccount14(privateKey);
8018
+ import * as path2 from "path";
8019
+ function homeDir() {
8020
+ return process.env.BLOCKRUN_HOME || os2.homedir();
8021
+ }
8022
+ function blockrunDir() {
8023
+ return path2.join(homeDir(), ".blockrun");
8024
+ }
8025
+ function paths() {
8026
+ const dir = blockrunDir();
8024
8027
  return {
8025
- address: account.address,
8026
- privateKey
8028
+ dir,
8029
+ session: path2.join(dir, ".session"),
8030
+ legacy: path2.join(dir, "wallet.key"),
8031
+ solana: path2.join(dir, ".solana"),
8032
+ config: path2.join(dir, "config.json"),
8033
+ costLog: path2.join(dir, "cost_log.jsonl")
8027
8034
  };
8028
8035
  }
8029
- function saveWallet(privateKey) {
8030
- if (!fs2.existsSync(WALLET_DIR)) {
8031
- fs2.mkdirSync(WALLET_DIR, { recursive: true });
8036
+
8037
+ // node_modules/.pnpm/@blockrun+core@0.1.1_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@3.25.76/node_modules/@blockrun/core/dist/wallet.js
8038
+ import * as fs3 from "fs";
8039
+ import * as path3 from "path";
8040
+ import { privateKeyToAccount as privateKeyToAccount14, generatePrivateKey } from "viem/accounts";
8041
+ function normalize(raw) {
8042
+ const k = raw.trim();
8043
+ return k.startsWith("0x") ? k : `0x${k}`;
8044
+ }
8045
+ function addressFromKey(raw) {
8046
+ try {
8047
+ return privateKeyToAccount14(normalize(raw)).address;
8048
+ } catch {
8049
+ return null;
8032
8050
  }
8033
- fs2.writeFileSync(WALLET_FILE, privateKey, { mode: 384 });
8034
- return WALLET_FILE;
8035
8051
  }
8036
8052
  function scanWallets() {
8037
- const home = os2.homedir();
8053
+ const home = homeDir();
8038
8054
  const results = [];
8039
8055
  try {
8040
- const entries = fs2.readdirSync(home, { withFileTypes: true });
8041
- for (const entry of entries) {
8042
- if (!entry.name.startsWith(".") || !entry.isDirectory()) continue;
8043
- const walletFile = path2.join(home, entry.name, "wallet.json");
8044
- if (!fs2.existsSync(walletFile)) continue;
8056
+ for (const entry of fs3.readdirSync(home, { withFileTypes: true })) {
8057
+ if (!entry.name.startsWith(".") || !entry.isDirectory())
8058
+ continue;
8059
+ const walletFile2 = path3.join(home, entry.name, "wallet.json");
8060
+ if (!fs3.existsSync(walletFile2))
8061
+ continue;
8045
8062
  try {
8046
- const data = JSON.parse(fs2.readFileSync(walletFile, "utf-8"));
8063
+ const data = JSON.parse(fs3.readFileSync(walletFile2, "utf-8"));
8047
8064
  const pk = data.privateKey || "";
8048
- const addr = data.address || "";
8049
- if (pk && addr) {
8050
- const mtime = fs2.statSync(walletFile).mtimeMs;
8051
- results.push({ mtime, privateKey: pk, address: addr, source: walletFile });
8052
- }
8065
+ if (!pk)
8066
+ continue;
8067
+ const derived = addressFromKey(pk);
8068
+ if (!derived)
8069
+ continue;
8070
+ results.push({ mtime: fs3.statSync(walletFile2).mtimeMs, privateKey: pk, address: derived, source: walletFile2 });
8053
8071
  } catch {
8054
8072
  continue;
8055
8073
  }
@@ -8060,71 +8078,97 @@ function scanWallets() {
8060
8078
  return results.map(({ privateKey, address, source }) => ({ privateKey, address, source }));
8061
8079
  }
8062
8080
  function listDiscoveredWallets() {
8063
- const listed = [];
8064
- for (const entry of scanWallets()) {
8065
- try {
8066
- listed.push({
8067
- address: privateKeyToAccount14(entry.privateKey).address,
8068
- source: entry.source
8069
- });
8070
- } catch {
8071
- continue;
8072
- }
8073
- }
8074
- return listed;
8081
+ return scanWallets().map(({ address, source }) => ({ address, source }));
8075
8082
  }
8076
- function importWallet(address) {
8083
+ function adoptWallet(address) {
8077
8084
  const wanted = address.trim().toLowerCase();
8085
+ const p = paths();
8078
8086
  for (const entry of scanWallets()) {
8079
- let derived;
8080
- try {
8081
- derived = privateKeyToAccount14(entry.privateKey).address;
8082
- } catch {
8087
+ if (entry.address.toLowerCase() !== wanted)
8083
8088
  continue;
8084
- }
8085
- if (derived.toLowerCase() !== wanted) continue;
8086
- if (fs2.existsSync(WALLET_FILE)) {
8087
- const current = fs2.readFileSync(WALLET_FILE, "utf-8").trim();
8088
- if (current && current !== entry.privateKey) {
8089
- const backup = path2.join(WALLET_DIR, `.session.backup-${Math.floor(Date.now() / 1e3)}`);
8090
- fs2.writeFileSync(backup, current, { mode: 384 });
8089
+ const privateKey = normalize(entry.privateKey);
8090
+ if (fs3.existsSync(p.session)) {
8091
+ const current = fs3.readFileSync(p.session, "utf8").trim();
8092
+ if (current && normalize(current) !== privateKey) {
8093
+ const backup = path3.join(p.dir, `.session.backup-${Math.floor(Date.now() / 1e3)}`);
8094
+ fs3.writeFileSync(backup, current, { mode: 384 });
8091
8095
  }
8092
8096
  }
8093
- saveWallet(entry.privateKey);
8094
- return derived;
8097
+ fs3.mkdirSync(p.dir, { recursive: true });
8098
+ fs3.writeFileSync(p.session, privateKey, { mode: 384 });
8099
+ return { address: entry.address, privateKey, source: "session" };
8095
8100
  }
8096
8101
  const available = listDiscoveredWallets().map((w) => w.address);
8097
- throw new Error(
8098
- `No discovered wallet controls ${address}. Available: ${available.length ? available.join(", ") : "none"}`
8099
- );
8102
+ throw new Error(`No discovered wallet controls ${address}. Available: ${available.length ? available.join(", ") : "none"}`);
8100
8103
  }
8101
- function loadWallet() {
8102
- if (fs2.existsSync(WALLET_FILE)) {
8103
- const key = fs2.readFileSync(WALLET_FILE, "utf-8").trim();
8104
- if (key) return key;
8105
- }
8106
- const legacyFile = path2.join(WALLET_DIR, "wallet.key");
8107
- if (fs2.existsSync(legacyFile)) {
8108
- const key = fs2.readFileSync(legacyFile, "utf-8").trim();
8109
- if (key) return key;
8104
+ function resolveFromFiles() {
8105
+ const p = paths();
8106
+ if (fs3.existsSync(p.session)) {
8107
+ const raw = fs3.readFileSync(p.session, "utf8").trim();
8108
+ if (raw)
8109
+ return { privateKey: normalize(raw), source: "session" };
8110
+ }
8111
+ if (fs3.existsSync(p.legacy)) {
8112
+ const raw = fs3.readFileSync(p.legacy, "utf8").trim();
8113
+ if (raw)
8114
+ return { privateKey: normalize(raw), source: "legacy" };
8110
8115
  }
8111
8116
  return null;
8112
8117
  }
8118
+ function resolvePrivateKey(env = process.env) {
8119
+ const fromEnv = env.BLOCKRUN_WALLET_KEY || env.BASE_CHAIN_WALLET_KEY;
8120
+ if (fromEnv && fromEnv.trim()) {
8121
+ return { privateKey: normalize(fromEnv), source: "env" };
8122
+ }
8123
+ return resolveFromFiles();
8124
+ }
8125
+
8126
+ // src/wallet.ts
8127
+ import * as fs4 from "fs";
8128
+ var USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
8129
+ var BASE_CHAIN_ID2 = "8453";
8130
+ function walletDir() {
8131
+ return paths().dir;
8132
+ }
8133
+ function walletFile() {
8134
+ return paths().session;
8135
+ }
8136
+ function createWallet() {
8137
+ const privateKey = generatePrivateKey2();
8138
+ const account = privateKeyToAccount15(privateKey);
8139
+ return {
8140
+ address: account.address,
8141
+ privateKey
8142
+ };
8143
+ }
8144
+ function saveWallet(privateKey) {
8145
+ const dir = walletDir();
8146
+ const file = walletFile();
8147
+ if (!fs4.existsSync(dir)) {
8148
+ fs4.mkdirSync(dir, { recursive: true });
8149
+ }
8150
+ fs4.writeFileSync(file, privateKey, { mode: 384 });
8151
+ return file;
8152
+ }
8153
+ function scanWallets2() {
8154
+ return scanWallets();
8155
+ }
8156
+ function listDiscoveredWallets2() {
8157
+ return listDiscoveredWallets();
8158
+ }
8159
+ function importWallet(address) {
8160
+ return adoptWallet(address).address;
8161
+ }
8162
+ function loadWallet() {
8163
+ return resolveFromFiles()?.privateKey ?? null;
8164
+ }
8113
8165
  function formatWalletMigrationNotice(newAddress) {
8114
- let discovered;
8166
+ let addresses;
8115
8167
  try {
8116
- discovered = scanWallets();
8168
+ addresses = listDiscoveredWallets().map((w) => w.address);
8117
8169
  } catch {
8118
8170
  return null;
8119
8171
  }
8120
- const addresses = [];
8121
- for (const entry of discovered) {
8122
- try {
8123
- addresses.push(privateKeyToAccount14(entry.privateKey).address);
8124
- } catch {
8125
- continue;
8126
- }
8127
- }
8128
8172
  if (addresses.length === 0) return null;
8129
8173
  const found = addresses.map((addr) => ` ${addr}`).join("\n");
8130
8174
  return `
@@ -8151,30 +8195,18 @@ BLOCKRUN_WALLET_KEY=<private-key> for a single run without changing anything.
8151
8195
  `;
8152
8196
  }
8153
8197
  function getOrCreateWallet() {
8154
- const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
8155
- if (envKey) {
8156
- const account = privateKeyToAccount14(envKey);
8157
- return { address: account.address, privateKey: envKey, isNew: false };
8158
- }
8159
- const fileKey = loadWallet();
8160
- if (fileKey) {
8161
- const account = privateKeyToAccount14(fileKey);
8162
- return { address: account.address, privateKey: fileKey, isNew: false };
8198
+ const resolved = resolvePrivateKey();
8199
+ if (resolved) {
8200
+ const account = privateKeyToAccount15(resolved.privateKey);
8201
+ return { address: account.address, privateKey: resolved.privateKey, isNew: false };
8163
8202
  }
8164
8203
  const { address, privateKey } = createWallet();
8165
8204
  saveWallet(privateKey);
8166
8205
  return { address, privateKey, isNew: true };
8167
8206
  }
8168
8207
  function getWalletAddress() {
8169
- const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
8170
- if (envKey) {
8171
- return privateKeyToAccount14(envKey).address;
8172
- }
8173
- const fileKey = loadWallet();
8174
- if (fileKey) {
8175
- return privateKeyToAccount14(fileKey).address;
8176
- }
8177
- return null;
8208
+ const resolved = resolvePrivateKey();
8209
+ return resolved ? privateKeyToAccount15(resolved.privateKey).address : null;
8178
8210
  }
8179
8211
  function getEip681Uri(address, amountUsdc = 1) {
8180
8212
  const amountWei = Math.floor(amountUsdc * 1e6);
@@ -8236,15 +8268,15 @@ function formatFundingMessageCompact(address) {
8236
8268
  return `I need a little top-up to keep helping you! Send USDC on Base to: ${address}
8237
8269
  Check my balance: ${links.basescan}`;
8238
8270
  }
8239
- var WALLET_FILE_PATH = WALLET_FILE;
8240
- var WALLET_DIR_PATH = WALLET_DIR;
8271
+ var WALLET_FILE_PATH = walletFile();
8272
+ var WALLET_DIR_PATH = walletDir();
8241
8273
 
8242
8274
  // src/solana-wallet.ts
8243
- import * as fs3 from "fs";
8244
- import * as path3 from "path";
8275
+ import * as fs5 from "fs";
8276
+ import * as path4 from "path";
8245
8277
  import * as os3 from "os";
8246
- var WALLET_DIR2 = path3.join(os3.homedir(), ".blockrun");
8247
- var SOLANA_WALLET_FILE = path3.join(WALLET_DIR2, ".solana-session");
8278
+ var WALLET_DIR = path4.join(os3.homedir(), ".blockrun");
8279
+ var SOLANA_WALLET_FILE = path4.join(WALLET_DIR, ".solana-session");
8248
8280
  async function createSolanaWallet() {
8249
8281
  const { Keypair } = await loadSolanaWeb3("Solana wallet operations");
8250
8282
  const bs58 = await import("bs58");
@@ -8308,39 +8340,39 @@ async function solanaPublicKey(privateKey) {
8308
8340
  return Keypair.fromSecretKey(bytes).publicKey.toBase58();
8309
8341
  }
8310
8342
  function saveSolanaWallet(privateKey) {
8311
- if (!fs3.existsSync(WALLET_DIR2)) fs3.mkdirSync(WALLET_DIR2, { recursive: true });
8312
- fs3.writeFileSync(SOLANA_WALLET_FILE, privateKey, { mode: 384 });
8343
+ if (!fs5.existsSync(WALLET_DIR)) fs5.mkdirSync(WALLET_DIR, { recursive: true });
8344
+ fs5.writeFileSync(SOLANA_WALLET_FILE, privateKey, { mode: 384 });
8313
8345
  return SOLANA_WALLET_FILE;
8314
8346
  }
8315
8347
  function scanSolanaWallets() {
8316
8348
  const home = os3.homedir();
8317
8349
  const results = [];
8318
8350
  try {
8319
- const entries = fs3.readdirSync(home, { withFileTypes: true });
8351
+ const entries = fs5.readdirSync(home, { withFileTypes: true });
8320
8352
  for (const entry of entries) {
8321
8353
  if (!entry.name.startsWith(".") || !entry.isDirectory()) continue;
8322
- const solanaWalletFile = path3.join(home, entry.name, "solana-wallet.json");
8323
- if (fs3.existsSync(solanaWalletFile)) {
8354
+ const solanaWalletFile = path4.join(home, entry.name, "solana-wallet.json");
8355
+ if (fs5.existsSync(solanaWalletFile)) {
8324
8356
  try {
8325
- const data = JSON.parse(fs3.readFileSync(solanaWalletFile, "utf-8"));
8357
+ const data = JSON.parse(fs5.readFileSync(solanaWalletFile, "utf-8"));
8326
8358
  const pk = data.privateKey || "";
8327
8359
  const addr = data.address || "";
8328
8360
  if (pk && addr) {
8329
- const mtime = fs3.statSync(solanaWalletFile).mtimeMs;
8361
+ const mtime = fs5.statSync(solanaWalletFile).mtimeMs;
8330
8362
  results.push({ mtime, secretKey: pk, publicKey: addr, source: solanaWalletFile });
8331
8363
  }
8332
8364
  } catch {
8333
8365
  }
8334
8366
  }
8335
8367
  if (entry.name === ".brcc") {
8336
- const brccWalletFile = path3.join(home, entry.name, "wallet.json");
8337
- if (fs3.existsSync(brccWalletFile)) {
8368
+ const brccWalletFile = path4.join(home, entry.name, "wallet.json");
8369
+ if (fs5.existsSync(brccWalletFile)) {
8338
8370
  try {
8339
- const data = JSON.parse(fs3.readFileSync(brccWalletFile, "utf-8"));
8371
+ const data = JSON.parse(fs5.readFileSync(brccWalletFile, "utf-8"));
8340
8372
  const pk = data.privateKey || "";
8341
8373
  const addr = data.address || "";
8342
8374
  if (pk && addr) {
8343
- const mtime = fs3.statSync(brccWalletFile).mtimeMs;
8375
+ const mtime = fs5.statSync(brccWalletFile).mtimeMs;
8344
8376
  results.push({ mtime, secretKey: pk, publicKey: addr, source: brccWalletFile });
8345
8377
  }
8346
8378
  } catch {
@@ -8354,8 +8386,8 @@ function scanSolanaWallets() {
8354
8386
  return results.map(({ secretKey, publicKey, source }) => ({ secretKey, publicKey, source }));
8355
8387
  }
8356
8388
  function loadSolanaWallet() {
8357
- if (fs3.existsSync(SOLANA_WALLET_FILE)) {
8358
- const key = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8389
+ if (fs5.existsSync(SOLANA_WALLET_FILE)) {
8390
+ const key = fs5.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8359
8391
  if (key) return key;
8360
8392
  }
8361
8393
  return null;
@@ -8381,14 +8413,14 @@ async function importSolanaWallet(address) {
8381
8413
  continue;
8382
8414
  }
8383
8415
  if (derived !== wanted) continue;
8384
- if (fs3.existsSync(SOLANA_WALLET_FILE)) {
8385
- const current = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8416
+ if (fs5.existsSync(SOLANA_WALLET_FILE)) {
8417
+ const current = fs5.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8386
8418
  if (current && current !== entry.secretKey) {
8387
- const backup = path3.join(
8388
- WALLET_DIR2,
8419
+ const backup = path4.join(
8420
+ WALLET_DIR,
8389
8421
  `.solana-session.backup-${Math.floor(Date.now() / 1e3)}`
8390
8422
  );
8391
- fs3.writeFileSync(backup, current, { mode: 384 });
8423
+ fs5.writeFileSync(backup, current, { mode: 384 });
8392
8424
  }
8393
8425
  }
8394
8426
  saveSolanaWallet(entry.secretKey);
@@ -8456,8 +8488,8 @@ async function getOrCreateSolanaWallet() {
8456
8488
  );
8457
8489
  return { privateKey: envKey, address: address2, isNew: false };
8458
8490
  }
8459
- if (fs3.existsSync(SOLANA_WALLET_FILE)) {
8460
- const fileKey = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8491
+ if (fs5.existsSync(SOLANA_WALLET_FILE)) {
8492
+ const fileKey = fs5.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8461
8493
  if (fileKey) {
8462
8494
  const address2 = await solanaPublicKeyFrom(fileKey, SOLANA_WALLET_FILE);
8463
8495
  return { privateKey: fileKey, address: address2, isNew: false };
@@ -8739,11 +8771,11 @@ var SolanaLLMClient = class {
8739
8771
  return data;
8740
8772
  }
8741
8773
  // ── Prediction Markets (Powered by Predexon) ────────────────────────────
8742
- async pm(path5, params) {
8743
- return this.getWithPaymentRaw(`/v1/pm/${path5}`, params);
8774
+ async pm(path6, params) {
8775
+ return this.getWithPaymentRaw(`/v1/pm/${path6}`, params);
8744
8776
  }
8745
- async pmQuery(path5, query) {
8746
- return this.requestWithPaymentRaw(`/v1/pm/${path5}`, query);
8777
+ async pmQuery(path6, query) {
8778
+ return this.requestWithPaymentRaw(`/v1/pm/${path6}`, query);
8747
8779
  }
8748
8780
  // ── Exa Web Search (Powered by Exa) ──────────────────────────────────────
8749
8781
  /**
@@ -8755,8 +8787,8 @@ var SolanaLLMClient = class {
8755
8787
  * @example
8756
8788
  * const results = await client.exa("search", { query: "latest AI research", numResults: 5 });
8757
8789
  */
8758
- async exa(path5, body) {
8759
- return this.requestWithPaymentRaw(`/v1/exa/${path5}`, body);
8790
+ async exa(path6, body) {
8791
+ return this.requestWithPaymentRaw(`/v1/exa/${path6}`, body);
8760
8792
  }
8761
8793
  /**
8762
8794
  * Neural and keyword web search via Exa (Solana payment, $0.01/request).
@@ -8806,8 +8838,8 @@ var SolanaLLMClient = class {
8806
8838
  * "prices/coingecko:bitcoin,base:0x..."
8807
8839
  * @param params - Query parameters passed through to DefiLlama
8808
8840
  */
8809
- async defi(path5, params) {
8810
- return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
8841
+ async defi(path6, params) {
8842
+ return this.getWithPaymentRaw(`/v1/defillama/${path6}`, params);
8811
8843
  }
8812
8844
  /** All DeFi protocols with TVL ($0.005/call). */
8813
8845
  async defiProtocols() {
@@ -8843,9 +8875,9 @@ var SolanaLLMClient = class {
8843
8875
  * @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
8844
8876
  * @param body - JSON body — pass to switch to POST (gasless/submit only)
8845
8877
  */
8846
- async dex(path5, params, body) {
8847
- if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
8848
- return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
8878
+ async dex(path6, params, body) {
8879
+ if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path6}`, body);
8880
+ return this.getWithPaymentRaw(`/v1/zerox/${path6}`, params);
8849
8881
  }
8850
8882
  /** Indicative Permit2 swap price — no commitment (free). */
8851
8883
  async dexPrice(params) {
@@ -8889,8 +8921,8 @@ var SolanaLLMClient = class {
8889
8921
  * "sandbox/status", "sandbox/terminate" ($0.001 each)
8890
8922
  * @param body - JSON body for the endpoint
8891
8923
  */
8892
- async modal(path5, body) {
8893
- return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
8924
+ async modal(path6, body) {
8925
+ return this.requestWithPaymentRaw(`/v1/modal/${path6}`, body ?? {});
8894
8926
  }
8895
8927
  /** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
8896
8928
  async modalSandboxCreate(body) {
@@ -9207,13 +9239,13 @@ function solanaClient(options = {}) {
9207
9239
  }
9208
9240
 
9209
9241
  // src/cache.ts
9210
- import * as fs4 from "fs";
9211
- import * as path4 from "path";
9242
+ import * as fs6 from "fs";
9243
+ import * as path5 from "path";
9212
9244
  import * as os4 from "os";
9213
9245
  import * as crypto2 from "crypto";
9214
- var CACHE_DIR = path4.join(os4.homedir(), ".blockrun", "cache");
9215
- var DATA_DIR = path4.join(os4.homedir(), ".blockrun", "data");
9216
- var COST_LOG_FILE2 = path4.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
9246
+ var CACHE_DIR = path5.join(os4.homedir(), ".blockrun", "cache");
9247
+ var DATA_DIR = path5.join(os4.homedir(), ".blockrun", "data");
9248
+ var COST_LOG_FILE2 = path5.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
9217
9249
  var DEFAULT_TTL = {
9218
9250
  "/v1/partner/": 3600 * 1e3,
9219
9251
  "/v1/pm/": 1800 * 1e3,
@@ -9233,19 +9265,19 @@ function cacheKey(endpoint, body) {
9233
9265
  return crypto2.createHash("sha256").update(keyData).digest("hex").slice(0, 16);
9234
9266
  }
9235
9267
  function cachePath(key) {
9236
- return path4.join(CACHE_DIR, `${key}.json`);
9268
+ return path5.join(CACHE_DIR, `${key}.json`);
9237
9269
  }
9238
9270
  function getCached(key) {
9239
9271
  const filePath = cachePath(key);
9240
- if (!fs4.existsSync(filePath)) return null;
9272
+ if (!fs6.existsSync(filePath)) return null;
9241
9273
  try {
9242
- const raw = fs4.readFileSync(filePath, "utf-8");
9274
+ const raw = fs6.readFileSync(filePath, "utf-8");
9243
9275
  const entry = JSON.parse(raw);
9244
9276
  const ttl = entry.ttlMs ?? getTtl(entry.endpoint ?? "");
9245
9277
  if (ttl <= 0) return null;
9246
9278
  if (Date.now() - entry.cachedAt > ttl) {
9247
9279
  try {
9248
- fs4.unlinkSync(filePath);
9280
+ fs6.unlinkSync(filePath);
9249
9281
  } catch {
9250
9282
  }
9251
9283
  return null;
@@ -9264,7 +9296,7 @@ function getCachedByRequest(endpoint, body) {
9264
9296
  function setCache(key, data, ttlMs) {
9265
9297
  if (ttlMs <= 0) return;
9266
9298
  try {
9267
- fs4.mkdirSync(CACHE_DIR, { recursive: true });
9299
+ fs6.mkdirSync(CACHE_DIR, { recursive: true });
9268
9300
  } catch {
9269
9301
  }
9270
9302
  const entry = {
@@ -9273,7 +9305,7 @@ function setCache(key, data, ttlMs) {
9273
9305
  ttlMs
9274
9306
  };
9275
9307
  try {
9276
- fs4.writeFileSync(cachePath(key), JSON.stringify(entry));
9308
+ fs6.writeFileSync(cachePath(key), JSON.stringify(entry));
9277
9309
  } catch {
9278
9310
  }
9279
9311
  }
@@ -9294,7 +9326,7 @@ function readableFilename(endpoint, body) {
9294
9326
  }
9295
9327
  function saveReadable(endpoint, body, response, costUsd) {
9296
9328
  try {
9297
- fs4.mkdirSync(DATA_DIR, { recursive: true });
9329
+ fs6.mkdirSync(DATA_DIR, { recursive: true });
9298
9330
  } catch {
9299
9331
  }
9300
9332
  const filename = readableFilename(endpoint, body);
@@ -9306,14 +9338,14 @@ function saveReadable(endpoint, body, response, costUsd) {
9306
9338
  response
9307
9339
  };
9308
9340
  try {
9309
- fs4.writeFileSync(path4.join(DATA_DIR, filename), JSON.stringify(entry, null, 2));
9341
+ fs6.writeFileSync(path5.join(DATA_DIR, filename), JSON.stringify(entry, null, 2));
9310
9342
  } catch {
9311
9343
  }
9312
9344
  }
9313
9345
  function appendCostLog(endpoint, costUsd) {
9314
9346
  if (costUsd <= 0) return;
9315
9347
  try {
9316
- fs4.mkdirSync(path4.dirname(COST_LOG_FILE2), { recursive: true });
9348
+ fs6.mkdirSync(path5.dirname(COST_LOG_FILE2), { recursive: true });
9317
9349
  } catch {
9318
9350
  }
9319
9351
  const entry = {
@@ -9322,7 +9354,7 @@ function appendCostLog(endpoint, costUsd) {
9322
9354
  cost_usd: costUsd
9323
9355
  };
9324
9356
  try {
9325
- fs4.appendFileSync(COST_LOG_FILE2, JSON.stringify(entry) + "\n");
9357
+ fs6.appendFileSync(COST_LOG_FILE2, JSON.stringify(entry) + "\n");
9326
9358
  } catch {
9327
9359
  }
9328
9360
  }
@@ -9330,7 +9362,7 @@ function saveToCache(endpoint, body, response, costUsd = 0) {
9330
9362
  const ttl = getTtl(endpoint);
9331
9363
  if (ttl > 0) {
9332
9364
  try {
9333
- fs4.mkdirSync(CACHE_DIR, { recursive: true });
9365
+ fs6.mkdirSync(CACHE_DIR, { recursive: true });
9334
9366
  } catch {
9335
9367
  }
9336
9368
  const key = cacheKey(endpoint, body);
@@ -9342,7 +9374,7 @@ function saveToCache(endpoint, body, response, costUsd = 0) {
9342
9374
  costUsd
9343
9375
  };
9344
9376
  try {
9345
- fs4.writeFileSync(cachePath(key), JSON.stringify(entry));
9377
+ fs6.writeFileSync(cachePath(key), JSON.stringify(entry));
9346
9378
  } catch {
9347
9379
  }
9348
9380
  }
@@ -9350,14 +9382,14 @@ function saveToCache(endpoint, body, response, costUsd = 0) {
9350
9382
  appendCostLog(endpoint, costUsd);
9351
9383
  }
9352
9384
  function clearCache() {
9353
- if (!fs4.existsSync(CACHE_DIR)) return 0;
9385
+ if (!fs6.existsSync(CACHE_DIR)) return 0;
9354
9386
  let count = 0;
9355
9387
  try {
9356
- const files = fs4.readdirSync(CACHE_DIR);
9388
+ const files = fs6.readdirSync(CACHE_DIR);
9357
9389
  for (const file of files) {
9358
9390
  if (file.endsWith(".json")) {
9359
9391
  try {
9360
- fs4.unlinkSync(path4.join(CACHE_DIR, file));
9392
+ fs6.unlinkSync(path5.join(CACHE_DIR, file));
9361
9393
  count++;
9362
9394
  } catch {
9363
9395
  }
@@ -9368,14 +9400,14 @@ function clearCache() {
9368
9400
  return count;
9369
9401
  }
9370
9402
  function getCostLogSummary() {
9371
- if (!fs4.existsSync(COST_LOG_FILE2)) {
9403
+ if (!fs6.existsSync(COST_LOG_FILE2)) {
9372
9404
  return { totalUsd: 0, calls: 0, byEndpoint: {} };
9373
9405
  }
9374
9406
  let totalUsd = 0;
9375
9407
  let calls = 0;
9376
9408
  const byEndpoint = {};
9377
9409
  try {
9378
- const content = fs4.readFileSync(COST_LOG_FILE2, "utf-8").trim();
9410
+ const content = fs6.readFileSync(COST_LOG_FILE2, "utf-8").trim();
9379
9411
  if (!content) return { totalUsd: 0, calls: 0, byEndpoint: {} };
9380
9412
  for (const line of content.split("\n")) {
9381
9413
  if (!line) continue;
@@ -9589,7 +9621,7 @@ var OpenAI = class {
9589
9621
  };
9590
9622
 
9591
9623
  // src/anthropic-compat.ts
9592
- import { privateKeyToAccount as privateKeyToAccount15 } from "viem/accounts";
9624
+ import { privateKeyToAccount as privateKeyToAccount16 } from "viem/accounts";
9593
9625
  var AnthropicClient = class {
9594
9626
  _client = null;
9595
9627
  _clientPromise = null;
@@ -9602,7 +9634,7 @@ var AnthropicClient = class {
9602
9634
  const key = options.privateKey ?? wallet.privateKey;
9603
9635
  validatePrivateKey(key);
9604
9636
  this._privateKey = key;
9605
- this._account = privateKeyToAccount15(this._privateKey);
9637
+ this._account = privateKeyToAccount16(this._privateKey);
9606
9638
  const apiUrl = options.apiUrl ?? "https://blockrun.ai/api";
9607
9639
  validateApiUrl(apiUrl);
9608
9640
  this._apiUrl = apiUrl.replace(/\/$/, "");
@@ -9755,7 +9787,7 @@ export {
9755
9787
  importSolanaWallet,
9756
9788
  importWallet,
9757
9789
  listDiscoveredSolanaWallets,
9758
- listDiscoveredWallets,
9790
+ listDiscoveredWallets2 as listDiscoveredWallets,
9759
9791
  loadSolanaWallet,
9760
9792
  loadWallet,
9761
9793
  logCost,
@@ -9764,7 +9796,7 @@ export {
9764
9796
  saveToCache,
9765
9797
  saveWallet,
9766
9798
  scanSolanaWallets,
9767
- scanWallets,
9799
+ scanWallets2 as scanWallets,
9768
9800
  setCache,
9769
9801
  setupAgentSolanaWallet,
9770
9802
  setupAgentWallet,