@blockrun/llm 1.1.0 → 1.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/index.d.cts CHANGED
@@ -205,6 +205,157 @@ interface SmartChatResponse {
205
205
  /** Routing decision metadata */
206
206
  routing: RoutingDecision;
207
207
  }
208
+ interface SearchResult {
209
+ query: string;
210
+ summary: string;
211
+ citations?: Array<Record<string, string>>;
212
+ sources_used?: number;
213
+ model?: string;
214
+ }
215
+ interface ImageEditOptions {
216
+ /** Model ID (default: "openai/gpt-image-1") */
217
+ model?: string;
218
+ /** Optional base64-encoded mask image */
219
+ mask?: string;
220
+ /** Image size (default: "1024x1024") */
221
+ size?: string;
222
+ /** Number of images to generate (default: 1) */
223
+ n?: number;
224
+ }
225
+ interface SearchOptions {
226
+ /** Source types to search (e.g. ["web", "x", "news"]) */
227
+ sources?: string[];
228
+ /** Maximum number of results (default: 10) */
229
+ maxResults?: number;
230
+ /** Start date filter (YYYY-MM-DD) */
231
+ fromDate?: string;
232
+ /** End date filter (YYYY-MM-DD) */
233
+ toDate?: string;
234
+ }
235
+ interface XUser {
236
+ id: string;
237
+ userName: string;
238
+ name: string;
239
+ profilePicture?: string;
240
+ description?: string;
241
+ followers?: number;
242
+ following?: number;
243
+ isBlueVerified?: boolean;
244
+ verifiedType?: string;
245
+ location?: string;
246
+ joined?: string;
247
+ }
248
+ interface XUserLookupResponse {
249
+ users: XUser[];
250
+ not_found?: string[];
251
+ total_requested?: number;
252
+ total_found?: number;
253
+ }
254
+ interface XFollower {
255
+ id: string;
256
+ name?: string;
257
+ screen_name?: string;
258
+ userName?: string;
259
+ location?: string;
260
+ description?: string;
261
+ protected?: boolean;
262
+ verified?: boolean;
263
+ followers_count?: number;
264
+ following_count?: number;
265
+ favourites_count?: number;
266
+ statuses_count?: number;
267
+ created_at?: string;
268
+ profile_image_url_https?: string;
269
+ can_dm?: boolean;
270
+ }
271
+ interface XFollowersResponse {
272
+ followers: XFollower[];
273
+ has_next_page?: boolean;
274
+ next_cursor?: string;
275
+ total_returned?: number;
276
+ username?: string;
277
+ }
278
+ interface XFollowingsResponse {
279
+ followings: XFollower[];
280
+ has_next_page?: boolean;
281
+ next_cursor?: string;
282
+ total_returned?: number;
283
+ username?: string;
284
+ }
285
+ interface XUserInfoResponse {
286
+ data: Record<string, unknown>;
287
+ username?: string;
288
+ }
289
+ interface XVerifiedFollowersResponse {
290
+ followers: XFollower[];
291
+ has_next_page?: boolean;
292
+ next_cursor?: string;
293
+ total_returned?: number;
294
+ }
295
+ interface XTweet {
296
+ id: string;
297
+ text?: string;
298
+ created_at?: string;
299
+ author?: Record<string, unknown>;
300
+ favorite_count?: number;
301
+ retweet_count?: number;
302
+ reply_count?: number;
303
+ view_count?: number;
304
+ lang?: string;
305
+ entities?: Record<string, unknown>;
306
+ media?: Array<Record<string, unknown>>;
307
+ [key: string]: unknown;
308
+ }
309
+ interface XTweetsResponse {
310
+ tweets: XTweet[];
311
+ has_next_page?: boolean;
312
+ next_cursor?: string;
313
+ total_returned?: number;
314
+ }
315
+ interface XMentionsResponse {
316
+ tweets: XTweet[];
317
+ has_next_page?: boolean;
318
+ next_cursor?: string;
319
+ total_returned?: number;
320
+ username?: string;
321
+ }
322
+ interface XTweetLookupResponse {
323
+ tweets: XTweet[];
324
+ not_found?: string[];
325
+ total_requested?: number;
326
+ total_found?: number;
327
+ }
328
+ interface XTweetRepliesResponse {
329
+ replies: XTweet[];
330
+ has_next_page?: boolean;
331
+ next_cursor?: string;
332
+ total_returned?: number;
333
+ }
334
+ interface XTweetThreadResponse {
335
+ tweets: XTweet[];
336
+ has_next_page?: boolean;
337
+ next_cursor?: string;
338
+ total_returned?: number;
339
+ }
340
+ interface XSearchResponse {
341
+ tweets: XTweet[];
342
+ has_next_page?: boolean;
343
+ next_cursor?: string;
344
+ total_returned?: number;
345
+ }
346
+ interface XTrendingResponse {
347
+ data: Record<string, unknown>;
348
+ }
349
+ interface XArticlesRisingResponse {
350
+ data: Record<string, unknown>;
351
+ }
352
+ interface XAuthorAnalyticsResponse {
353
+ data: Record<string, unknown>;
354
+ handle?: string;
355
+ }
356
+ interface XCompareAuthorsResponse {
357
+ data: Record<string, unknown>;
358
+ }
208
359
  declare class BlockrunError extends Error {
209
360
  constructor(message: string);
210
361
  }
@@ -344,6 +495,15 @@ declare class LLMClient {
344
495
  * Handle 402 response: parse requirements, sign payment, retry.
345
496
  */
346
497
  private handlePaymentAndRetry;
498
+ /**
499
+ * Make a request with automatic x402 payment handling, returning raw JSON.
500
+ * Used for non-ChatResponse endpoints (X/Twitter, search, image edit, etc.).
501
+ */
502
+ private requestWithPaymentRaw;
503
+ /**
504
+ * Handle 402 response for raw endpoints: parse requirements, sign payment, retry.
505
+ */
506
+ private handlePaymentAndRetryRaw;
347
507
  /**
348
508
  * Fetch with timeout.
349
509
  */
@@ -372,6 +532,165 @@ declare class LLMClient {
372
532
  * }
373
533
  */
374
534
  listAllModels(): Promise<(Model | ImageModel)[]>;
535
+ /**
536
+ * Edit an image using img2img.
537
+ *
538
+ * @param prompt - Text description of the desired edit
539
+ * @param image - Base64-encoded image or URL of the source image
540
+ * @param options - Optional edit parameters
541
+ * @returns ImageResponse with edited image URLs
542
+ */
543
+ imageEdit(prompt: string, image: string, options?: ImageEditOptions): Promise<ImageResponse>;
544
+ /**
545
+ * Standalone search (web, X/Twitter, news).
546
+ *
547
+ * @param query - Search query
548
+ * @param options - Optional search parameters
549
+ * @returns SearchResult with summary and citations
550
+ */
551
+ search(query: string, options?: SearchOptions): Promise<SearchResult>;
552
+ /**
553
+ * Get USDC balance on Base network.
554
+ *
555
+ * Automatically detects mainnet vs testnet based on API URL.
556
+ *
557
+ * @returns USDC balance as a float (6 decimal places normalized)
558
+ *
559
+ * @example
560
+ * const balance = await client.getBalance();
561
+ * console.log(`Balance: $${balance.toFixed(2)} USDC`);
562
+ */
563
+ getBalance(): Promise<number>;
564
+ /**
565
+ * Look up X/Twitter user profiles by username.
566
+ *
567
+ * Powered by AttentionVC. $0.002 per user (min $0.02, max $0.20).
568
+ *
569
+ * @param usernames - Single username or array of usernames (without @)
570
+ */
571
+ xUserLookup(usernames: string | string[]): Promise<XUserLookupResponse>;
572
+ /**
573
+ * Get followers of an X/Twitter user.
574
+ *
575
+ * Powered by AttentionVC. $0.05 per page (~200 accounts).
576
+ *
577
+ * @param username - X/Twitter username (without @)
578
+ * @param cursor - Pagination cursor from previous response
579
+ */
580
+ xFollowers(username: string, cursor?: string): Promise<XFollowersResponse>;
581
+ /**
582
+ * Get accounts an X/Twitter user is following.
583
+ *
584
+ * Powered by AttentionVC. $0.05 per page (~200 accounts).
585
+ *
586
+ * @param username - X/Twitter username (without @)
587
+ * @param cursor - Pagination cursor from previous response
588
+ */
589
+ xFollowings(username: string, cursor?: string): Promise<XFollowingsResponse>;
590
+ /**
591
+ * Get detailed profile info for a single X/Twitter user.
592
+ *
593
+ * Powered by AttentionVC. $0.002 per request.
594
+ *
595
+ * @param username - X/Twitter username (without @)
596
+ */
597
+ xUserInfo(username: string): Promise<XUserInfoResponse>;
598
+ /**
599
+ * Get verified (blue-check) followers of an X/Twitter user.
600
+ *
601
+ * Powered by AttentionVC. $0.048 per page.
602
+ *
603
+ * @param userId - X/Twitter user ID (not username)
604
+ * @param cursor - Pagination cursor from previous response
605
+ */
606
+ xVerifiedFollowers(userId: string, cursor?: string): Promise<XVerifiedFollowersResponse>;
607
+ /**
608
+ * Get tweets posted by an X/Twitter user.
609
+ *
610
+ * Powered by AttentionVC. $0.032 per page.
611
+ *
612
+ * @param username - X/Twitter username (without @)
613
+ * @param includeReplies - Include reply tweets (default: false)
614
+ * @param cursor - Pagination cursor from previous response
615
+ */
616
+ xUserTweets(username: string, includeReplies?: boolean, cursor?: string): Promise<XTweetsResponse>;
617
+ /**
618
+ * Get tweets that mention an X/Twitter user.
619
+ *
620
+ * Powered by AttentionVC. $0.032 per page.
621
+ *
622
+ * @param username - X/Twitter username (without @)
623
+ * @param sinceTime - Start time filter (ISO8601 or Unix timestamp)
624
+ * @param untilTime - End time filter (ISO8601 or Unix timestamp)
625
+ * @param cursor - Pagination cursor from previous response
626
+ */
627
+ xUserMentions(username: string, sinceTime?: string, untilTime?: string, cursor?: string): Promise<XMentionsResponse>;
628
+ /**
629
+ * Fetch full tweet data for up to 200 tweet IDs.
630
+ *
631
+ * Powered by AttentionVC. $0.16 per batch.
632
+ *
633
+ * @param tweetIds - Single tweet ID or array of tweet IDs (max 200)
634
+ */
635
+ xTweetLookup(tweetIds: string | string[]): Promise<XTweetLookupResponse>;
636
+ /**
637
+ * Get replies to a specific tweet.
638
+ *
639
+ * Powered by AttentionVC. $0.032 per page.
640
+ *
641
+ * @param tweetId - The tweet ID to get replies for
642
+ * @param queryType - Sort order: 'Latest' or 'Default'
643
+ * @param cursor - Pagination cursor from previous response
644
+ */
645
+ xTweetReplies(tweetId: string, queryType?: string, cursor?: string): Promise<XTweetRepliesResponse>;
646
+ /**
647
+ * Get the full thread context for a tweet.
648
+ *
649
+ * Powered by AttentionVC. $0.032 per page.
650
+ *
651
+ * @param tweetId - The tweet ID to get thread for
652
+ * @param cursor - Pagination cursor from previous response
653
+ */
654
+ xTweetThread(tweetId: string, cursor?: string): Promise<XTweetThreadResponse>;
655
+ /**
656
+ * Search X/Twitter with advanced query operators.
657
+ *
658
+ * Powered by AttentionVC. $0.032 per page.
659
+ *
660
+ * @param query - Search query (supports Twitter search operators)
661
+ * @param queryType - Sort order: 'Latest', 'Top', or 'Default'
662
+ * @param cursor - Pagination cursor from previous response
663
+ */
664
+ xSearch(query: string, queryType?: string, cursor?: string): Promise<XSearchResponse>;
665
+ /**
666
+ * Get current trending topics on X/Twitter.
667
+ *
668
+ * Powered by AttentionVC. $0.002 per request.
669
+ */
670
+ xTrending(): Promise<XTrendingResponse>;
671
+ /**
672
+ * Get rising/viral articles from X/Twitter.
673
+ *
674
+ * Powered by AttentionVC intelligence layer. $0.05 per request.
675
+ */
676
+ xArticlesRising(): Promise<XArticlesRisingResponse>;
677
+ /**
678
+ * Get author analytics and intelligence metrics for an X/Twitter user.
679
+ *
680
+ * Powered by AttentionVC intelligence layer. $0.02 per request.
681
+ *
682
+ * @param handle - X/Twitter handle (without @)
683
+ */
684
+ xAuthorAnalytics(handle: string): Promise<XAuthorAnalyticsResponse>;
685
+ /**
686
+ * Compare two X/Twitter authors side-by-side with intelligence metrics.
687
+ *
688
+ * Powered by AttentionVC intelligence layer. $0.05 per request.
689
+ *
690
+ * @param handle1 - First X/Twitter handle (without @)
691
+ * @param handle2 - Second X/Twitter handle (without @)
692
+ */
693
+ xCompareAuthors(handle1: string, handle2: string): Promise<XCompareAuthorsResponse>;
375
694
  /**
376
695
  * Get current session spending.
377
696
  *
@@ -467,6 +786,19 @@ declare class ImageClient {
467
786
  * console.log(result.data[0].url);
468
787
  */
469
788
  generate(prompt: string, options?: ImageGenerateOptions): Promise<ImageResponse>;
789
+ /**
790
+ * Edit an image using img2img.
791
+ *
792
+ * @param prompt - Text description of the desired edit
793
+ * @param image - Base64-encoded image or URL of the source image
794
+ * @param options - Optional edit parameters
795
+ * @returns ImageResponse with edited image URLs
796
+ *
797
+ * @example
798
+ * const result = await client.edit('Make it a painting', imageBase64);
799
+ * console.log(result.data[0].url);
800
+ */
801
+ edit(prompt: string, image: string, options?: ImageEditOptions): Promise<ImageResponse>;
470
802
  /**
471
803
  * List available image generation models with pricing.
472
804
  */
@@ -672,12 +1004,39 @@ declare class SolanaLLMClient {
672
1004
  chatCompletion(model: string, messages: ChatMessage[], options?: ChatCompletionOptions): Promise<ChatResponse>;
673
1005
  /** List available models. */
674
1006
  listModels(): Promise<Model[]>;
1007
+ /**
1008
+ * Get Solana USDC balance.
1009
+ *
1010
+ * @returns USDC balance as a float
1011
+ */
1012
+ getBalance(): Promise<number>;
1013
+ /** Edit an image using img2img (Solana payment). */
1014
+ imageEdit(prompt: string, image: string, options?: ImageEditOptions): Promise<ImageResponse>;
1015
+ /** Standalone search (Solana payment). */
1016
+ search(query: string, options?: SearchOptions): Promise<SearchResult>;
1017
+ xUserLookup(usernames: string | string[]): Promise<XUserLookupResponse>;
1018
+ xFollowers(username: string, cursor?: string): Promise<XFollowersResponse>;
1019
+ xFollowings(username: string, cursor?: string): Promise<XFollowingsResponse>;
1020
+ xUserInfo(username: string): Promise<XUserInfoResponse>;
1021
+ xVerifiedFollowers(userId: string, cursor?: string): Promise<XVerifiedFollowersResponse>;
1022
+ xUserTweets(username: string, includeReplies?: boolean, cursor?: string): Promise<XTweetsResponse>;
1023
+ xUserMentions(username: string, sinceTime?: string, untilTime?: string, cursor?: string): Promise<XMentionsResponse>;
1024
+ xTweetLookup(tweetIds: string | string[]): Promise<XTweetLookupResponse>;
1025
+ xTweetReplies(tweetId: string, queryType?: string, cursor?: string): Promise<XTweetRepliesResponse>;
1026
+ xTweetThread(tweetId: string, cursor?: string): Promise<XTweetThreadResponse>;
1027
+ xSearch(query: string, queryType?: string, cursor?: string): Promise<XSearchResponse>;
1028
+ xTrending(): Promise<XTrendingResponse>;
1029
+ xArticlesRising(): Promise<XArticlesRisingResponse>;
1030
+ xAuthorAnalytics(handle: string): Promise<XAuthorAnalyticsResponse>;
1031
+ xCompareAuthors(handle1: string, handle2: string): Promise<XCompareAuthorsResponse>;
675
1032
  /** Get session spending. */
676
1033
  getSpending(): Spending;
677
1034
  /** True if using sol.blockrun.ai. */
678
1035
  isSolana(): boolean;
679
1036
  private requestWithPayment;
680
1037
  private handlePaymentAndRetry;
1038
+ private requestWithPaymentRaw;
1039
+ private handlePaymentAndRetryRaw;
681
1040
  private fetchWithTimeout;
682
1041
  }
683
1042
  /**
@@ -851,4 +1210,4 @@ declare class OpenAI {
851
1210
  getWalletAddress(): string;
852
1211
  }
853
1212
 
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 };
1213
+ 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 ImageEditOptions, 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 SearchOptions, type SearchParameters, type SearchResult, 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 XArticlesRisingResponse, type XAuthorAnalyticsResponse, type XCompareAuthorsResponse, type XFollower, type XFollowersResponse, type XFollowingsResponse, type XMentionsResponse, type XSearchResponse, type XSearchSource, type XTrendingResponse, type XTweet, type XTweetLookupResponse, type XTweetRepliesResponse, type XTweetThreadResponse, type XTweetsResponse, type XUser, type XUserInfoResponse, type XUserLookupResponse, type XVerifiedFollowersResponse, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, formatFundingMessageCompact, formatNeedsFundingMessage, formatWalletCreatedMessage, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, loadSolanaWallet, loadWallet, saveSolanaWallet, saveWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, testnetClient };