@blockrun/llm 0.1.1 → 0.2.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/{chunk-R7MQBF5Y.mjs → chunk-4LEERQOK.js} +1 -1
- package/dist/{esm-3BUZROFC.mjs → esm-W3HWUFAT.js} +2 -2
- package/dist/index.cjs +1074 -0
- package/dist/index.d.cts +587 -0
- package/dist/index.d.ts +294 -2
- package/dist/{index.esm-FLTVMT4C.mjs → index.esm-DGL5QIKD.js} +2 -2
- package/dist/index.js +490 -36439
- package/package.json +11 -6
- package/dist/chunk-FCKQTBEP.mjs +0 -90
- package/dist/chunk-TYQEUMVI.mjs +0 -206
- package/dist/index.d.mts +0 -295
- package/dist/index.mjs +0 -428
- package/dist/validation-FPOEEOR4.mjs +0 -15
- package/dist/x402-ELHVFRUU.mjs +0 -27
- /package/dist/{chunk-HEBXNMVQ.mjs → chunk-2ESYSVXG.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface ChatUsage {
|
|
|
14
14
|
prompt_tokens: number;
|
|
15
15
|
completion_tokens: number;
|
|
16
16
|
total_tokens: number;
|
|
17
|
+
num_sources_used?: number;
|
|
17
18
|
}
|
|
18
19
|
interface ChatResponse {
|
|
19
20
|
id: string;
|
|
@@ -22,6 +23,7 @@ interface ChatResponse {
|
|
|
22
23
|
model: string;
|
|
23
24
|
choices: ChatChoice[];
|
|
24
25
|
usage?: ChatUsage;
|
|
26
|
+
citations?: string[];
|
|
25
27
|
}
|
|
26
28
|
interface Model {
|
|
27
29
|
id: string;
|
|
@@ -33,6 +35,83 @@ interface Model {
|
|
|
33
35
|
contextWindow: number;
|
|
34
36
|
maxOutput: number;
|
|
35
37
|
available: boolean;
|
|
38
|
+
type?: "llm" | "image";
|
|
39
|
+
}
|
|
40
|
+
interface ImageData {
|
|
41
|
+
url: string;
|
|
42
|
+
revised_prompt?: string;
|
|
43
|
+
b64_json?: string;
|
|
44
|
+
}
|
|
45
|
+
interface ImageResponse {
|
|
46
|
+
created: number;
|
|
47
|
+
data: ImageData[];
|
|
48
|
+
}
|
|
49
|
+
interface ImageModel {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
provider: string;
|
|
53
|
+
description: string;
|
|
54
|
+
pricePerImage: number;
|
|
55
|
+
supportedSizes?: string[];
|
|
56
|
+
maxPromptLength?: number;
|
|
57
|
+
available: boolean;
|
|
58
|
+
type?: "llm" | "image";
|
|
59
|
+
}
|
|
60
|
+
interface ImageClientOptions {
|
|
61
|
+
/** EVM wallet private key (hex string starting with 0x) */
|
|
62
|
+
privateKey?: `0x${string}` | string;
|
|
63
|
+
/** API endpoint URL (default: https://blockrun.ai/api) */
|
|
64
|
+
apiUrl?: string;
|
|
65
|
+
/** Request timeout in milliseconds (default: 120000 for images) */
|
|
66
|
+
timeout?: number;
|
|
67
|
+
}
|
|
68
|
+
interface ImageGenerateOptions {
|
|
69
|
+
/** Model ID (default: "google/nano-banana") */
|
|
70
|
+
model?: string;
|
|
71
|
+
/** Image size (default: "1024x1024") */
|
|
72
|
+
size?: string;
|
|
73
|
+
/** Number of images to generate (default: 1) */
|
|
74
|
+
n?: number;
|
|
75
|
+
/** Image quality (for supported models) */
|
|
76
|
+
quality?: "standard" | "hd";
|
|
77
|
+
}
|
|
78
|
+
interface WebSearchSource {
|
|
79
|
+
type: "web";
|
|
80
|
+
country?: string;
|
|
81
|
+
excludedWebsites?: string[];
|
|
82
|
+
allowedWebsites?: string[];
|
|
83
|
+
safeSearch?: boolean;
|
|
84
|
+
}
|
|
85
|
+
interface XSearchSource {
|
|
86
|
+
type: "x";
|
|
87
|
+
includedXHandles?: string[];
|
|
88
|
+
excludedXHandles?: string[];
|
|
89
|
+
postFavoriteCount?: number;
|
|
90
|
+
postViewCount?: number;
|
|
91
|
+
}
|
|
92
|
+
interface NewsSearchSource {
|
|
93
|
+
type: "news";
|
|
94
|
+
country?: string;
|
|
95
|
+
excludedWebsites?: string[];
|
|
96
|
+
allowedWebsites?: string[];
|
|
97
|
+
safeSearch?: boolean;
|
|
98
|
+
}
|
|
99
|
+
interface RssSearchSource {
|
|
100
|
+
type: "rss";
|
|
101
|
+
links: string[];
|
|
102
|
+
}
|
|
103
|
+
type SearchSource = WebSearchSource | XSearchSource | NewsSearchSource | RssSearchSource;
|
|
104
|
+
interface SearchParameters {
|
|
105
|
+
mode?: "off" | "auto" | "on";
|
|
106
|
+
sources?: SearchSource[];
|
|
107
|
+
returnCitations?: boolean;
|
|
108
|
+
fromDate?: string;
|
|
109
|
+
toDate?: string;
|
|
110
|
+
maxSearchResults?: number;
|
|
111
|
+
}
|
|
112
|
+
interface Spending {
|
|
113
|
+
totalUsd: number;
|
|
114
|
+
calls: number;
|
|
36
115
|
}
|
|
37
116
|
interface LLMClientOptions {
|
|
38
117
|
/** EVM wallet private key (hex string starting with 0x). Optional if BASE_CHAIN_WALLET_KEY env var is set. */
|
|
@@ -51,6 +130,10 @@ interface ChatOptions {
|
|
|
51
130
|
temperature?: number;
|
|
52
131
|
/** Nucleus sampling parameter */
|
|
53
132
|
topP?: number;
|
|
133
|
+
/** Enable xAI Live Search (shortcut for searchParameters.mode = "on") */
|
|
134
|
+
search?: boolean;
|
|
135
|
+
/** Full xAI Live Search configuration (for Grok models) */
|
|
136
|
+
searchParameters?: SearchParameters;
|
|
54
137
|
}
|
|
55
138
|
interface ChatCompletionOptions {
|
|
56
139
|
/** Max tokens to generate */
|
|
@@ -59,6 +142,10 @@ interface ChatCompletionOptions {
|
|
|
59
142
|
temperature?: number;
|
|
60
143
|
/** Nucleus sampling parameter */
|
|
61
144
|
topP?: number;
|
|
145
|
+
/** Enable xAI Live Search (shortcut for searchParameters.mode = "on") */
|
|
146
|
+
search?: boolean;
|
|
147
|
+
/** Full xAI Live Search configuration (for Grok models) */
|
|
148
|
+
searchParameters?: SearchParameters;
|
|
62
149
|
}
|
|
63
150
|
declare class BlockrunError extends Error {
|
|
64
151
|
constructor(message: string);
|
|
@@ -99,6 +186,8 @@ declare class LLMClient {
|
|
|
99
186
|
private privateKey;
|
|
100
187
|
private apiUrl;
|
|
101
188
|
private timeout;
|
|
189
|
+
private sessionTotalUsd;
|
|
190
|
+
private sessionCalls;
|
|
102
191
|
/**
|
|
103
192
|
* Initialize the BlockRun LLM client.
|
|
104
193
|
*
|
|
@@ -140,13 +229,117 @@ declare class LLMClient {
|
|
|
140
229
|
*/
|
|
141
230
|
private fetchWithTimeout;
|
|
142
231
|
/**
|
|
143
|
-
* List available models with pricing.
|
|
232
|
+
* List available LLM models with pricing.
|
|
144
233
|
*/
|
|
145
234
|
listModels(): Promise<Model[]>;
|
|
235
|
+
/**
|
|
236
|
+
* List available image generation models with pricing.
|
|
237
|
+
*/
|
|
238
|
+
listImageModels(): Promise<ImageModel[]>;
|
|
239
|
+
/**
|
|
240
|
+
* List all available models (both LLM and image) with pricing.
|
|
241
|
+
*
|
|
242
|
+
* @returns Array of all models with 'type' field ('llm' or 'image')
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* const models = await client.listAllModels();
|
|
246
|
+
* for (const model of models) {
|
|
247
|
+
* if (model.type === 'llm') {
|
|
248
|
+
* console.log(`LLM: ${model.id} - $${model.inputPrice}/M input`);
|
|
249
|
+
* } else {
|
|
250
|
+
* console.log(`Image: ${model.id} - $${model.pricePerImage}/image`);
|
|
251
|
+
* }
|
|
252
|
+
* }
|
|
253
|
+
*/
|
|
254
|
+
listAllModels(): Promise<(Model | ImageModel)[]>;
|
|
255
|
+
/**
|
|
256
|
+
* Get current session spending.
|
|
257
|
+
*
|
|
258
|
+
* @returns Object with totalUsd and calls count
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* const spending = client.getSpending();
|
|
262
|
+
* console.log(`Spent $${spending.totalUsd.toFixed(4)} across ${spending.calls} calls`);
|
|
263
|
+
*/
|
|
264
|
+
getSpending(): Spending;
|
|
265
|
+
/**
|
|
266
|
+
* Get the wallet address being used for payments.
|
|
267
|
+
*/
|
|
268
|
+
getWalletAddress(): string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* BlockRun Image Client - Generate images via x402 micropayments.
|
|
273
|
+
*
|
|
274
|
+
* SECURITY NOTE - Private Key Handling:
|
|
275
|
+
* Your private key NEVER leaves your machine. Here's what happens:
|
|
276
|
+
* 1. Key stays local - only used to sign an EIP-712 typed data message
|
|
277
|
+
* 2. Only the SIGNATURE is sent in the PAYMENT-SIGNATURE header
|
|
278
|
+
* 3. BlockRun verifies the signature on-chain via Coinbase CDP facilitator
|
|
279
|
+
*
|
|
280
|
+
* Usage:
|
|
281
|
+
* import { ImageClient } from '@blockrun/llm';
|
|
282
|
+
*
|
|
283
|
+
* const client = new ImageClient({ privateKey: '0x...' });
|
|
284
|
+
* const result = await client.generate('A cute cat in space');
|
|
285
|
+
* console.log(result.data[0].url);
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* BlockRun Image Generation Client.
|
|
290
|
+
*
|
|
291
|
+
* Generate images using Nano Banana (Google Gemini), DALL-E 3, or GPT Image
|
|
292
|
+
* with automatic x402 micropayments on Base chain.
|
|
293
|
+
*/
|
|
294
|
+
declare class ImageClient {
|
|
295
|
+
private account;
|
|
296
|
+
private privateKey;
|
|
297
|
+
private apiUrl;
|
|
298
|
+
private timeout;
|
|
299
|
+
private sessionTotalUsd;
|
|
300
|
+
private sessionCalls;
|
|
301
|
+
/**
|
|
302
|
+
* Initialize the BlockRun Image client.
|
|
303
|
+
*
|
|
304
|
+
* @param options - Client configuration options
|
|
305
|
+
*/
|
|
306
|
+
constructor(options?: ImageClientOptions);
|
|
307
|
+
/**
|
|
308
|
+
* Generate an image from a text prompt.
|
|
309
|
+
*
|
|
310
|
+
* @param prompt - Text description of the image to generate
|
|
311
|
+
* @param options - Optional generation parameters
|
|
312
|
+
* @returns ImageResponse with generated image URLs
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* const result = await client.generate('A sunset over mountains');
|
|
316
|
+
* console.log(result.data[0].url);
|
|
317
|
+
*/
|
|
318
|
+
generate(prompt: string, options?: ImageGenerateOptions): Promise<ImageResponse>;
|
|
319
|
+
/**
|
|
320
|
+
* List available image generation models with pricing.
|
|
321
|
+
*/
|
|
322
|
+
listImageModels(): Promise<ImageModel[]>;
|
|
323
|
+
/**
|
|
324
|
+
* Make a request with automatic x402 payment handling.
|
|
325
|
+
*/
|
|
326
|
+
private requestWithPayment;
|
|
327
|
+
/**
|
|
328
|
+
* Handle 402 response: parse requirements, sign payment, retry.
|
|
329
|
+
*/
|
|
330
|
+
private handlePaymentAndRetry;
|
|
331
|
+
/**
|
|
332
|
+
* Fetch with timeout.
|
|
333
|
+
*/
|
|
334
|
+
private fetchWithTimeout;
|
|
146
335
|
/**
|
|
147
336
|
* Get the wallet address being used for payments.
|
|
148
337
|
*/
|
|
149
338
|
getWalletAddress(): string;
|
|
339
|
+
/**
|
|
340
|
+
* Get session spending information.
|
|
341
|
+
*/
|
|
342
|
+
getSpending(): Spending;
|
|
150
343
|
}
|
|
151
344
|
|
|
152
345
|
/**
|
|
@@ -159,6 +352,105 @@ declare class LLMClient {
|
|
|
159
352
|
declare const BASE_CHAIN_ID = 8453;
|
|
160
353
|
declare const USDC_BASE: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
161
354
|
|
|
355
|
+
/**
|
|
356
|
+
* BlockRun Wallet Management - Auto-create and manage wallets.
|
|
357
|
+
*
|
|
358
|
+
* Provides frictionless wallet setup for new users:
|
|
359
|
+
* - Auto-creates wallet if none exists
|
|
360
|
+
* - Stores key securely at ~/.blockrun/.session
|
|
361
|
+
* - Generates EIP-681 URIs for easy MetaMask funding
|
|
362
|
+
*/
|
|
363
|
+
declare const USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
364
|
+
interface WalletInfo {
|
|
365
|
+
privateKey: string;
|
|
366
|
+
address: string;
|
|
367
|
+
isNew: boolean;
|
|
368
|
+
}
|
|
369
|
+
interface PaymentLinks {
|
|
370
|
+
basescan: string;
|
|
371
|
+
walletLink: string;
|
|
372
|
+
ethereum: string;
|
|
373
|
+
blockrun: string;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Create a new Ethereum wallet.
|
|
377
|
+
*
|
|
378
|
+
* @returns Object with address and privateKey
|
|
379
|
+
*/
|
|
380
|
+
declare function createWallet(): {
|
|
381
|
+
address: string;
|
|
382
|
+
privateKey: string;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Save wallet private key to ~/.blockrun/.session
|
|
386
|
+
*
|
|
387
|
+
* @param privateKey - Private key string (with 0x prefix)
|
|
388
|
+
* @returns Path to saved wallet file
|
|
389
|
+
*/
|
|
390
|
+
declare function saveWallet(privateKey: string): string;
|
|
391
|
+
/**
|
|
392
|
+
* Load wallet private key from file.
|
|
393
|
+
*
|
|
394
|
+
* @returns Private key string or null if not found
|
|
395
|
+
*/
|
|
396
|
+
declare function loadWallet(): string | null;
|
|
397
|
+
/**
|
|
398
|
+
* Get existing wallet or create new one.
|
|
399
|
+
*
|
|
400
|
+
* Priority:
|
|
401
|
+
* 1. BLOCKRUN_WALLET_KEY environment variable
|
|
402
|
+
* 2. ~/.blockrun/.session file
|
|
403
|
+
* 3. ~/.blockrun/wallet.key file (legacy)
|
|
404
|
+
* 4. Create new wallet
|
|
405
|
+
*
|
|
406
|
+
* @returns WalletInfo with address, privateKey, and isNew flag
|
|
407
|
+
*/
|
|
408
|
+
declare function getOrCreateWallet(): WalletInfo;
|
|
409
|
+
/**
|
|
410
|
+
* Get wallet address without exposing private key.
|
|
411
|
+
*
|
|
412
|
+
* @returns Wallet address or null if no wallet configured
|
|
413
|
+
*/
|
|
414
|
+
declare function getWalletAddress(): string | null;
|
|
415
|
+
/**
|
|
416
|
+
* Generate EIP-681 URI for USDC transfer on Base.
|
|
417
|
+
*
|
|
418
|
+
* @param address - Recipient Ethereum address
|
|
419
|
+
* @param amountUsdc - Amount in USDC (default 1.0)
|
|
420
|
+
* @returns EIP-681 URI string for MetaMask/wallet scanning
|
|
421
|
+
*/
|
|
422
|
+
declare function getEip681Uri(address: string, amountUsdc?: number): string;
|
|
423
|
+
/**
|
|
424
|
+
* Generate payment links for the wallet address.
|
|
425
|
+
*
|
|
426
|
+
* @param address - Ethereum address
|
|
427
|
+
* @returns Object with various payment links
|
|
428
|
+
*/
|
|
429
|
+
declare function getPaymentLinks(address: string): PaymentLinks;
|
|
430
|
+
/**
|
|
431
|
+
* Format the message shown when a new wallet is created.
|
|
432
|
+
*
|
|
433
|
+
* @param address - New wallet address
|
|
434
|
+
* @returns Formatted message string
|
|
435
|
+
*/
|
|
436
|
+
declare function formatWalletCreatedMessage(address: string): string;
|
|
437
|
+
/**
|
|
438
|
+
* Format the message shown when wallet needs more funds.
|
|
439
|
+
*
|
|
440
|
+
* @param address - Wallet address
|
|
441
|
+
* @returns Formatted message string
|
|
442
|
+
*/
|
|
443
|
+
declare function formatNeedsFundingMessage(address: string): string;
|
|
444
|
+
/**
|
|
445
|
+
* Compact funding message (no QR) for repeated displays.
|
|
446
|
+
*
|
|
447
|
+
* @param address - Wallet address
|
|
448
|
+
* @returns Short formatted message string
|
|
449
|
+
*/
|
|
450
|
+
declare function formatFundingMessageCompact(address: string): string;
|
|
451
|
+
declare const WALLET_FILE_PATH: string;
|
|
452
|
+
declare const WALLET_DIR_PATH: string;
|
|
453
|
+
|
|
162
454
|
/**
|
|
163
455
|
* OpenAI-compatible API wrapper for BlockRun LLM SDK.
|
|
164
456
|
*
|
|
@@ -292,4 +584,4 @@ declare class OpenAI {
|
|
|
292
584
|
getWalletAddress(): string;
|
|
293
585
|
}
|
|
294
586
|
|
|
295
|
-
export { APIError, BASE_CHAIN_ID, BlockrunError, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatUsage, LLMClient, type LLMClientOptions, type Model, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PaymentError, USDC_BASE, LLMClient as default };
|
|
587
|
+
export { APIError, BASE_CHAIN_ID, BlockrunError, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatUsage, ImageClient, type ImageClientOptions, type ImageData, type ImageGenerateOptions, type ImageModel, type ImageResponse, LLMClient, type LLMClientOptions, type Model, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PaymentError, type PaymentLinks, type RssSearchSource, type SearchParameters, type SearchSource, type Spending, USDC_BASE, USDC_BASE_CONTRACT, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, createWallet, LLMClient as default, formatFundingMessageCompact, formatNeedsFundingMessage, formatWalletCreatedMessage, getEip681Uri, getOrCreateWallet, getPaymentLinks, getWalletAddress, loadWallet, saveWallet };
|
|
@@ -75,8 +75,8 @@ import {
|
|
|
75
75
|
clusterApiUrl,
|
|
76
76
|
sendAndConfirmRawTransaction,
|
|
77
77
|
sendAndConfirmTransaction
|
|
78
|
-
} from "./chunk-
|
|
79
|
-
import "./chunk-
|
|
78
|
+
} from "./chunk-4LEERQOK.js";
|
|
79
|
+
import "./chunk-2ESYSVXG.js";
|
|
80
80
|
export {
|
|
81
81
|
Account,
|
|
82
82
|
AddressLookupTableAccount,
|