@blockrun/llm 3.11.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/README.md +315 -194
- package/dist/index.cjs +3826 -285
- package/dist/index.d.cts +70 -21
- package/dist/index.d.ts +70 -21
- package/dist/index.js +3826 -285
- package/package.json +3 -7
package/dist/index.d.cts
CHANGED
|
@@ -252,6 +252,8 @@ interface ChatResponse {
|
|
|
252
252
|
model?: string;
|
|
253
253
|
settlementSkipped?: boolean;
|
|
254
254
|
};
|
|
255
|
+
/** Present when a `blockrun/auto|eco|premium` alias selected the model locally. */
|
|
256
|
+
routing?: RoutingDecision;
|
|
255
257
|
}
|
|
256
258
|
interface Model {
|
|
257
259
|
id: string;
|
|
@@ -490,8 +492,8 @@ interface ChatCompletionOptions {
|
|
|
490
492
|
type RoutingProfile = "eco" | "auto" | "premium";
|
|
491
493
|
type RoutingTier = Tier;
|
|
492
494
|
/**
|
|
493
|
-
* Request classification produced by the
|
|
494
|
-
*
|
|
495
|
+
* Request classification produced by the bundled Router Core V3 portfolio
|
|
496
|
+
* router. Present on decisions with `method: "portfolio"`.
|
|
495
497
|
*/
|
|
496
498
|
type RoutingTaskType = TaskType;
|
|
497
499
|
/** Primary model + ordered fallbacks for one routing tier. */
|
|
@@ -500,7 +502,7 @@ interface RoutingDecision extends RoutingDecision$1 {
|
|
|
500
502
|
/**
|
|
501
503
|
* Remaining gateway-callable models, in the router's ranked order.
|
|
502
504
|
* `chat()` walks this list when the primary model hits a transient error
|
|
503
|
-
* (timeout, network, 429, 5xx). Excludes the primary itself.
|
|
505
|
+
* (timeout, network, 429, 5xx). Excludes the primary itself. The router's
|
|
504
506
|
* proxy-namespace `free/*` ids appear here as their `nvidia/*` gateway
|
|
505
507
|
* ids (or are dropped when the mapping is proxy-only).
|
|
506
508
|
*/
|
|
@@ -512,6 +514,12 @@ interface SmartChatOptions extends ChatOptions {
|
|
|
512
514
|
/** Maximum output tokens (used for cost estimation) */
|
|
513
515
|
maxOutputTokens?: number;
|
|
514
516
|
}
|
|
517
|
+
interface SmartChatCompletionOptions extends ChatCompletionOptions {
|
|
518
|
+
/** Routing profile: eco (budget), auto (balanced), premium (best quality) */
|
|
519
|
+
routingProfile?: RoutingProfile;
|
|
520
|
+
/** Maximum output tokens used for route cost/capacity estimation. */
|
|
521
|
+
maxOutputTokens?: number;
|
|
522
|
+
}
|
|
515
523
|
interface SmartChatResponse {
|
|
516
524
|
/** The AI response text */
|
|
517
525
|
response: string;
|
|
@@ -520,6 +528,14 @@ interface SmartChatResponse {
|
|
|
520
528
|
/** Routing decision metadata */
|
|
521
529
|
routing: RoutingDecision;
|
|
522
530
|
}
|
|
531
|
+
interface SmartChatCompletionResponse {
|
|
532
|
+
/** Full OpenAI-compatible response, including tool calls. */
|
|
533
|
+
response: ChatResponse;
|
|
534
|
+
/** Model selected before any transient runtime fallback. */
|
|
535
|
+
model: string;
|
|
536
|
+
/** Local routing decision and ordered fallback candidates. */
|
|
537
|
+
routing: RoutingDecision;
|
|
538
|
+
}
|
|
523
539
|
interface SearchResult {
|
|
524
540
|
query: string;
|
|
525
541
|
summary: string;
|
|
@@ -1192,11 +1208,17 @@ declare class LLMClient {
|
|
|
1192
1208
|
* console.log(response); // 'The capital of France is Paris.'
|
|
1193
1209
|
*/
|
|
1194
1210
|
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
1211
|
+
private makeRoutingDecision;
|
|
1212
|
+
/**
|
|
1213
|
+
* Inspect a local routing decision without making or paying for a model call.
|
|
1214
|
+
* The first invocation may fetch the public model catalog for current prices.
|
|
1215
|
+
*/
|
|
1216
|
+
route(prompt: string, options?: SmartChatOptions): Promise<RoutingDecision>;
|
|
1195
1217
|
/**
|
|
1196
1218
|
* Smart chat with automatic model routing.
|
|
1197
1219
|
*
|
|
1198
|
-
* Uses
|
|
1199
|
-
*
|
|
1220
|
+
* Uses BlockRun's product-neutral Router Core portfolio strategy: it
|
|
1221
|
+
* classifies the task shape locally (no
|
|
1200
1222
|
* extra model call), enforces capability constraints as hard filters, and
|
|
1201
1223
|
* ranks an ordered candidate portfolio — the cheapest model that can handle
|
|
1202
1224
|
* the request wins, and the rest become the transient-error fallback chain.
|
|
@@ -1224,21 +1246,14 @@ declare class LLMClient {
|
|
|
1224
1246
|
* ```
|
|
1225
1247
|
*/
|
|
1226
1248
|
smartChat(prompt: string, options?: SmartChatOptions): Promise<SmartChatResponse>;
|
|
1249
|
+
/** Route a full Agent/tool conversation while preserving its complete response. */
|
|
1250
|
+
smartChatCompletion(messages: ChatMessage[], options?: SmartChatCompletionOptions): Promise<SmartChatCompletionResponse>;
|
|
1227
1251
|
/**
|
|
1228
1252
|
* Get model pricing map (cached).
|
|
1229
1253
|
* Fetches from API on first call, then returns cached result.
|
|
1230
1254
|
*/
|
|
1231
1255
|
private getModelPricing;
|
|
1232
|
-
/**
|
|
1233
|
-
* Fetch model pricing from API.
|
|
1234
|
-
*
|
|
1235
|
-
* For flat-billed models (e.g. ZAI GLM-5 family at $0.001/call) the
|
|
1236
|
-
* router still expects per-token rates, so we synthesise an equivalent
|
|
1237
|
-
* per-token price assuming ~1500 total tokens per call. Without this,
|
|
1238
|
-
* flat models would resolve to inputPrice=outputPrice=0 and the router
|
|
1239
|
-
* would treat them as free, biasing routing decisions and reporting
|
|
1240
|
-
* inflated savings %.
|
|
1241
|
-
*/
|
|
1256
|
+
/** Fetch model pricing from the live catalog, preserving flat billing. */
|
|
1242
1257
|
private fetchModelPricing;
|
|
1243
1258
|
/**
|
|
1244
1259
|
* Full chat completion interface (OpenAI-compatible).
|
|
@@ -2701,6 +2716,20 @@ declare function extractPaymentDetails(paymentRequired: PaymentRequired, preferr
|
|
|
2701
2716
|
* - Auto-creates wallet if none exists
|
|
2702
2717
|
* - Stores key securely at ~/.blockrun/.session
|
|
2703
2718
|
* - Generates EIP-681 URIs for easy MetaMask funding
|
|
2719
|
+
*
|
|
2720
|
+
* Key resolution, discovery, and adoption are delegated to `@blockrun/core`, the
|
|
2721
|
+
* shared kernel every BlockRun product reads. That is what guarantees this SDK,
|
|
2722
|
+
* the `blockrun` CLI, and clawrouter-codex all resolve the SAME wallet — the
|
|
2723
|
+
* behaviour is defined in one place instead of being re-implemented per product
|
|
2724
|
+
* and drifting. Kept SDK-local: the funding/messaging surface (SDK-specific),
|
|
2725
|
+
* plus createWallet()/saveWallet() as thin persistence wrappers for API
|
|
2726
|
+
* compatibility — they write to the same core-resolved path, per call.
|
|
2727
|
+
*
|
|
2728
|
+
* Because path resolution now comes from core, `BLOCKRUN_HOME` overrides the base
|
|
2729
|
+
* directory (previously this module always used the OS home directory). Treat
|
|
2730
|
+
* that variable as security-sensitive: it redirects where the signing key is
|
|
2731
|
+
* read from AND written to, so an environment that can set it controls the
|
|
2732
|
+
* wallet as surely as one that can set BLOCKRUN_WALLET_KEY.
|
|
2704
2733
|
*/
|
|
2705
2734
|
declare const USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2706
2735
|
interface WalletInfo {
|
|
@@ -2733,12 +2762,15 @@ declare function saveWallet(privateKey: string): string;
|
|
|
2733
2762
|
/**
|
|
2734
2763
|
* Discover ~/.<dir>/wallet.json files from other providers.
|
|
2735
2764
|
*
|
|
2736
|
-
* Each file should contain JSON with "privateKey"
|
|
2737
|
-
*
|
|
2738
|
-
*
|
|
2739
|
-
*
|
|
2765
|
+
* Each file should contain JSON with a "privateKey" field; the returned
|
|
2766
|
+
* address is DERIVED from that key (any "address" field in the file is
|
|
2767
|
+
* ignored, so a file cannot claim an address it holds no key for), and
|
|
2768
|
+
* entries whose key does not parse are dropped. Results are sorted by
|
|
2769
|
+
* modification time (most recent first). Discovery is intentionally opt-in:
|
|
2770
|
+
* a provider wallet must never replace the canonical BlockRun wallet merely
|
|
2771
|
+
* because it was written more recently.
|
|
2740
2772
|
*
|
|
2741
|
-
* @returns Array of wallet objects with privateKey and address
|
|
2773
|
+
* @returns Array of wallet objects with privateKey and derived address
|
|
2742
2774
|
*/
|
|
2743
2775
|
declare function scanWallets(): Array<{
|
|
2744
2776
|
privateKey: string;
|
|
@@ -2771,6 +2803,12 @@ declare function listDiscoveredWallets(): Array<{
|
|
|
2771
2803
|
* The current `~/.blockrun/.session` is backed up beside itself before being
|
|
2772
2804
|
* overwritten, so adopting a wallet can't strand the funds in the old one.
|
|
2773
2805
|
*
|
|
2806
|
+
* NOTE: this is NOT `@blockrun/core`'s `importWallet(rawPrivateKey)` — that
|
|
2807
|
+
* one persists a raw key and refuses to overwrite without `force`. This SDK
|
|
2808
|
+
* function adopts a DISCOVERED wallet by address and maps onto core's
|
|
2809
|
+
* `adoptWallet()`. Same name, different operation; don't mix them up when
|
|
2810
|
+
* importing from core directly.
|
|
2811
|
+
*
|
|
2774
2812
|
* @param address Address to adopt, as shown by `listDiscoveredWallets()`
|
|
2775
2813
|
* @returns The adopted address
|
|
2776
2814
|
* @throws If no discovered wallet derives to that address
|
|
@@ -2908,6 +2946,8 @@ declare class SolanaLLMClient {
|
|
|
2908
2946
|
private sessionTotalUsd;
|
|
2909
2947
|
private sessionCalls;
|
|
2910
2948
|
private addressCache;
|
|
2949
|
+
private modelPricingCache;
|
|
2950
|
+
private modelPricingPromise;
|
|
2911
2951
|
constructor(options?: SolanaLLMClientOptions);
|
|
2912
2952
|
/** Get Solana wallet address (public key in base58). */
|
|
2913
2953
|
getWalletAddress(): Promise<string>;
|
|
@@ -2915,6 +2955,13 @@ declare class SolanaLLMClient {
|
|
|
2915
2955
|
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
2916
2956
|
/** Full chat completion (OpenAI-compatible). */
|
|
2917
2957
|
chatCompletion(model: string, messages: ChatMessage[], options?: ChatCompletionOptions): Promise<ChatResponse>;
|
|
2958
|
+
private getModelPricing;
|
|
2959
|
+
/** Inspect a Solana route without making or paying for a model call. */
|
|
2960
|
+
route(prompt: string, options?: SmartChatOptions): Promise<RoutingDecision>;
|
|
2961
|
+
/** Smart one-line chat paid on Solana. */
|
|
2962
|
+
smartChat(prompt: string, options?: SmartChatOptions): Promise<SmartChatResponse>;
|
|
2963
|
+
/** Smart full message/tool completion paid on Solana. */
|
|
2964
|
+
smartChatCompletion(messages: ChatMessage[], options?: SmartChatCompletionOptions): Promise<SmartChatCompletionResponse>;
|
|
2918
2965
|
/** List available models. */
|
|
2919
2966
|
listModels(): Promise<Model[]>;
|
|
2920
2967
|
/**
|
|
@@ -3257,6 +3304,8 @@ interface OpenAIChatCompletionResponse {
|
|
|
3257
3304
|
completion_tokens: number;
|
|
3258
3305
|
total_tokens: number;
|
|
3259
3306
|
};
|
|
3307
|
+
/** BlockRun extension present when a `blockrun/*` Auto alias was used. */
|
|
3308
|
+
routing?: RoutingDecision;
|
|
3260
3309
|
}
|
|
3261
3310
|
interface OpenAIChatCompletionChunk {
|
|
3262
3311
|
id: string;
|
|
@@ -3414,4 +3463,4 @@ declare function validateTemperature(temperature?: number): void;
|
|
|
3414
3463
|
*/
|
|
3415
3464
|
declare function validateTopP(topP?: number): void;
|
|
3416
3465
|
|
|
3417
|
-
export { APIError, AnthropicClient, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
|
3466
|
+
export { APIError, AnthropicClient, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
package/dist/index.d.ts
CHANGED
|
@@ -252,6 +252,8 @@ interface ChatResponse {
|
|
|
252
252
|
model?: string;
|
|
253
253
|
settlementSkipped?: boolean;
|
|
254
254
|
};
|
|
255
|
+
/** Present when a `blockrun/auto|eco|premium` alias selected the model locally. */
|
|
256
|
+
routing?: RoutingDecision;
|
|
255
257
|
}
|
|
256
258
|
interface Model {
|
|
257
259
|
id: string;
|
|
@@ -490,8 +492,8 @@ interface ChatCompletionOptions {
|
|
|
490
492
|
type RoutingProfile = "eco" | "auto" | "premium";
|
|
491
493
|
type RoutingTier = Tier;
|
|
492
494
|
/**
|
|
493
|
-
* Request classification produced by the
|
|
494
|
-
*
|
|
495
|
+
* Request classification produced by the bundled Router Core V3 portfolio
|
|
496
|
+
* router. Present on decisions with `method: "portfolio"`.
|
|
495
497
|
*/
|
|
496
498
|
type RoutingTaskType = TaskType;
|
|
497
499
|
/** Primary model + ordered fallbacks for one routing tier. */
|
|
@@ -500,7 +502,7 @@ interface RoutingDecision extends RoutingDecision$1 {
|
|
|
500
502
|
/**
|
|
501
503
|
* Remaining gateway-callable models, in the router's ranked order.
|
|
502
504
|
* `chat()` walks this list when the primary model hits a transient error
|
|
503
|
-
* (timeout, network, 429, 5xx). Excludes the primary itself.
|
|
505
|
+
* (timeout, network, 429, 5xx). Excludes the primary itself. The router's
|
|
504
506
|
* proxy-namespace `free/*` ids appear here as their `nvidia/*` gateway
|
|
505
507
|
* ids (or are dropped when the mapping is proxy-only).
|
|
506
508
|
*/
|
|
@@ -512,6 +514,12 @@ interface SmartChatOptions extends ChatOptions {
|
|
|
512
514
|
/** Maximum output tokens (used for cost estimation) */
|
|
513
515
|
maxOutputTokens?: number;
|
|
514
516
|
}
|
|
517
|
+
interface SmartChatCompletionOptions extends ChatCompletionOptions {
|
|
518
|
+
/** Routing profile: eco (budget), auto (balanced), premium (best quality) */
|
|
519
|
+
routingProfile?: RoutingProfile;
|
|
520
|
+
/** Maximum output tokens used for route cost/capacity estimation. */
|
|
521
|
+
maxOutputTokens?: number;
|
|
522
|
+
}
|
|
515
523
|
interface SmartChatResponse {
|
|
516
524
|
/** The AI response text */
|
|
517
525
|
response: string;
|
|
@@ -520,6 +528,14 @@ interface SmartChatResponse {
|
|
|
520
528
|
/** Routing decision metadata */
|
|
521
529
|
routing: RoutingDecision;
|
|
522
530
|
}
|
|
531
|
+
interface SmartChatCompletionResponse {
|
|
532
|
+
/** Full OpenAI-compatible response, including tool calls. */
|
|
533
|
+
response: ChatResponse;
|
|
534
|
+
/** Model selected before any transient runtime fallback. */
|
|
535
|
+
model: string;
|
|
536
|
+
/** Local routing decision and ordered fallback candidates. */
|
|
537
|
+
routing: RoutingDecision;
|
|
538
|
+
}
|
|
523
539
|
interface SearchResult {
|
|
524
540
|
query: string;
|
|
525
541
|
summary: string;
|
|
@@ -1192,11 +1208,17 @@ declare class LLMClient {
|
|
|
1192
1208
|
* console.log(response); // 'The capital of France is Paris.'
|
|
1193
1209
|
*/
|
|
1194
1210
|
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
1211
|
+
private makeRoutingDecision;
|
|
1212
|
+
/**
|
|
1213
|
+
* Inspect a local routing decision without making or paying for a model call.
|
|
1214
|
+
* The first invocation may fetch the public model catalog for current prices.
|
|
1215
|
+
*/
|
|
1216
|
+
route(prompt: string, options?: SmartChatOptions): Promise<RoutingDecision>;
|
|
1195
1217
|
/**
|
|
1196
1218
|
* Smart chat with automatic model routing.
|
|
1197
1219
|
*
|
|
1198
|
-
* Uses
|
|
1199
|
-
*
|
|
1220
|
+
* Uses BlockRun's product-neutral Router Core portfolio strategy: it
|
|
1221
|
+
* classifies the task shape locally (no
|
|
1200
1222
|
* extra model call), enforces capability constraints as hard filters, and
|
|
1201
1223
|
* ranks an ordered candidate portfolio — the cheapest model that can handle
|
|
1202
1224
|
* the request wins, and the rest become the transient-error fallback chain.
|
|
@@ -1224,21 +1246,14 @@ declare class LLMClient {
|
|
|
1224
1246
|
* ```
|
|
1225
1247
|
*/
|
|
1226
1248
|
smartChat(prompt: string, options?: SmartChatOptions): Promise<SmartChatResponse>;
|
|
1249
|
+
/** Route a full Agent/tool conversation while preserving its complete response. */
|
|
1250
|
+
smartChatCompletion(messages: ChatMessage[], options?: SmartChatCompletionOptions): Promise<SmartChatCompletionResponse>;
|
|
1227
1251
|
/**
|
|
1228
1252
|
* Get model pricing map (cached).
|
|
1229
1253
|
* Fetches from API on first call, then returns cached result.
|
|
1230
1254
|
*/
|
|
1231
1255
|
private getModelPricing;
|
|
1232
|
-
/**
|
|
1233
|
-
* Fetch model pricing from API.
|
|
1234
|
-
*
|
|
1235
|
-
* For flat-billed models (e.g. ZAI GLM-5 family at $0.001/call) the
|
|
1236
|
-
* router still expects per-token rates, so we synthesise an equivalent
|
|
1237
|
-
* per-token price assuming ~1500 total tokens per call. Without this,
|
|
1238
|
-
* flat models would resolve to inputPrice=outputPrice=0 and the router
|
|
1239
|
-
* would treat them as free, biasing routing decisions and reporting
|
|
1240
|
-
* inflated savings %.
|
|
1241
|
-
*/
|
|
1256
|
+
/** Fetch model pricing from the live catalog, preserving flat billing. */
|
|
1242
1257
|
private fetchModelPricing;
|
|
1243
1258
|
/**
|
|
1244
1259
|
* Full chat completion interface (OpenAI-compatible).
|
|
@@ -2701,6 +2716,20 @@ declare function extractPaymentDetails(paymentRequired: PaymentRequired, preferr
|
|
|
2701
2716
|
* - Auto-creates wallet if none exists
|
|
2702
2717
|
* - Stores key securely at ~/.blockrun/.session
|
|
2703
2718
|
* - Generates EIP-681 URIs for easy MetaMask funding
|
|
2719
|
+
*
|
|
2720
|
+
* Key resolution, discovery, and adoption are delegated to `@blockrun/core`, the
|
|
2721
|
+
* shared kernel every BlockRun product reads. That is what guarantees this SDK,
|
|
2722
|
+
* the `blockrun` CLI, and clawrouter-codex all resolve the SAME wallet — the
|
|
2723
|
+
* behaviour is defined in one place instead of being re-implemented per product
|
|
2724
|
+
* and drifting. Kept SDK-local: the funding/messaging surface (SDK-specific),
|
|
2725
|
+
* plus createWallet()/saveWallet() as thin persistence wrappers for API
|
|
2726
|
+
* compatibility — they write to the same core-resolved path, per call.
|
|
2727
|
+
*
|
|
2728
|
+
* Because path resolution now comes from core, `BLOCKRUN_HOME` overrides the base
|
|
2729
|
+
* directory (previously this module always used the OS home directory). Treat
|
|
2730
|
+
* that variable as security-sensitive: it redirects where the signing key is
|
|
2731
|
+
* read from AND written to, so an environment that can set it controls the
|
|
2732
|
+
* wallet as surely as one that can set BLOCKRUN_WALLET_KEY.
|
|
2704
2733
|
*/
|
|
2705
2734
|
declare const USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2706
2735
|
interface WalletInfo {
|
|
@@ -2733,12 +2762,15 @@ declare function saveWallet(privateKey: string): string;
|
|
|
2733
2762
|
/**
|
|
2734
2763
|
* Discover ~/.<dir>/wallet.json files from other providers.
|
|
2735
2764
|
*
|
|
2736
|
-
* Each file should contain JSON with "privateKey"
|
|
2737
|
-
*
|
|
2738
|
-
*
|
|
2739
|
-
*
|
|
2765
|
+
* Each file should contain JSON with a "privateKey" field; the returned
|
|
2766
|
+
* address is DERIVED from that key (any "address" field in the file is
|
|
2767
|
+
* ignored, so a file cannot claim an address it holds no key for), and
|
|
2768
|
+
* entries whose key does not parse are dropped. Results are sorted by
|
|
2769
|
+
* modification time (most recent first). Discovery is intentionally opt-in:
|
|
2770
|
+
* a provider wallet must never replace the canonical BlockRun wallet merely
|
|
2771
|
+
* because it was written more recently.
|
|
2740
2772
|
*
|
|
2741
|
-
* @returns Array of wallet objects with privateKey and address
|
|
2773
|
+
* @returns Array of wallet objects with privateKey and derived address
|
|
2742
2774
|
*/
|
|
2743
2775
|
declare function scanWallets(): Array<{
|
|
2744
2776
|
privateKey: string;
|
|
@@ -2771,6 +2803,12 @@ declare function listDiscoveredWallets(): Array<{
|
|
|
2771
2803
|
* The current `~/.blockrun/.session` is backed up beside itself before being
|
|
2772
2804
|
* overwritten, so adopting a wallet can't strand the funds in the old one.
|
|
2773
2805
|
*
|
|
2806
|
+
* NOTE: this is NOT `@blockrun/core`'s `importWallet(rawPrivateKey)` — that
|
|
2807
|
+
* one persists a raw key and refuses to overwrite without `force`. This SDK
|
|
2808
|
+
* function adopts a DISCOVERED wallet by address and maps onto core's
|
|
2809
|
+
* `adoptWallet()`. Same name, different operation; don't mix them up when
|
|
2810
|
+
* importing from core directly.
|
|
2811
|
+
*
|
|
2774
2812
|
* @param address Address to adopt, as shown by `listDiscoveredWallets()`
|
|
2775
2813
|
* @returns The adopted address
|
|
2776
2814
|
* @throws If no discovered wallet derives to that address
|
|
@@ -2908,6 +2946,8 @@ declare class SolanaLLMClient {
|
|
|
2908
2946
|
private sessionTotalUsd;
|
|
2909
2947
|
private sessionCalls;
|
|
2910
2948
|
private addressCache;
|
|
2949
|
+
private modelPricingCache;
|
|
2950
|
+
private modelPricingPromise;
|
|
2911
2951
|
constructor(options?: SolanaLLMClientOptions);
|
|
2912
2952
|
/** Get Solana wallet address (public key in base58). */
|
|
2913
2953
|
getWalletAddress(): Promise<string>;
|
|
@@ -2915,6 +2955,13 @@ declare class SolanaLLMClient {
|
|
|
2915
2955
|
chat(model: string, prompt: string, options?: ChatOptions): Promise<string>;
|
|
2916
2956
|
/** Full chat completion (OpenAI-compatible). */
|
|
2917
2957
|
chatCompletion(model: string, messages: ChatMessage[], options?: ChatCompletionOptions): Promise<ChatResponse>;
|
|
2958
|
+
private getModelPricing;
|
|
2959
|
+
/** Inspect a Solana route without making or paying for a model call. */
|
|
2960
|
+
route(prompt: string, options?: SmartChatOptions): Promise<RoutingDecision>;
|
|
2961
|
+
/** Smart one-line chat paid on Solana. */
|
|
2962
|
+
smartChat(prompt: string, options?: SmartChatOptions): Promise<SmartChatResponse>;
|
|
2963
|
+
/** Smart full message/tool completion paid on Solana. */
|
|
2964
|
+
smartChatCompletion(messages: ChatMessage[], options?: SmartChatCompletionOptions): Promise<SmartChatCompletionResponse>;
|
|
2918
2965
|
/** List available models. */
|
|
2919
2966
|
listModels(): Promise<Model[]>;
|
|
2920
2967
|
/**
|
|
@@ -3257,6 +3304,8 @@ interface OpenAIChatCompletionResponse {
|
|
|
3257
3304
|
completion_tokens: number;
|
|
3258
3305
|
total_tokens: number;
|
|
3259
3306
|
};
|
|
3307
|
+
/** BlockRun extension present when a `blockrun/*` Auto alias was used. */
|
|
3308
|
+
routing?: RoutingDecision;
|
|
3260
3309
|
}
|
|
3261
3310
|
interface OpenAIChatCompletionChunk {
|
|
3262
3311
|
id: string;
|
|
@@ -3414,4 +3463,4 @@ declare function validateTemperature(temperature?: number): void;
|
|
|
3414
3463
|
*/
|
|
3415
3464
|
declare function validateTopP(topP?: number): void;
|
|
3416
3465
|
|
|
3417
|
-
export { APIError, AnthropicClient, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
|
3466
|
+
export { APIError, AnthropicClient, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|