@blockrun/llm 0.3.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -24
- package/dist/{chunk-S7BEMV6T.js → chunk-KRDGCX7W.js} +25914 -25839
- package/dist/{esm-EBZAIN5N.js → esm-PTFDM6PE.js} +159 -6
- package/dist/index.cjs +36985 -37
- package/dist/index.d.cts +179 -1
- package/dist/index.d.ts +179 -1
- package/dist/{index.esm-WP2DIBSK.js → index.esm-SXKIFLA7.js} +3 -2
- package/dist/index.js +421 -1
- package/package.json +71 -70
- package/dist/chunk-2ESYSVXG.js +0 -48
package/dist/index.d.cts
CHANGED
|
@@ -179,6 +179,32 @@ interface ChatCompletionOptions {
|
|
|
179
179
|
/** Tool selection strategy */
|
|
180
180
|
toolChoice?: ToolChoice;
|
|
181
181
|
}
|
|
182
|
+
type RoutingProfile = "free" | "eco" | "auto" | "premium";
|
|
183
|
+
type RoutingTier = "SIMPLE" | "MEDIUM" | "COMPLEX" | "REASONING";
|
|
184
|
+
interface RoutingDecision {
|
|
185
|
+
model: string;
|
|
186
|
+
tier: RoutingTier;
|
|
187
|
+
confidence: number;
|
|
188
|
+
method: "rules" | "llm";
|
|
189
|
+
reasoning: string;
|
|
190
|
+
costEstimate: number;
|
|
191
|
+
baselineCost: number;
|
|
192
|
+
savings: number;
|
|
193
|
+
}
|
|
194
|
+
interface SmartChatOptions extends ChatOptions {
|
|
195
|
+
/** Routing profile: free (zero cost), eco (budget), auto (balanced), premium (best quality) */
|
|
196
|
+
routingProfile?: RoutingProfile;
|
|
197
|
+
/** Maximum output tokens (used for cost estimation) */
|
|
198
|
+
maxOutputTokens?: number;
|
|
199
|
+
}
|
|
200
|
+
interface SmartChatResponse {
|
|
201
|
+
/** The AI response text */
|
|
202
|
+
response: string;
|
|
203
|
+
/** Which model was selected by smart routing */
|
|
204
|
+
model: string;
|
|
205
|
+
/** Routing decision metadata */
|
|
206
|
+
routing: RoutingDecision;
|
|
207
|
+
}
|
|
182
208
|
declare class BlockrunError extends Error {
|
|
183
209
|
constructor(message: string);
|
|
184
210
|
}
|
|
@@ -240,6 +266,8 @@ declare class LLMClient {
|
|
|
240
266
|
private timeout;
|
|
241
267
|
private sessionTotalUsd;
|
|
242
268
|
private sessionCalls;
|
|
269
|
+
private modelPricingCache;
|
|
270
|
+
private modelPricingPromise;
|
|
243
271
|
/**
|
|
244
272
|
* Initialize the BlockRun LLM client.
|
|
245
273
|
*
|
|
@@ -259,6 +287,46 @@ declare class LLMClient {
|
|
|
259
287
|
* console.log(response); // 'The capital of France is Paris.'
|
|
260
288
|
*/
|
|
261
289
|
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
290
|
+
/**
|
|
291
|
+
* Smart chat with automatic model routing.
|
|
292
|
+
*
|
|
293
|
+
* Uses ClawRouter's 14-dimension rule-based scoring algorithm (<1ms, 100% local)
|
|
294
|
+
* to select the cheapest model that can handle your request.
|
|
295
|
+
*
|
|
296
|
+
* @param prompt - User message
|
|
297
|
+
* @param options - Optional chat and routing parameters
|
|
298
|
+
* @returns SmartChatResponse with response text, selected model, and routing metadata
|
|
299
|
+
*
|
|
300
|
+
* @example Simple usage (auto profile)
|
|
301
|
+
* ```ts
|
|
302
|
+
* const result = await client.smartChat('What is 2+2?');
|
|
303
|
+
* console.log(result.response); // '4'
|
|
304
|
+
* console.log(result.model); // 'google/gemini-2.5-flash-lite'
|
|
305
|
+
* console.log(result.routing.savings); // 0.78 (78% savings)
|
|
306
|
+
* ```
|
|
307
|
+
*
|
|
308
|
+
* @example With routing profile
|
|
309
|
+
* ```ts
|
|
310
|
+
* // Free tier only (zero cost)
|
|
311
|
+
* const result = await client.smartChat('Hello!', { routingProfile: 'free' });
|
|
312
|
+
*
|
|
313
|
+
* // Eco mode (budget optimized)
|
|
314
|
+
* const result = await client.smartChat('Explain quantum computing', { routingProfile: 'eco' });
|
|
315
|
+
*
|
|
316
|
+
* // Premium mode (best quality)
|
|
317
|
+
* const result = await client.smartChat('Write a business plan', { routingProfile: 'premium' });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
smartChat(prompt: string, options?: SmartChatOptions): Promise<SmartChatResponse>;
|
|
321
|
+
/**
|
|
322
|
+
* Get model pricing map (cached).
|
|
323
|
+
* Fetches from API on first call, then returns cached result.
|
|
324
|
+
*/
|
|
325
|
+
private getModelPricing;
|
|
326
|
+
/**
|
|
327
|
+
* Fetch model pricing from API.
|
|
328
|
+
*/
|
|
329
|
+
private fetchModelPricing;
|
|
262
330
|
/**
|
|
263
331
|
* Full chat completion interface (OpenAI-compatible).
|
|
264
332
|
*
|
|
@@ -434,6 +502,33 @@ declare class ImageClient {
|
|
|
434
502
|
|
|
435
503
|
declare const BASE_CHAIN_ID = 8453;
|
|
436
504
|
declare const USDC_BASE: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
505
|
+
declare const SOLANA_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
506
|
+
declare const USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
507
|
+
interface CreateSolanaPaymentOptions {
|
|
508
|
+
resourceUrl?: string;
|
|
509
|
+
resourceDescription?: string;
|
|
510
|
+
maxTimeoutSeconds?: number;
|
|
511
|
+
extra?: Record<string, unknown>;
|
|
512
|
+
extensions?: Record<string, unknown>;
|
|
513
|
+
rpcUrl?: string;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Create a signed Solana x402 v2 payment payload.
|
|
517
|
+
*
|
|
518
|
+
* This creates an SPL TransferChecked transaction for USDC payment
|
|
519
|
+
* that the CDP facilitator can verify and settle.
|
|
520
|
+
*
|
|
521
|
+
* Requires @solana/web3.js and @solana/spl-token dependencies.
|
|
522
|
+
*
|
|
523
|
+
* @param secretKey - Solana secret key (Uint8Array, 64 bytes)
|
|
524
|
+
* @param fromAddress - Sender wallet address (base58)
|
|
525
|
+
* @param recipient - Payment recipient address (base58)
|
|
526
|
+
* @param amount - Amount in micro USDC (6 decimals)
|
|
527
|
+
* @param feePayer - CDP facilitator fee payer address (base58)
|
|
528
|
+
* @param options - Additional options
|
|
529
|
+
* @returns Base64-encoded signed payment payload
|
|
530
|
+
*/
|
|
531
|
+
declare function createSolanaPaymentPayload(secretKey: Uint8Array, fromAddress: string, recipient: string, amount: string, feePayer: string, options?: CreateSolanaPaymentOptions): Promise<string>;
|
|
437
532
|
|
|
438
533
|
/**
|
|
439
534
|
* BlockRun Wallet Management - Auto-create and manage wallets.
|
|
@@ -534,6 +629,89 @@ declare function formatFundingMessageCompact(address: string): string;
|
|
|
534
629
|
declare const WALLET_FILE_PATH: string;
|
|
535
630
|
declare const WALLET_DIR_PATH: string;
|
|
536
631
|
|
|
632
|
+
/**
|
|
633
|
+
* BlockRun Solana LLM Client.
|
|
634
|
+
*
|
|
635
|
+
* Usage:
|
|
636
|
+
* import { SolanaLLMClient } from '@blockrun/llm';
|
|
637
|
+
*
|
|
638
|
+
* // SOLANA_WALLET_KEY env var (bs58-encoded Solana secret key)
|
|
639
|
+
* const client = new SolanaLLMClient();
|
|
640
|
+
*
|
|
641
|
+
* // Or pass key directly
|
|
642
|
+
* const client = new SolanaLLMClient({ privateKey: 'your-bs58-key' });
|
|
643
|
+
*
|
|
644
|
+
* const response = await client.chat('openai/gpt-4o', 'gm Solana');
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
interface SolanaLLMClientOptions {
|
|
648
|
+
/** bs58-encoded Solana secret key (64 bytes). Optional if SOLANA_WALLET_KEY env var is set. */
|
|
649
|
+
privateKey?: string;
|
|
650
|
+
/** API endpoint URL (default: https://sol.blockrun.ai/api) */
|
|
651
|
+
apiUrl?: string;
|
|
652
|
+
/** Solana RPC URL (default: https://api.mainnet-beta.solana.com) */
|
|
653
|
+
rpcUrl?: string;
|
|
654
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
655
|
+
timeout?: number;
|
|
656
|
+
}
|
|
657
|
+
declare class SolanaLLMClient {
|
|
658
|
+
static readonly SOLANA_API_URL = "https://sol.blockrun.ai/api";
|
|
659
|
+
private privateKey;
|
|
660
|
+
private apiUrl;
|
|
661
|
+
private rpcUrl;
|
|
662
|
+
private timeout;
|
|
663
|
+
private sessionTotalUsd;
|
|
664
|
+
private sessionCalls;
|
|
665
|
+
private addressCache;
|
|
666
|
+
constructor(options?: SolanaLLMClientOptions);
|
|
667
|
+
/** Get Solana wallet address (public key in base58). */
|
|
668
|
+
getWalletAddress(): Promise<string>;
|
|
669
|
+
/** Simple 1-line chat. */
|
|
670
|
+
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
671
|
+
/** Full chat completion (OpenAI-compatible). */
|
|
672
|
+
chatCompletion(model: string, messages: ChatMessage[], options?: ChatCompletionOptions): Promise<ChatResponse>;
|
|
673
|
+
/** List available models. */
|
|
674
|
+
listModels(): Promise<Model[]>;
|
|
675
|
+
/** Get session spending. */
|
|
676
|
+
getSpending(): Spending;
|
|
677
|
+
/** True if using sol.blockrun.ai. */
|
|
678
|
+
isSolana(): boolean;
|
|
679
|
+
private requestWithPayment;
|
|
680
|
+
private handlePaymentAndRetry;
|
|
681
|
+
private fetchWithTimeout;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Convenience function: create SolanaLLMClient for sol.blockrun.ai.
|
|
685
|
+
*/
|
|
686
|
+
declare function solanaClient(options?: SolanaLLMClientOptions): SolanaLLMClient;
|
|
687
|
+
|
|
688
|
+
declare const SOLANA_WALLET_FILE: string;
|
|
689
|
+
interface SolanaWalletInfo {
|
|
690
|
+
privateKey: string;
|
|
691
|
+
address: string;
|
|
692
|
+
isNew: boolean;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Create a new Solana wallet.
|
|
696
|
+
* Requires @solana/web3.js (optional dep).
|
|
697
|
+
*/
|
|
698
|
+
declare function createSolanaWallet(): {
|
|
699
|
+
address: string;
|
|
700
|
+
privateKey: string;
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* Convert a bs58 private key string to Uint8Array (64 bytes).
|
|
704
|
+
* Accepts: bs58-encoded 64-byte key (standard Solana format).
|
|
705
|
+
*/
|
|
706
|
+
declare function solanaKeyToBytes(privateKey: string): Promise<Uint8Array>;
|
|
707
|
+
/**
|
|
708
|
+
* Get Solana public key (address) from bs58 private key.
|
|
709
|
+
*/
|
|
710
|
+
declare function solanaPublicKey(privateKey: string): Promise<string>;
|
|
711
|
+
declare function saveSolanaWallet(privateKey: string): string;
|
|
712
|
+
declare function loadSolanaWallet(): string | null;
|
|
713
|
+
declare function getOrCreateSolanaWallet(): Promise<SolanaWalletInfo>;
|
|
714
|
+
|
|
537
715
|
/**
|
|
538
716
|
* OpenAI-compatible API wrapper for BlockRun LLM SDK.
|
|
539
717
|
*
|
|
@@ -673,4 +851,4 @@ declare class OpenAI {
|
|
|
673
851
|
getWalletAddress(): string;
|
|
674
852
|
}
|
|
675
853
|
|
|
676
|
-
export { APIError, BASE_CHAIN_ID, BlockrunError, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatUsage, type FunctionCall, type FunctionDefinition, 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, type Tool, type ToolCall, type ToolChoice, 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, testnetClient };
|
|
854
|
+
export { APIError, BASE_CHAIN_ID, BlockrunError, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatUsage, type FunctionCall, type FunctionDefinition, 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 RoutingDecision, type RoutingProfile, type RoutingTier, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, type SearchParameters, type SearchSource, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type Spending, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, formatFundingMessageCompact, formatNeedsFundingMessage, formatWalletCreatedMessage, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, loadSolanaWallet, loadWallet, saveSolanaWallet, saveWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, testnetClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -179,6 +179,32 @@ interface ChatCompletionOptions {
|
|
|
179
179
|
/** Tool selection strategy */
|
|
180
180
|
toolChoice?: ToolChoice;
|
|
181
181
|
}
|
|
182
|
+
type RoutingProfile = "free" | "eco" | "auto" | "premium";
|
|
183
|
+
type RoutingTier = "SIMPLE" | "MEDIUM" | "COMPLEX" | "REASONING";
|
|
184
|
+
interface RoutingDecision {
|
|
185
|
+
model: string;
|
|
186
|
+
tier: RoutingTier;
|
|
187
|
+
confidence: number;
|
|
188
|
+
method: "rules" | "llm";
|
|
189
|
+
reasoning: string;
|
|
190
|
+
costEstimate: number;
|
|
191
|
+
baselineCost: number;
|
|
192
|
+
savings: number;
|
|
193
|
+
}
|
|
194
|
+
interface SmartChatOptions extends ChatOptions {
|
|
195
|
+
/** Routing profile: free (zero cost), eco (budget), auto (balanced), premium (best quality) */
|
|
196
|
+
routingProfile?: RoutingProfile;
|
|
197
|
+
/** Maximum output tokens (used for cost estimation) */
|
|
198
|
+
maxOutputTokens?: number;
|
|
199
|
+
}
|
|
200
|
+
interface SmartChatResponse {
|
|
201
|
+
/** The AI response text */
|
|
202
|
+
response: string;
|
|
203
|
+
/** Which model was selected by smart routing */
|
|
204
|
+
model: string;
|
|
205
|
+
/** Routing decision metadata */
|
|
206
|
+
routing: RoutingDecision;
|
|
207
|
+
}
|
|
182
208
|
declare class BlockrunError extends Error {
|
|
183
209
|
constructor(message: string);
|
|
184
210
|
}
|
|
@@ -240,6 +266,8 @@ declare class LLMClient {
|
|
|
240
266
|
private timeout;
|
|
241
267
|
private sessionTotalUsd;
|
|
242
268
|
private sessionCalls;
|
|
269
|
+
private modelPricingCache;
|
|
270
|
+
private modelPricingPromise;
|
|
243
271
|
/**
|
|
244
272
|
* Initialize the BlockRun LLM client.
|
|
245
273
|
*
|
|
@@ -259,6 +287,46 @@ declare class LLMClient {
|
|
|
259
287
|
* console.log(response); // 'The capital of France is Paris.'
|
|
260
288
|
*/
|
|
261
289
|
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
290
|
+
/**
|
|
291
|
+
* Smart chat with automatic model routing.
|
|
292
|
+
*
|
|
293
|
+
* Uses ClawRouter's 14-dimension rule-based scoring algorithm (<1ms, 100% local)
|
|
294
|
+
* to select the cheapest model that can handle your request.
|
|
295
|
+
*
|
|
296
|
+
* @param prompt - User message
|
|
297
|
+
* @param options - Optional chat and routing parameters
|
|
298
|
+
* @returns SmartChatResponse with response text, selected model, and routing metadata
|
|
299
|
+
*
|
|
300
|
+
* @example Simple usage (auto profile)
|
|
301
|
+
* ```ts
|
|
302
|
+
* const result = await client.smartChat('What is 2+2?');
|
|
303
|
+
* console.log(result.response); // '4'
|
|
304
|
+
* console.log(result.model); // 'google/gemini-2.5-flash-lite'
|
|
305
|
+
* console.log(result.routing.savings); // 0.78 (78% savings)
|
|
306
|
+
* ```
|
|
307
|
+
*
|
|
308
|
+
* @example With routing profile
|
|
309
|
+
* ```ts
|
|
310
|
+
* // Free tier only (zero cost)
|
|
311
|
+
* const result = await client.smartChat('Hello!', { routingProfile: 'free' });
|
|
312
|
+
*
|
|
313
|
+
* // Eco mode (budget optimized)
|
|
314
|
+
* const result = await client.smartChat('Explain quantum computing', { routingProfile: 'eco' });
|
|
315
|
+
*
|
|
316
|
+
* // Premium mode (best quality)
|
|
317
|
+
* const result = await client.smartChat('Write a business plan', { routingProfile: 'premium' });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
smartChat(prompt: string, options?: SmartChatOptions): Promise<SmartChatResponse>;
|
|
321
|
+
/**
|
|
322
|
+
* Get model pricing map (cached).
|
|
323
|
+
* Fetches from API on first call, then returns cached result.
|
|
324
|
+
*/
|
|
325
|
+
private getModelPricing;
|
|
326
|
+
/**
|
|
327
|
+
* Fetch model pricing from API.
|
|
328
|
+
*/
|
|
329
|
+
private fetchModelPricing;
|
|
262
330
|
/**
|
|
263
331
|
* Full chat completion interface (OpenAI-compatible).
|
|
264
332
|
*
|
|
@@ -434,6 +502,33 @@ declare class ImageClient {
|
|
|
434
502
|
|
|
435
503
|
declare const BASE_CHAIN_ID = 8453;
|
|
436
504
|
declare const USDC_BASE: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
505
|
+
declare const SOLANA_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
506
|
+
declare const USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
507
|
+
interface CreateSolanaPaymentOptions {
|
|
508
|
+
resourceUrl?: string;
|
|
509
|
+
resourceDescription?: string;
|
|
510
|
+
maxTimeoutSeconds?: number;
|
|
511
|
+
extra?: Record<string, unknown>;
|
|
512
|
+
extensions?: Record<string, unknown>;
|
|
513
|
+
rpcUrl?: string;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Create a signed Solana x402 v2 payment payload.
|
|
517
|
+
*
|
|
518
|
+
* This creates an SPL TransferChecked transaction for USDC payment
|
|
519
|
+
* that the CDP facilitator can verify and settle.
|
|
520
|
+
*
|
|
521
|
+
* Requires @solana/web3.js and @solana/spl-token dependencies.
|
|
522
|
+
*
|
|
523
|
+
* @param secretKey - Solana secret key (Uint8Array, 64 bytes)
|
|
524
|
+
* @param fromAddress - Sender wallet address (base58)
|
|
525
|
+
* @param recipient - Payment recipient address (base58)
|
|
526
|
+
* @param amount - Amount in micro USDC (6 decimals)
|
|
527
|
+
* @param feePayer - CDP facilitator fee payer address (base58)
|
|
528
|
+
* @param options - Additional options
|
|
529
|
+
* @returns Base64-encoded signed payment payload
|
|
530
|
+
*/
|
|
531
|
+
declare function createSolanaPaymentPayload(secretKey: Uint8Array, fromAddress: string, recipient: string, amount: string, feePayer: string, options?: CreateSolanaPaymentOptions): Promise<string>;
|
|
437
532
|
|
|
438
533
|
/**
|
|
439
534
|
* BlockRun Wallet Management - Auto-create and manage wallets.
|
|
@@ -534,6 +629,89 @@ declare function formatFundingMessageCompact(address: string): string;
|
|
|
534
629
|
declare const WALLET_FILE_PATH: string;
|
|
535
630
|
declare const WALLET_DIR_PATH: string;
|
|
536
631
|
|
|
632
|
+
/**
|
|
633
|
+
* BlockRun Solana LLM Client.
|
|
634
|
+
*
|
|
635
|
+
* Usage:
|
|
636
|
+
* import { SolanaLLMClient } from '@blockrun/llm';
|
|
637
|
+
*
|
|
638
|
+
* // SOLANA_WALLET_KEY env var (bs58-encoded Solana secret key)
|
|
639
|
+
* const client = new SolanaLLMClient();
|
|
640
|
+
*
|
|
641
|
+
* // Or pass key directly
|
|
642
|
+
* const client = new SolanaLLMClient({ privateKey: 'your-bs58-key' });
|
|
643
|
+
*
|
|
644
|
+
* const response = await client.chat('openai/gpt-4o', 'gm Solana');
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
interface SolanaLLMClientOptions {
|
|
648
|
+
/** bs58-encoded Solana secret key (64 bytes). Optional if SOLANA_WALLET_KEY env var is set. */
|
|
649
|
+
privateKey?: string;
|
|
650
|
+
/** API endpoint URL (default: https://sol.blockrun.ai/api) */
|
|
651
|
+
apiUrl?: string;
|
|
652
|
+
/** Solana RPC URL (default: https://api.mainnet-beta.solana.com) */
|
|
653
|
+
rpcUrl?: string;
|
|
654
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
655
|
+
timeout?: number;
|
|
656
|
+
}
|
|
657
|
+
declare class SolanaLLMClient {
|
|
658
|
+
static readonly SOLANA_API_URL = "https://sol.blockrun.ai/api";
|
|
659
|
+
private privateKey;
|
|
660
|
+
private apiUrl;
|
|
661
|
+
private rpcUrl;
|
|
662
|
+
private timeout;
|
|
663
|
+
private sessionTotalUsd;
|
|
664
|
+
private sessionCalls;
|
|
665
|
+
private addressCache;
|
|
666
|
+
constructor(options?: SolanaLLMClientOptions);
|
|
667
|
+
/** Get Solana wallet address (public key in base58). */
|
|
668
|
+
getWalletAddress(): Promise<string>;
|
|
669
|
+
/** Simple 1-line chat. */
|
|
670
|
+
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
671
|
+
/** Full chat completion (OpenAI-compatible). */
|
|
672
|
+
chatCompletion(model: string, messages: ChatMessage[], options?: ChatCompletionOptions): Promise<ChatResponse>;
|
|
673
|
+
/** List available models. */
|
|
674
|
+
listModels(): Promise<Model[]>;
|
|
675
|
+
/** Get session spending. */
|
|
676
|
+
getSpending(): Spending;
|
|
677
|
+
/** True if using sol.blockrun.ai. */
|
|
678
|
+
isSolana(): boolean;
|
|
679
|
+
private requestWithPayment;
|
|
680
|
+
private handlePaymentAndRetry;
|
|
681
|
+
private fetchWithTimeout;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Convenience function: create SolanaLLMClient for sol.blockrun.ai.
|
|
685
|
+
*/
|
|
686
|
+
declare function solanaClient(options?: SolanaLLMClientOptions): SolanaLLMClient;
|
|
687
|
+
|
|
688
|
+
declare const SOLANA_WALLET_FILE: string;
|
|
689
|
+
interface SolanaWalletInfo {
|
|
690
|
+
privateKey: string;
|
|
691
|
+
address: string;
|
|
692
|
+
isNew: boolean;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Create a new Solana wallet.
|
|
696
|
+
* Requires @solana/web3.js (optional dep).
|
|
697
|
+
*/
|
|
698
|
+
declare function createSolanaWallet(): {
|
|
699
|
+
address: string;
|
|
700
|
+
privateKey: string;
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* Convert a bs58 private key string to Uint8Array (64 bytes).
|
|
704
|
+
* Accepts: bs58-encoded 64-byte key (standard Solana format).
|
|
705
|
+
*/
|
|
706
|
+
declare function solanaKeyToBytes(privateKey: string): Promise<Uint8Array>;
|
|
707
|
+
/**
|
|
708
|
+
* Get Solana public key (address) from bs58 private key.
|
|
709
|
+
*/
|
|
710
|
+
declare function solanaPublicKey(privateKey: string): Promise<string>;
|
|
711
|
+
declare function saveSolanaWallet(privateKey: string): string;
|
|
712
|
+
declare function loadSolanaWallet(): string | null;
|
|
713
|
+
declare function getOrCreateSolanaWallet(): Promise<SolanaWalletInfo>;
|
|
714
|
+
|
|
537
715
|
/**
|
|
538
716
|
* OpenAI-compatible API wrapper for BlockRun LLM SDK.
|
|
539
717
|
*
|
|
@@ -673,4 +851,4 @@ declare class OpenAI {
|
|
|
673
851
|
getWalletAddress(): string;
|
|
674
852
|
}
|
|
675
853
|
|
|
676
|
-
export { APIError, BASE_CHAIN_ID, BlockrunError, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatUsage, type FunctionCall, type FunctionDefinition, 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, type Tool, type ToolCall, type ToolChoice, 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, testnetClient };
|
|
854
|
+
export { APIError, BASE_CHAIN_ID, BlockrunError, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatUsage, type FunctionCall, type FunctionDefinition, 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 RoutingDecision, type RoutingProfile, type RoutingTier, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, type SearchParameters, type SearchSource, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type Spending, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, formatFundingMessageCompact, formatNeedsFundingMessage, formatWalletCreatedMessage, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, loadSolanaWallet, loadWallet, saveSolanaWallet, saveWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, testnetClient };
|
|
@@ -73,10 +73,11 @@ import {
|
|
|
73
73
|
VoteInstruction,
|
|
74
74
|
VoteProgram,
|
|
75
75
|
clusterApiUrl,
|
|
76
|
+
init_index_esm,
|
|
76
77
|
sendAndConfirmRawTransaction,
|
|
77
78
|
sendAndConfirmTransaction
|
|
78
|
-
} from "./chunk-
|
|
79
|
-
|
|
79
|
+
} from "./chunk-KRDGCX7W.js";
|
|
80
|
+
init_index_esm();
|
|
80
81
|
export {
|
|
81
82
|
Account,
|
|
82
83
|
AddressLookupTableAccount,
|