@blockrun/llm 3.12.0 → 3.13.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.cjs CHANGED
@@ -88,7 +88,7 @@ __export(index_exports, {
88
88
  importSolanaWallet: () => importSolanaWallet,
89
89
  importWallet: () => importWallet,
90
90
  listDiscoveredSolanaWallets: () => listDiscoveredSolanaWallets,
91
- listDiscoveredWallets: () => listDiscoveredWallets,
91
+ listDiscoveredWallets: () => listDiscoveredWallets2,
92
92
  loadSolanaWallet: () => loadSolanaWallet,
93
93
  loadWallet: () => loadWallet,
94
94
  logCost: () => logCost,
@@ -97,7 +97,7 @@ __export(index_exports, {
97
97
  saveToCache: () => saveToCache,
98
98
  saveWallet: () => saveWallet,
99
99
  scanSolanaWallets: () => scanSolanaWallets,
100
- scanWallets: () => scanWallets,
100
+ scanWallets: () => scanWallets2,
101
101
  setCache: () => setCache,
102
102
  setupAgentSolanaWallet: () => setupAgentSolanaWallet,
103
103
  setupAgentWallet: () => setupAgentWallet,
@@ -3964,7 +3964,7 @@ function getCostSummary() {
3964
3964
  }
3965
3965
 
3966
3966
  // src/version.ts
3967
- var SDK_VERSION = "3.12.0";
3967
+ var SDK_VERSION = "3.13.0";
3968
3968
  var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
3969
3969
 
3970
3970
  // src/client.ts
@@ -5054,8 +5054,8 @@ var LLMClient = class _LLMClient {
5054
5054
  * @example
5055
5055
  * const results = await client.exa("search", { query: "latest AI research", numResults: 5 });
5056
5056
  */
5057
- async exa(path5, body) {
5058
- return this.requestWithPaymentRaw(`/v1/exa/${path5}`, body);
5057
+ async exa(path6, body) {
5058
+ return this.requestWithPaymentRaw(`/v1/exa/${path6}`, body);
5059
5059
  }
5060
5060
  /**
5061
5061
  * Neural web search via Exa. Returns semantically relevant URLs and metadata.
@@ -5203,8 +5203,8 @@ var LLMClient = class _LLMClient {
5203
5203
  * const market = await client.pm("kalshi/markets/KXBTC-25MAR14");
5204
5204
  * const results = await client.pm("polymarket/search", { q: "bitcoin" });
5205
5205
  */
5206
- async pm(path5, params) {
5207
- return this.getWithPaymentRaw(`/v1/pm/${path5}`, params);
5206
+ async pm(path6, params) {
5207
+ return this.getWithPaymentRaw(`/v1/pm/${path6}`, params);
5208
5208
  }
5209
5209
  /**
5210
5210
  * Structured query for Predexon prediction market data (POST endpoints).
@@ -5220,8 +5220,8 @@ var LLMClient = class _LLMClient {
5220
5220
  * addresses: ["0xabc...", "0xdef..."],
5221
5221
  * });
5222
5222
  */
5223
- async pmQuery(path5, query) {
5224
- return this.requestWithPaymentRaw(`/v1/pm/${path5}`, query);
5223
+ async pmQuery(path6, query) {
5224
+ return this.requestWithPaymentRaw(`/v1/pm/${path6}`, query);
5225
5225
  }
5226
5226
  // ── PM convenience helpers (Predexon v2) ─────────────────────────────────
5227
5227
  // Thin wrappers over pm() / pmQuery() for the most common v2 endpoints.
@@ -5309,8 +5309,8 @@ var LLMClient = class _LLMClient {
5309
5309
  * "prices/coingecko:bitcoin,base:0x..."
5310
5310
  * @param params - Query parameters passed through to DefiLlama
5311
5311
  */
5312
- async defi(path5, params) {
5313
- return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
5312
+ async defi(path6, params) {
5313
+ return this.getWithPaymentRaw(`/v1/defillama/${path6}`, params);
5314
5314
  }
5315
5315
  /** All DeFi protocols with TVL ($0.005/call). */
5316
5316
  async defiProtocols() {
@@ -5346,9 +5346,9 @@ var LLMClient = class _LLMClient {
5346
5346
  * @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
5347
5347
  * @param body - JSON body — pass to switch to POST (gasless/submit only)
5348
5348
  */
5349
- async dex(path5, params, body) {
5350
- if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
5351
- return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
5349
+ async dex(path6, params, body) {
5350
+ if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path6}`, body);
5351
+ return this.getWithPaymentRaw(`/v1/zerox/${path6}`, params);
5352
5352
  }
5353
5353
  /** Indicative Permit2 swap price — no commitment (free). */
5354
5354
  async dexPrice(params) {
@@ -5392,8 +5392,8 @@ var LLMClient = class _LLMClient {
5392
5392
  * "sandbox/status", "sandbox/terminate" ($0.001 each)
5393
5393
  * @param body - JSON body for the endpoint
5394
5394
  */
5395
- async modal(path5, body) {
5396
- return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
5395
+ async modal(path6, body) {
5396
+ return this.requestWithPaymentRaw(`/v1/modal/${path6}`, body ?? {});
5397
5397
  }
5398
5398
  /** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
5399
5399
  async modalSandboxCreate(body) {
@@ -6755,8 +6755,8 @@ var PhoneClient = class {
6755
6755
  return data;
6756
6756
  }
6757
6757
  // ─── Internals ─────────────────────────────────────────────────────────
6758
- async request(path5, body) {
6759
- const url = `${this.apiUrl}/v1/phone/${path5}`;
6758
+ async request(path6, body) {
6759
+ const url = `${this.apiUrl}/v1/phone/${path6}`;
6760
6760
  const response = await this.fetchWithTimeout(url, {
6761
6761
  method: "POST",
6762
6762
  headers: { "Content-Type": "application/json" },
@@ -7163,10 +7163,10 @@ var PriceClient = class {
7163
7163
  }
7164
7164
  async price(category, symbol, options) {
7165
7165
  if (!symbol) throw new Error("symbol is required");
7166
- const path5 = categoryPath(category, options?.market, "price", symbol);
7166
+ const path6 = categoryPath(category, options?.market, "price", symbol);
7167
7167
  const query = {};
7168
7168
  if (options?.session) query.session = options.session;
7169
- const data = await this.getWithPayment(path5, query);
7169
+ const data = await this.getWithPayment(path6, query);
7170
7170
  return {
7171
7171
  symbol: data.symbol ?? symbol.toUpperCase(),
7172
7172
  price: data.price,
@@ -7185,14 +7185,14 @@ var PriceClient = class {
7185
7185
  if (!options.from || options.from <= 0) {
7186
7186
  throw new Error("history requires options.from (unix seconds)");
7187
7187
  }
7188
- const path5 = categoryPath(category, options.market, "history", symbol);
7188
+ const path6 = categoryPath(category, options.market, "history", symbol);
7189
7189
  const query = {
7190
7190
  resolution: options.resolution ?? "D",
7191
7191
  from: String(options.from)
7192
7192
  };
7193
7193
  if (options.to) query.to = String(options.to);
7194
7194
  if (options.session) query.session = options.session;
7195
- const data = await this.getWithPayment(path5, query);
7195
+ const data = await this.getWithPayment(path6, query);
7196
7196
  return {
7197
7197
  symbol: data.symbol ?? symbol.toUpperCase(),
7198
7198
  resolution: data.resolution ?? (options.resolution ?? "D"),
@@ -7204,12 +7204,12 @@ var PriceClient = class {
7204
7204
  };
7205
7205
  }
7206
7206
  async listSymbols(category, options) {
7207
- const path5 = categoryPath(category, options?.market, "list");
7207
+ const path6 = categoryPath(category, options?.market, "list");
7208
7208
  const query = {
7209
7209
  limit: String(options?.limit && options.limit > 0 ? options.limit : 100)
7210
7210
  };
7211
7211
  if (options?.query) query.q = options.query;
7212
- const data = await this.getWithPayment(path5, query);
7212
+ const data = await this.getWithPayment(path6, query);
7213
7213
  if (Array.isArray(data)) {
7214
7214
  return { symbols: data, count: data.length };
7215
7215
  }
@@ -7368,19 +7368,19 @@ var SurfClient = class {
7368
7368
  * `/v1/surf` is tolerated and stripped). Query params are URL-encoded;
7369
7369
  * arrays become repeated keys (`?a=1&a=2`).
7370
7370
  */
7371
- async get(path5, params) {
7372
- const url = this.buildUrl(path5, params);
7371
+ async get(path6, params) {
7372
+ const url = this.buildUrl(path6, params);
7373
7373
  return this.requestWithPayment(url, "GET");
7374
7374
  }
7375
7375
  /**
7376
7376
  * POST a Surf endpoint with a JSON body. Same path normalization as `get`.
7377
7377
  */
7378
- async post(path5, body) {
7379
- const url = this.buildUrl(path5);
7378
+ async post(path6, body) {
7379
+ const url = this.buildUrl(path6);
7380
7380
  return this.requestWithPayment(url, "POST", body);
7381
7381
  }
7382
- buildUrl(path5, params) {
7383
- let normalized = path5.startsWith("/") ? path5 : `/${path5}`;
7382
+ buildUrl(path6, params) {
7383
+ let normalized = path6.startsWith("/") ? path6 : `/${path6}`;
7384
7384
  if (!normalized.startsWith(SURF_PREFIX)) {
7385
7385
  normalized = `${SURF_PREFIX}${normalized}`;
7386
7386
  }
@@ -7780,15 +7780,15 @@ var BlockrunClient = class {
7780
7780
  * `/api` is tolerated and stripped). Query params are URL-encoded; arrays
7781
7781
  * become repeated keys (`?a=1&a=2`); undefined/null are dropped.
7782
7782
  */
7783
- async get(path5, params) {
7784
- const url = this.buildUrl(path5, params);
7783
+ async get(path6, params) {
7784
+ const url = this.buildUrl(path6, params);
7785
7785
  return this.requestWithPayment(url, "GET");
7786
7786
  }
7787
7787
  /**
7788
7788
  * POST a BlockRun endpoint with a JSON body.
7789
7789
  */
7790
- async post(path5, body) {
7791
- const url = this.buildUrl(path5);
7790
+ async post(path6, body) {
7791
+ const url = this.buildUrl(path6);
7792
7792
  return this.requestWithPayment(url, "POST", body);
7793
7793
  }
7794
7794
  /**
@@ -7803,8 +7803,8 @@ var BlockrunClient = class {
7803
7803
  * short-circuits and returns the body. Most long-running endpoints (image,
7804
7804
  * video, music, voice) return 202 with a poll_url.
7805
7805
  */
7806
- async poll(path5, body, options) {
7807
- const submitUrl = this.buildUrl(path5);
7806
+ async poll(path6, body, options) {
7807
+ const submitUrl = this.buildUrl(path6);
7808
7808
  const budgetMs = options?.budgetMs ?? DEFAULT_POLL_BUDGET_MS;
7809
7809
  const intervalMs = options?.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
7810
7810
  const resp402 = await this.fetchWithTimeout(submitUrl, {
@@ -7903,8 +7903,8 @@ var BlockrunClient = class {
7903
7903
  * process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "");
7904
7904
  * }
7905
7905
  */
7906
- async *stream(path5, body) {
7907
- const url = this.buildUrl(path5);
7906
+ async *stream(path6, body) {
7907
+ const url = this.buildUrl(path6);
7908
7908
  const requestBody = JSON.stringify(body ?? {});
7909
7909
  const resp402 = await this.fetchWithTimeout(url, {
7910
7910
  method: "POST",
@@ -7970,8 +7970,8 @@ var BlockrunClient = class {
7970
7970
  // --------------------------------------------------------------------
7971
7971
  // Internal: shared infrastructure
7972
7972
  // --------------------------------------------------------------------
7973
- buildUrl(path5, params) {
7974
- let normalized = path5.startsWith("/") ? path5 : `/${path5}`;
7973
+ buildUrl(path6, params) {
7974
+ let normalized = path6.startsWith("/") ? path6 : `/${path6}`;
7975
7975
  if (normalized.startsWith("/api/")) {
7976
7976
  normalized = normalized.slice(4);
7977
7977
  }
@@ -8124,46 +8124,64 @@ function sleep(ms) {
8124
8124
  }
8125
8125
 
8126
8126
  // src/wallet.ts
8127
- var import_accounts15 = require("viem/accounts");
8127
+ var import_accounts16 = require("viem/accounts");
8128
+
8129
+ // 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
8128
8130
  var fs2 = __toESM(require("fs"), 1);
8129
- var path2 = __toESM(require("path"), 1);
8130
8131
  var os2 = __toESM(require("os"), 1);
8131
- var USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
8132
- var BASE_CHAIN_ID2 = "8453";
8133
- var WALLET_DIR = path2.join(os2.homedir(), ".blockrun");
8134
- var WALLET_FILE = path2.join(WALLET_DIR, ".session");
8135
- function createWallet() {
8136
- const privateKey = (0, import_accounts15.generatePrivateKey)();
8137
- const account = (0, import_accounts15.privateKeyToAccount)(privateKey);
8132
+ var path2 = __toESM(require("path"), 1);
8133
+ function homeDir() {
8134
+ return process.env.BLOCKRUN_HOME || os2.homedir();
8135
+ }
8136
+ function blockrunDir() {
8137
+ return path2.join(homeDir(), ".blockrun");
8138
+ }
8139
+ function paths() {
8140
+ const dir = blockrunDir();
8138
8141
  return {
8139
- address: account.address,
8140
- privateKey
8142
+ dir,
8143
+ session: path2.join(dir, ".session"),
8144
+ legacy: path2.join(dir, "wallet.key"),
8145
+ solana: path2.join(dir, ".solana"),
8146
+ config: path2.join(dir, "config.json"),
8147
+ costLog: path2.join(dir, "cost_log.jsonl")
8141
8148
  };
8142
8149
  }
8143
- function saveWallet(privateKey) {
8144
- if (!fs2.existsSync(WALLET_DIR)) {
8145
- fs2.mkdirSync(WALLET_DIR, { recursive: true });
8150
+
8151
+ // 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
8152
+ var fs3 = __toESM(require("fs"), 1);
8153
+ var path3 = __toESM(require("path"), 1);
8154
+ var import_accounts15 = require("viem/accounts");
8155
+ function normalize(raw) {
8156
+ const k = raw.trim();
8157
+ return k.startsWith("0x") ? k : `0x${k}`;
8158
+ }
8159
+ function addressFromKey(raw) {
8160
+ try {
8161
+ return (0, import_accounts15.privateKeyToAccount)(normalize(raw)).address;
8162
+ } catch {
8163
+ return null;
8146
8164
  }
8147
- fs2.writeFileSync(WALLET_FILE, privateKey, { mode: 384 });
8148
- return WALLET_FILE;
8149
8165
  }
8150
8166
  function scanWallets() {
8151
- const home = os2.homedir();
8167
+ const home = homeDir();
8152
8168
  const results = [];
8153
8169
  try {
8154
- const entries = fs2.readdirSync(home, { withFileTypes: true });
8155
- for (const entry of entries) {
8156
- if (!entry.name.startsWith(".") || !entry.isDirectory()) continue;
8157
- const walletFile = path2.join(home, entry.name, "wallet.json");
8158
- if (!fs2.existsSync(walletFile)) continue;
8170
+ for (const entry of fs3.readdirSync(home, { withFileTypes: true })) {
8171
+ if (!entry.name.startsWith(".") || !entry.isDirectory())
8172
+ continue;
8173
+ const walletFile2 = path3.join(home, entry.name, "wallet.json");
8174
+ if (!fs3.existsSync(walletFile2))
8175
+ continue;
8159
8176
  try {
8160
- const data = JSON.parse(fs2.readFileSync(walletFile, "utf-8"));
8177
+ const data = JSON.parse(fs3.readFileSync(walletFile2, "utf-8"));
8161
8178
  const pk = data.privateKey || "";
8162
- const addr = data.address || "";
8163
- if (pk && addr) {
8164
- const mtime = fs2.statSync(walletFile).mtimeMs;
8165
- results.push({ mtime, privateKey: pk, address: addr, source: walletFile });
8166
- }
8179
+ if (!pk)
8180
+ continue;
8181
+ const derived = addressFromKey(pk);
8182
+ if (!derived)
8183
+ continue;
8184
+ results.push({ mtime: fs3.statSync(walletFile2).mtimeMs, privateKey: pk, address: derived, source: walletFile2 });
8167
8185
  } catch {
8168
8186
  continue;
8169
8187
  }
@@ -8174,71 +8192,97 @@ function scanWallets() {
8174
8192
  return results.map(({ privateKey, address, source }) => ({ privateKey, address, source }));
8175
8193
  }
8176
8194
  function listDiscoveredWallets() {
8177
- const listed = [];
8178
- for (const entry of scanWallets()) {
8179
- try {
8180
- listed.push({
8181
- address: (0, import_accounts15.privateKeyToAccount)(entry.privateKey).address,
8182
- source: entry.source
8183
- });
8184
- } catch {
8185
- continue;
8186
- }
8187
- }
8188
- return listed;
8195
+ return scanWallets().map(({ address, source }) => ({ address, source }));
8189
8196
  }
8190
- function importWallet(address) {
8197
+ function adoptWallet(address) {
8191
8198
  const wanted = address.trim().toLowerCase();
8199
+ const p = paths();
8192
8200
  for (const entry of scanWallets()) {
8193
- let derived;
8194
- try {
8195
- derived = (0, import_accounts15.privateKeyToAccount)(entry.privateKey).address;
8196
- } catch {
8201
+ if (entry.address.toLowerCase() !== wanted)
8197
8202
  continue;
8198
- }
8199
- if (derived.toLowerCase() !== wanted) continue;
8200
- if (fs2.existsSync(WALLET_FILE)) {
8201
- const current = fs2.readFileSync(WALLET_FILE, "utf-8").trim();
8202
- if (current && current !== entry.privateKey) {
8203
- const backup = path2.join(WALLET_DIR, `.session.backup-${Math.floor(Date.now() / 1e3)}`);
8204
- fs2.writeFileSync(backup, current, { mode: 384 });
8203
+ const privateKey = normalize(entry.privateKey);
8204
+ if (fs3.existsSync(p.session)) {
8205
+ const current = fs3.readFileSync(p.session, "utf8").trim();
8206
+ if (current && normalize(current) !== privateKey) {
8207
+ const backup = path3.join(p.dir, `.session.backup-${Math.floor(Date.now() / 1e3)}`);
8208
+ fs3.writeFileSync(backup, current, { mode: 384 });
8205
8209
  }
8206
8210
  }
8207
- saveWallet(entry.privateKey);
8208
- return derived;
8211
+ fs3.mkdirSync(p.dir, { recursive: true });
8212
+ fs3.writeFileSync(p.session, privateKey, { mode: 384 });
8213
+ return { address: entry.address, privateKey, source: "session" };
8209
8214
  }
8210
8215
  const available = listDiscoveredWallets().map((w) => w.address);
8211
- throw new Error(
8212
- `No discovered wallet controls ${address}. Available: ${available.length ? available.join(", ") : "none"}`
8213
- );
8216
+ throw new Error(`No discovered wallet controls ${address}. Available: ${available.length ? available.join(", ") : "none"}`);
8214
8217
  }
8215
- function loadWallet() {
8216
- if (fs2.existsSync(WALLET_FILE)) {
8217
- const key = fs2.readFileSync(WALLET_FILE, "utf-8").trim();
8218
- if (key) return key;
8219
- }
8220
- const legacyFile = path2.join(WALLET_DIR, "wallet.key");
8221
- if (fs2.existsSync(legacyFile)) {
8222
- const key = fs2.readFileSync(legacyFile, "utf-8").trim();
8223
- if (key) return key;
8218
+ function resolveFromFiles() {
8219
+ const p = paths();
8220
+ if (fs3.existsSync(p.session)) {
8221
+ const raw = fs3.readFileSync(p.session, "utf8").trim();
8222
+ if (raw)
8223
+ return { privateKey: normalize(raw), source: "session" };
8224
+ }
8225
+ if (fs3.existsSync(p.legacy)) {
8226
+ const raw = fs3.readFileSync(p.legacy, "utf8").trim();
8227
+ if (raw)
8228
+ return { privateKey: normalize(raw), source: "legacy" };
8224
8229
  }
8225
8230
  return null;
8226
8231
  }
8232
+ function resolvePrivateKey(env = process.env) {
8233
+ const fromEnv = env.BLOCKRUN_WALLET_KEY || env.BASE_CHAIN_WALLET_KEY;
8234
+ if (fromEnv && fromEnv.trim()) {
8235
+ return { privateKey: normalize(fromEnv), source: "env" };
8236
+ }
8237
+ return resolveFromFiles();
8238
+ }
8239
+
8240
+ // src/wallet.ts
8241
+ var fs4 = __toESM(require("fs"), 1);
8242
+ var USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
8243
+ var BASE_CHAIN_ID2 = "8453";
8244
+ function walletDir() {
8245
+ return paths().dir;
8246
+ }
8247
+ function walletFile() {
8248
+ return paths().session;
8249
+ }
8250
+ function createWallet() {
8251
+ const privateKey = (0, import_accounts16.generatePrivateKey)();
8252
+ const account = (0, import_accounts16.privateKeyToAccount)(privateKey);
8253
+ return {
8254
+ address: account.address,
8255
+ privateKey
8256
+ };
8257
+ }
8258
+ function saveWallet(privateKey) {
8259
+ const dir = walletDir();
8260
+ const file = walletFile();
8261
+ if (!fs4.existsSync(dir)) {
8262
+ fs4.mkdirSync(dir, { recursive: true });
8263
+ }
8264
+ fs4.writeFileSync(file, privateKey, { mode: 384 });
8265
+ return file;
8266
+ }
8267
+ function scanWallets2() {
8268
+ return scanWallets();
8269
+ }
8270
+ function listDiscoveredWallets2() {
8271
+ return listDiscoveredWallets();
8272
+ }
8273
+ function importWallet(address) {
8274
+ return adoptWallet(address).address;
8275
+ }
8276
+ function loadWallet() {
8277
+ return resolveFromFiles()?.privateKey ?? null;
8278
+ }
8227
8279
  function formatWalletMigrationNotice(newAddress) {
8228
- let discovered;
8280
+ let addresses;
8229
8281
  try {
8230
- discovered = scanWallets();
8282
+ addresses = listDiscoveredWallets().map((w) => w.address);
8231
8283
  } catch {
8232
8284
  return null;
8233
8285
  }
8234
- const addresses = [];
8235
- for (const entry of discovered) {
8236
- try {
8237
- addresses.push((0, import_accounts15.privateKeyToAccount)(entry.privateKey).address);
8238
- } catch {
8239
- continue;
8240
- }
8241
- }
8242
8286
  if (addresses.length === 0) return null;
8243
8287
  const found = addresses.map((addr) => ` ${addr}`).join("\n");
8244
8288
  return `
@@ -8265,30 +8309,18 @@ BLOCKRUN_WALLET_KEY=<private-key> for a single run without changing anything.
8265
8309
  `;
8266
8310
  }
8267
8311
  function getOrCreateWallet() {
8268
- const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
8269
- if (envKey) {
8270
- const account = (0, import_accounts15.privateKeyToAccount)(envKey);
8271
- return { address: account.address, privateKey: envKey, isNew: false };
8272
- }
8273
- const fileKey = loadWallet();
8274
- if (fileKey) {
8275
- const account = (0, import_accounts15.privateKeyToAccount)(fileKey);
8276
- return { address: account.address, privateKey: fileKey, isNew: false };
8312
+ const resolved = resolvePrivateKey();
8313
+ if (resolved) {
8314
+ const account = (0, import_accounts16.privateKeyToAccount)(resolved.privateKey);
8315
+ return { address: account.address, privateKey: resolved.privateKey, isNew: false };
8277
8316
  }
8278
8317
  const { address, privateKey } = createWallet();
8279
8318
  saveWallet(privateKey);
8280
8319
  return { address, privateKey, isNew: true };
8281
8320
  }
8282
8321
  function getWalletAddress() {
8283
- const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
8284
- if (envKey) {
8285
- return (0, import_accounts15.privateKeyToAccount)(envKey).address;
8286
- }
8287
- const fileKey = loadWallet();
8288
- if (fileKey) {
8289
- return (0, import_accounts15.privateKeyToAccount)(fileKey).address;
8290
- }
8291
- return null;
8322
+ const resolved = resolvePrivateKey();
8323
+ return resolved ? (0, import_accounts16.privateKeyToAccount)(resolved.privateKey).address : null;
8292
8324
  }
8293
8325
  function getEip681Uri(address, amountUsdc = 1) {
8294
8326
  const amountWei = Math.floor(amountUsdc * 1e6);
@@ -8350,15 +8382,15 @@ function formatFundingMessageCompact(address) {
8350
8382
  return `I need a little top-up to keep helping you! Send USDC on Base to: ${address}
8351
8383
  Check my balance: ${links.basescan}`;
8352
8384
  }
8353
- var WALLET_FILE_PATH = WALLET_FILE;
8354
- var WALLET_DIR_PATH = WALLET_DIR;
8385
+ var WALLET_FILE_PATH = walletFile();
8386
+ var WALLET_DIR_PATH = walletDir();
8355
8387
 
8356
8388
  // src/solana-wallet.ts
8357
- var fs3 = __toESM(require("fs"), 1);
8358
- var path3 = __toESM(require("path"), 1);
8389
+ var fs5 = __toESM(require("fs"), 1);
8390
+ var path4 = __toESM(require("path"), 1);
8359
8391
  var os3 = __toESM(require("os"), 1);
8360
- var WALLET_DIR2 = path3.join(os3.homedir(), ".blockrun");
8361
- var SOLANA_WALLET_FILE = path3.join(WALLET_DIR2, ".solana-session");
8392
+ var WALLET_DIR = path4.join(os3.homedir(), ".blockrun");
8393
+ var SOLANA_WALLET_FILE = path4.join(WALLET_DIR, ".solana-session");
8362
8394
  async function createSolanaWallet() {
8363
8395
  const { Keypair } = await loadSolanaWeb3("Solana wallet operations");
8364
8396
  const bs58 = await import("bs58");
@@ -8422,39 +8454,39 @@ async function solanaPublicKey(privateKey) {
8422
8454
  return Keypair.fromSecretKey(bytes).publicKey.toBase58();
8423
8455
  }
8424
8456
  function saveSolanaWallet(privateKey) {
8425
- if (!fs3.existsSync(WALLET_DIR2)) fs3.mkdirSync(WALLET_DIR2, { recursive: true });
8426
- fs3.writeFileSync(SOLANA_WALLET_FILE, privateKey, { mode: 384 });
8457
+ if (!fs5.existsSync(WALLET_DIR)) fs5.mkdirSync(WALLET_DIR, { recursive: true });
8458
+ fs5.writeFileSync(SOLANA_WALLET_FILE, privateKey, { mode: 384 });
8427
8459
  return SOLANA_WALLET_FILE;
8428
8460
  }
8429
8461
  function scanSolanaWallets() {
8430
8462
  const home = os3.homedir();
8431
8463
  const results = [];
8432
8464
  try {
8433
- const entries = fs3.readdirSync(home, { withFileTypes: true });
8465
+ const entries = fs5.readdirSync(home, { withFileTypes: true });
8434
8466
  for (const entry of entries) {
8435
8467
  if (!entry.name.startsWith(".") || !entry.isDirectory()) continue;
8436
- const solanaWalletFile = path3.join(home, entry.name, "solana-wallet.json");
8437
- if (fs3.existsSync(solanaWalletFile)) {
8468
+ const solanaWalletFile = path4.join(home, entry.name, "solana-wallet.json");
8469
+ if (fs5.existsSync(solanaWalletFile)) {
8438
8470
  try {
8439
- const data = JSON.parse(fs3.readFileSync(solanaWalletFile, "utf-8"));
8471
+ const data = JSON.parse(fs5.readFileSync(solanaWalletFile, "utf-8"));
8440
8472
  const pk = data.privateKey || "";
8441
8473
  const addr = data.address || "";
8442
8474
  if (pk && addr) {
8443
- const mtime = fs3.statSync(solanaWalletFile).mtimeMs;
8475
+ const mtime = fs5.statSync(solanaWalletFile).mtimeMs;
8444
8476
  results.push({ mtime, secretKey: pk, publicKey: addr, source: solanaWalletFile });
8445
8477
  }
8446
8478
  } catch {
8447
8479
  }
8448
8480
  }
8449
8481
  if (entry.name === ".brcc") {
8450
- const brccWalletFile = path3.join(home, entry.name, "wallet.json");
8451
- if (fs3.existsSync(brccWalletFile)) {
8482
+ const brccWalletFile = path4.join(home, entry.name, "wallet.json");
8483
+ if (fs5.existsSync(brccWalletFile)) {
8452
8484
  try {
8453
- const data = JSON.parse(fs3.readFileSync(brccWalletFile, "utf-8"));
8485
+ const data = JSON.parse(fs5.readFileSync(brccWalletFile, "utf-8"));
8454
8486
  const pk = data.privateKey || "";
8455
8487
  const addr = data.address || "";
8456
8488
  if (pk && addr) {
8457
- const mtime = fs3.statSync(brccWalletFile).mtimeMs;
8489
+ const mtime = fs5.statSync(brccWalletFile).mtimeMs;
8458
8490
  results.push({ mtime, secretKey: pk, publicKey: addr, source: brccWalletFile });
8459
8491
  }
8460
8492
  } catch {
@@ -8468,8 +8500,8 @@ function scanSolanaWallets() {
8468
8500
  return results.map(({ secretKey, publicKey, source }) => ({ secretKey, publicKey, source }));
8469
8501
  }
8470
8502
  function loadSolanaWallet() {
8471
- if (fs3.existsSync(SOLANA_WALLET_FILE)) {
8472
- const key = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8503
+ if (fs5.existsSync(SOLANA_WALLET_FILE)) {
8504
+ const key = fs5.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8473
8505
  if (key) return key;
8474
8506
  }
8475
8507
  return null;
@@ -8495,14 +8527,14 @@ async function importSolanaWallet(address) {
8495
8527
  continue;
8496
8528
  }
8497
8529
  if (derived !== wanted) continue;
8498
- if (fs3.existsSync(SOLANA_WALLET_FILE)) {
8499
- const current = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8530
+ if (fs5.existsSync(SOLANA_WALLET_FILE)) {
8531
+ const current = fs5.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8500
8532
  if (current && current !== entry.secretKey) {
8501
- const backup = path3.join(
8502
- WALLET_DIR2,
8533
+ const backup = path4.join(
8534
+ WALLET_DIR,
8503
8535
  `.solana-session.backup-${Math.floor(Date.now() / 1e3)}`
8504
8536
  );
8505
- fs3.writeFileSync(backup, current, { mode: 384 });
8537
+ fs5.writeFileSync(backup, current, { mode: 384 });
8506
8538
  }
8507
8539
  }
8508
8540
  saveSolanaWallet(entry.secretKey);
@@ -8570,8 +8602,8 @@ async function getOrCreateSolanaWallet() {
8570
8602
  );
8571
8603
  return { privateKey: envKey, address: address2, isNew: false };
8572
8604
  }
8573
- if (fs3.existsSync(SOLANA_WALLET_FILE)) {
8574
- const fileKey = fs3.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8605
+ if (fs5.existsSync(SOLANA_WALLET_FILE)) {
8606
+ const fileKey = fs5.readFileSync(SOLANA_WALLET_FILE, "utf-8").trim();
8575
8607
  if (fileKey) {
8576
8608
  const address2 = await solanaPublicKeyFrom(fileKey, SOLANA_WALLET_FILE);
8577
8609
  return { privateKey: fileKey, address: address2, isNew: false };
@@ -8853,11 +8885,11 @@ var SolanaLLMClient = class {
8853
8885
  return data;
8854
8886
  }
8855
8887
  // ── Prediction Markets (Powered by Predexon) ────────────────────────────
8856
- async pm(path5, params) {
8857
- return this.getWithPaymentRaw(`/v1/pm/${path5}`, params);
8888
+ async pm(path6, params) {
8889
+ return this.getWithPaymentRaw(`/v1/pm/${path6}`, params);
8858
8890
  }
8859
- async pmQuery(path5, query) {
8860
- return this.requestWithPaymentRaw(`/v1/pm/${path5}`, query);
8891
+ async pmQuery(path6, query) {
8892
+ return this.requestWithPaymentRaw(`/v1/pm/${path6}`, query);
8861
8893
  }
8862
8894
  // ── Exa Web Search (Powered by Exa) ──────────────────────────────────────
8863
8895
  /**
@@ -8869,8 +8901,8 @@ var SolanaLLMClient = class {
8869
8901
  * @example
8870
8902
  * const results = await client.exa("search", { query: "latest AI research", numResults: 5 });
8871
8903
  */
8872
- async exa(path5, body) {
8873
- return this.requestWithPaymentRaw(`/v1/exa/${path5}`, body);
8904
+ async exa(path6, body) {
8905
+ return this.requestWithPaymentRaw(`/v1/exa/${path6}`, body);
8874
8906
  }
8875
8907
  /**
8876
8908
  * Neural and keyword web search via Exa (Solana payment, $0.01/request).
@@ -8920,8 +8952,8 @@ var SolanaLLMClient = class {
8920
8952
  * "prices/coingecko:bitcoin,base:0x..."
8921
8953
  * @param params - Query parameters passed through to DefiLlama
8922
8954
  */
8923
- async defi(path5, params) {
8924
- return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
8955
+ async defi(path6, params) {
8956
+ return this.getWithPaymentRaw(`/v1/defillama/${path6}`, params);
8925
8957
  }
8926
8958
  /** All DeFi protocols with TVL ($0.005/call). */
8927
8959
  async defiProtocols() {
@@ -8957,9 +8989,9 @@ var SolanaLLMClient = class {
8957
8989
  * @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
8958
8990
  * @param body - JSON body — pass to switch to POST (gasless/submit only)
8959
8991
  */
8960
- async dex(path5, params, body) {
8961
- if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
8962
- return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
8992
+ async dex(path6, params, body) {
8993
+ if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path6}`, body);
8994
+ return this.getWithPaymentRaw(`/v1/zerox/${path6}`, params);
8963
8995
  }
8964
8996
  /** Indicative Permit2 swap price — no commitment (free). */
8965
8997
  async dexPrice(params) {
@@ -9003,8 +9035,8 @@ var SolanaLLMClient = class {
9003
9035
  * "sandbox/status", "sandbox/terminate" ($0.001 each)
9004
9036
  * @param body - JSON body for the endpoint
9005
9037
  */
9006
- async modal(path5, body) {
9007
- return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
9038
+ async modal(path6, body) {
9039
+ return this.requestWithPaymentRaw(`/v1/modal/${path6}`, body ?? {});
9008
9040
  }
9009
9041
  /** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
9010
9042
  async modalSandboxCreate(body) {
@@ -9321,13 +9353,13 @@ function solanaClient(options = {}) {
9321
9353
  }
9322
9354
 
9323
9355
  // src/cache.ts
9324
- var fs4 = __toESM(require("fs"), 1);
9325
- var path4 = __toESM(require("path"), 1);
9356
+ var fs6 = __toESM(require("fs"), 1);
9357
+ var path5 = __toESM(require("path"), 1);
9326
9358
  var os4 = __toESM(require("os"), 1);
9327
9359
  var crypto2 = __toESM(require("crypto"), 1);
9328
- var CACHE_DIR = path4.join(os4.homedir(), ".blockrun", "cache");
9329
- var DATA_DIR = path4.join(os4.homedir(), ".blockrun", "data");
9330
- var COST_LOG_FILE2 = path4.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
9360
+ var CACHE_DIR = path5.join(os4.homedir(), ".blockrun", "cache");
9361
+ var DATA_DIR = path5.join(os4.homedir(), ".blockrun", "data");
9362
+ var COST_LOG_FILE2 = path5.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
9331
9363
  var DEFAULT_TTL = {
9332
9364
  "/v1/partner/": 3600 * 1e3,
9333
9365
  "/v1/pm/": 1800 * 1e3,
@@ -9347,19 +9379,19 @@ function cacheKey(endpoint, body) {
9347
9379
  return crypto2.createHash("sha256").update(keyData).digest("hex").slice(0, 16);
9348
9380
  }
9349
9381
  function cachePath(key) {
9350
- return path4.join(CACHE_DIR, `${key}.json`);
9382
+ return path5.join(CACHE_DIR, `${key}.json`);
9351
9383
  }
9352
9384
  function getCached(key) {
9353
9385
  const filePath = cachePath(key);
9354
- if (!fs4.existsSync(filePath)) return null;
9386
+ if (!fs6.existsSync(filePath)) return null;
9355
9387
  try {
9356
- const raw = fs4.readFileSync(filePath, "utf-8");
9388
+ const raw = fs6.readFileSync(filePath, "utf-8");
9357
9389
  const entry = JSON.parse(raw);
9358
9390
  const ttl = entry.ttlMs ?? getTtl(entry.endpoint ?? "");
9359
9391
  if (ttl <= 0) return null;
9360
9392
  if (Date.now() - entry.cachedAt > ttl) {
9361
9393
  try {
9362
- fs4.unlinkSync(filePath);
9394
+ fs6.unlinkSync(filePath);
9363
9395
  } catch {
9364
9396
  }
9365
9397
  return null;
@@ -9378,7 +9410,7 @@ function getCachedByRequest(endpoint, body) {
9378
9410
  function setCache(key, data, ttlMs) {
9379
9411
  if (ttlMs <= 0) return;
9380
9412
  try {
9381
- fs4.mkdirSync(CACHE_DIR, { recursive: true });
9413
+ fs6.mkdirSync(CACHE_DIR, { recursive: true });
9382
9414
  } catch {
9383
9415
  }
9384
9416
  const entry = {
@@ -9387,7 +9419,7 @@ function setCache(key, data, ttlMs) {
9387
9419
  ttlMs
9388
9420
  };
9389
9421
  try {
9390
- fs4.writeFileSync(cachePath(key), JSON.stringify(entry));
9422
+ fs6.writeFileSync(cachePath(key), JSON.stringify(entry));
9391
9423
  } catch {
9392
9424
  }
9393
9425
  }
@@ -9408,7 +9440,7 @@ function readableFilename(endpoint, body) {
9408
9440
  }
9409
9441
  function saveReadable(endpoint, body, response, costUsd) {
9410
9442
  try {
9411
- fs4.mkdirSync(DATA_DIR, { recursive: true });
9443
+ fs6.mkdirSync(DATA_DIR, { recursive: true });
9412
9444
  } catch {
9413
9445
  }
9414
9446
  const filename = readableFilename(endpoint, body);
@@ -9420,14 +9452,14 @@ function saveReadable(endpoint, body, response, costUsd) {
9420
9452
  response
9421
9453
  };
9422
9454
  try {
9423
- fs4.writeFileSync(path4.join(DATA_DIR, filename), JSON.stringify(entry, null, 2));
9455
+ fs6.writeFileSync(path5.join(DATA_DIR, filename), JSON.stringify(entry, null, 2));
9424
9456
  } catch {
9425
9457
  }
9426
9458
  }
9427
9459
  function appendCostLog(endpoint, costUsd) {
9428
9460
  if (costUsd <= 0) return;
9429
9461
  try {
9430
- fs4.mkdirSync(path4.dirname(COST_LOG_FILE2), { recursive: true });
9462
+ fs6.mkdirSync(path5.dirname(COST_LOG_FILE2), { recursive: true });
9431
9463
  } catch {
9432
9464
  }
9433
9465
  const entry = {
@@ -9436,7 +9468,7 @@ function appendCostLog(endpoint, costUsd) {
9436
9468
  cost_usd: costUsd
9437
9469
  };
9438
9470
  try {
9439
- fs4.appendFileSync(COST_LOG_FILE2, JSON.stringify(entry) + "\n");
9471
+ fs6.appendFileSync(COST_LOG_FILE2, JSON.stringify(entry) + "\n");
9440
9472
  } catch {
9441
9473
  }
9442
9474
  }
@@ -9444,7 +9476,7 @@ function saveToCache(endpoint, body, response, costUsd = 0) {
9444
9476
  const ttl = getTtl(endpoint);
9445
9477
  if (ttl > 0) {
9446
9478
  try {
9447
- fs4.mkdirSync(CACHE_DIR, { recursive: true });
9479
+ fs6.mkdirSync(CACHE_DIR, { recursive: true });
9448
9480
  } catch {
9449
9481
  }
9450
9482
  const key = cacheKey(endpoint, body);
@@ -9456,7 +9488,7 @@ function saveToCache(endpoint, body, response, costUsd = 0) {
9456
9488
  costUsd
9457
9489
  };
9458
9490
  try {
9459
- fs4.writeFileSync(cachePath(key), JSON.stringify(entry));
9491
+ fs6.writeFileSync(cachePath(key), JSON.stringify(entry));
9460
9492
  } catch {
9461
9493
  }
9462
9494
  }
@@ -9464,14 +9496,14 @@ function saveToCache(endpoint, body, response, costUsd = 0) {
9464
9496
  appendCostLog(endpoint, costUsd);
9465
9497
  }
9466
9498
  function clearCache() {
9467
- if (!fs4.existsSync(CACHE_DIR)) return 0;
9499
+ if (!fs6.existsSync(CACHE_DIR)) return 0;
9468
9500
  let count = 0;
9469
9501
  try {
9470
- const files = fs4.readdirSync(CACHE_DIR);
9502
+ const files = fs6.readdirSync(CACHE_DIR);
9471
9503
  for (const file of files) {
9472
9504
  if (file.endsWith(".json")) {
9473
9505
  try {
9474
- fs4.unlinkSync(path4.join(CACHE_DIR, file));
9506
+ fs6.unlinkSync(path5.join(CACHE_DIR, file));
9475
9507
  count++;
9476
9508
  } catch {
9477
9509
  }
@@ -9482,14 +9514,14 @@ function clearCache() {
9482
9514
  return count;
9483
9515
  }
9484
9516
  function getCostLogSummary() {
9485
- if (!fs4.existsSync(COST_LOG_FILE2)) {
9517
+ if (!fs6.existsSync(COST_LOG_FILE2)) {
9486
9518
  return { totalUsd: 0, calls: 0, byEndpoint: {} };
9487
9519
  }
9488
9520
  let totalUsd = 0;
9489
9521
  let calls = 0;
9490
9522
  const byEndpoint = {};
9491
9523
  try {
9492
- const content = fs4.readFileSync(COST_LOG_FILE2, "utf-8").trim();
9524
+ const content = fs6.readFileSync(COST_LOG_FILE2, "utf-8").trim();
9493
9525
  if (!content) return { totalUsd: 0, calls: 0, byEndpoint: {} };
9494
9526
  for (const line of content.split("\n")) {
9495
9527
  if (!line) continue;
@@ -9703,7 +9735,7 @@ var OpenAI = class {
9703
9735
  };
9704
9736
 
9705
9737
  // src/anthropic-compat.ts
9706
- var import_accounts16 = require("viem/accounts");
9738
+ var import_accounts17 = require("viem/accounts");
9707
9739
  var AnthropicClient = class {
9708
9740
  _client = null;
9709
9741
  _clientPromise = null;
@@ -9716,7 +9748,7 @@ var AnthropicClient = class {
9716
9748
  const key = options.privateKey ?? wallet.privateKey;
9717
9749
  validatePrivateKey(key);
9718
9750
  this._privateKey = key;
9719
- this._account = (0, import_accounts16.privateKeyToAccount)(this._privateKey);
9751
+ this._account = (0, import_accounts17.privateKeyToAccount)(this._privateKey);
9720
9752
  const apiUrl = options.apiUrl ?? "https://blockrun.ai/api";
9721
9753
  validateApiUrl(apiUrl);
9722
9754
  this._apiUrl = apiUrl.replace(/\/$/, "");