@bridgenode/llm 0.1.0 → 0.2.1
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 +46 -1406
- package/dist/index.cjs +72 -80
- package/dist/index.d.cts +86 -96
- package/dist/index.d.ts +86 -96
- package/dist/index.js +72 -77
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -27,8 +27,6 @@ var APIError = class extends BridgeNodeError {
|
|
|
27
27
|
|
|
28
28
|
// src/x402.ts
|
|
29
29
|
import { signTypedData } from "viem/accounts";
|
|
30
|
-
var BASE_CHAIN_ID = 8453;
|
|
31
|
-
var USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
32
30
|
var SOLANA_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
33
31
|
var USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
34
32
|
var DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1;
|
|
@@ -36,8 +34,8 @@ var DEFAULT_COMPUTE_UNIT_LIMIT = 8e3;
|
|
|
36
34
|
var USDC_DOMAIN = {
|
|
37
35
|
name: "USD Coin",
|
|
38
36
|
version: "2",
|
|
39
|
-
chainId:
|
|
40
|
-
verifyingContract:
|
|
37
|
+
chainId: 8453,
|
|
38
|
+
verifyingContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
41
39
|
};
|
|
42
40
|
var TRANSFER_TYPES = {
|
|
43
41
|
TransferWithAuthorization: [
|
|
@@ -64,7 +62,7 @@ function withBuilderCodeServiceCode(extensions) {
|
|
|
64
62
|
};
|
|
65
63
|
return merged;
|
|
66
64
|
}
|
|
67
|
-
async function createPaymentPayload(privateKey, fromAddress, recipient, amount, network =
|
|
65
|
+
async function createPaymentPayload(privateKey, fromAddress, recipient, amount, network = SOLANA_NETWORK, options = {}) {
|
|
68
66
|
const now = Math.floor(Date.now() / 1e3);
|
|
69
67
|
const validAfter = now - 600;
|
|
70
68
|
const validBefore = now + (options.maxTimeoutSeconds || 300);
|
|
@@ -95,7 +93,7 @@ async function createPaymentPayload(privateKey, fromAddress, recipient, amount,
|
|
|
95
93
|
scheme: "exact",
|
|
96
94
|
network,
|
|
97
95
|
amount,
|
|
98
|
-
asset:
|
|
96
|
+
asset: USDC_SOLANA,
|
|
99
97
|
payTo: recipient,
|
|
100
98
|
maxTimeoutSeconds: options.maxTimeoutSeconds || 300,
|
|
101
99
|
extra: { name: "USD Coin", version: "2" }
|
|
@@ -472,16 +470,16 @@ var LLMClient = class _LLMClient {
|
|
|
472
470
|
preAuthCache = /* @__PURE__ */ new Map();
|
|
473
471
|
static PRE_AUTH_TTL_MS = 36e5;
|
|
474
472
|
/**
|
|
475
|
-
* Initialize the
|
|
473
|
+
* Initialize the BridgeNode LLM client.
|
|
476
474
|
*
|
|
477
|
-
* @param options - Client configuration options (optional if
|
|
475
|
+
* @param options - Client configuration options (optional if BRIDGENODE_WALLET_KEY env var is set)
|
|
478
476
|
*/
|
|
479
477
|
constructor(options = {}) {
|
|
480
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.
|
|
478
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
481
479
|
const privateKey = options.privateKey || envKey;
|
|
482
480
|
if (!privateKey) {
|
|
483
481
|
throw new Error(
|
|
484
|
-
"Private key required. Pass privateKey in options or set
|
|
482
|
+
"Private key required. Pass privateKey in options or set BRIDGENODE_WALLET_KEY environment variable."
|
|
485
483
|
);
|
|
486
484
|
}
|
|
487
485
|
validatePrivateKey(privateKey);
|
|
@@ -813,13 +811,13 @@ var LLMClient = class _LLMClient {
|
|
|
813
811
|
this.account.address,
|
|
814
812
|
details.recipient,
|
|
815
813
|
details.amount,
|
|
816
|
-
details.network ||
|
|
814
|
+
details.network || SOLANA_NETWORK,
|
|
817
815
|
{
|
|
818
816
|
resourceUrl: validateResourceUrl(
|
|
819
817
|
details.resource?.url || `${this.apiUrl}/v1/chat/completions`,
|
|
820
818
|
this.apiUrl
|
|
821
819
|
),
|
|
822
|
-
resourceDescription: details.resource?.description || "
|
|
820
|
+
resourceDescription: details.resource?.description || "BridgeNode AI API call",
|
|
823
821
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
824
822
|
extra: details.extra,
|
|
825
823
|
extensions
|
|
@@ -898,13 +896,13 @@ var LLMClient = class _LLMClient {
|
|
|
898
896
|
this.account.address,
|
|
899
897
|
details.recipient,
|
|
900
898
|
details.amount,
|
|
901
|
-
details.network ||
|
|
899
|
+
details.network || SOLANA_NETWORK,
|
|
902
900
|
{
|
|
903
901
|
resourceUrl: validateResourceUrl(
|
|
904
902
|
details.resource?.url || `${this.apiUrl}/v1/chat/completions`,
|
|
905
903
|
this.apiUrl
|
|
906
904
|
),
|
|
907
|
-
resourceDescription: details.resource?.description || "
|
|
905
|
+
resourceDescription: details.resource?.description || "BridgeNode AI API call",
|
|
908
906
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
909
907
|
extra: details.extra,
|
|
910
908
|
extensions
|
|
@@ -1089,13 +1087,13 @@ var LLMClient = class _LLMClient {
|
|
|
1089
1087
|
this.account.address,
|
|
1090
1088
|
details.recipient,
|
|
1091
1089
|
details.amount,
|
|
1092
|
-
details.network ||
|
|
1090
|
+
details.network || SOLANA_NETWORK,
|
|
1093
1091
|
{
|
|
1094
1092
|
resourceUrl: validateResourceUrl(
|
|
1095
1093
|
details.resource?.url || url,
|
|
1096
1094
|
this.apiUrl
|
|
1097
1095
|
),
|
|
1098
|
-
resourceDescription: details.resource?.description || "
|
|
1096
|
+
resourceDescription: details.resource?.description || "BridgeNode AI API call",
|
|
1099
1097
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
1100
1098
|
extra: details.extra,
|
|
1101
1099
|
extensions
|
|
@@ -1236,13 +1234,13 @@ var LLMClient = class _LLMClient {
|
|
|
1236
1234
|
this.account.address,
|
|
1237
1235
|
details.recipient,
|
|
1238
1236
|
details.amount,
|
|
1239
|
-
details.network ||
|
|
1237
|
+
details.network || SOLANA_NETWORK,
|
|
1240
1238
|
{
|
|
1241
1239
|
resourceUrl: validateResourceUrl(
|
|
1242
1240
|
details.resource?.url || url,
|
|
1243
1241
|
this.apiUrl
|
|
1244
1242
|
),
|
|
1245
|
-
resourceDescription: details.resource?.description || "
|
|
1243
|
+
resourceDescription: details.resource?.description || "BridgeNode AI API call",
|
|
1246
1244
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
1247
1245
|
extra: details.extra,
|
|
1248
1246
|
extensions
|
|
@@ -1698,7 +1696,7 @@ var LLMClient = class _LLMClient {
|
|
|
1698
1696
|
// 0x DEX (swap quotes + gasless) — free passthrough
|
|
1699
1697
|
// ============================================================
|
|
1700
1698
|
/**
|
|
1701
|
-
* Query the 0x Swap / Gasless APIs (free — no x402 payment;
|
|
1699
|
+
* Query the 0x Swap / Gasless APIs (free — no x402 payment; BridgeNode
|
|
1702
1700
|
* takes an on-chain affiliate fee on executed swaps instead).
|
|
1703
1701
|
*
|
|
1704
1702
|
* @param path - "price", "quote", "gasless/price", "gasless/quote",
|
|
@@ -1812,12 +1810,12 @@ var ImageClient = class {
|
|
|
1812
1810
|
sessionTotalUsd = 0;
|
|
1813
1811
|
sessionCalls = 0;
|
|
1814
1812
|
/**
|
|
1815
|
-
* Initialize the
|
|
1813
|
+
* Initialize the BridgeNode Image client.
|
|
1816
1814
|
*
|
|
1817
1815
|
* @param options - Client configuration options
|
|
1818
1816
|
*/
|
|
1819
1817
|
constructor(options = {}) {
|
|
1820
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
1818
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
1821
1819
|
const privateKey = options.privateKey || envKey;
|
|
1822
1820
|
if (!privateKey) {
|
|
1823
1821
|
throw new Error(
|
|
@@ -1981,7 +1979,7 @@ var ImageClient = class {
|
|
|
1981
1979
|
this.account.address,
|
|
1982
1980
|
details.recipient,
|
|
1983
1981
|
details.amount,
|
|
1984
|
-
details.network ||
|
|
1982
|
+
details.network || SOLANA_NETWORK,
|
|
1985
1983
|
{
|
|
1986
1984
|
resourceUrl: validateResourceUrl(
|
|
1987
1985
|
details.resource?.url || `${this.apiUrl}/v1/images/generations`,
|
|
@@ -2130,7 +2128,7 @@ var MusicClient = class {
|
|
|
2130
2128
|
sessionTotalUsd = 0;
|
|
2131
2129
|
sessionCalls = 0;
|
|
2132
2130
|
constructor(options = {}) {
|
|
2133
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
2131
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
2134
2132
|
const privateKey = options.privateKey || envKey;
|
|
2135
2133
|
if (!privateKey) {
|
|
2136
2134
|
throw new Error(
|
|
@@ -2220,7 +2218,7 @@ var MusicClient = class {
|
|
|
2220
2218
|
this.account.address,
|
|
2221
2219
|
details.recipient,
|
|
2222
2220
|
details.amount,
|
|
2223
|
-
details.network ||
|
|
2221
|
+
details.network || SOLANA_NETWORK,
|
|
2224
2222
|
{
|
|
2225
2223
|
resourceUrl: details.resource?.url || `${this.apiUrl}/v1/audio/generations`,
|
|
2226
2224
|
resourceDescription: details.resource?.description || "BridgeNode Music Generation",
|
|
@@ -2286,7 +2284,7 @@ var SpeechClient = class {
|
|
|
2286
2284
|
sessionTotalUsd = 0;
|
|
2287
2285
|
sessionCalls = 0;
|
|
2288
2286
|
constructor(options = {}) {
|
|
2289
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
2287
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
2290
2288
|
const privateKey = options.privateKey || envKey;
|
|
2291
2289
|
if (!privateKey) {
|
|
2292
2290
|
throw new Error(
|
|
@@ -2313,7 +2311,7 @@ var SpeechClient = class {
|
|
|
2313
2311
|
* @returns SpeechResponse with audio URL, format, and character count
|
|
2314
2312
|
*
|
|
2315
2313
|
* @example
|
|
2316
|
-
* const result = await client.generate('Welcome to
|
|
2314
|
+
* const result = await client.generate('Welcome to BridgeNode.', { voice: 'george' });
|
|
2317
2315
|
* console.log(result.data[0].url); // audio URL (mp3 by default)
|
|
2318
2316
|
*/
|
|
2319
2317
|
async generate(input, options) {
|
|
@@ -2418,7 +2416,7 @@ var SpeechClient = class {
|
|
|
2418
2416
|
this.account.address,
|
|
2419
2417
|
details.recipient,
|
|
2420
2418
|
details.amount,
|
|
2421
|
-
details.network ||
|
|
2419
|
+
details.network || SOLANA_NETWORK,
|
|
2422
2420
|
{
|
|
2423
2421
|
resourceUrl: details.resource?.url || `${this.apiUrl}${endpoint}`,
|
|
2424
2422
|
resourceDescription: details.resource?.description || "BridgeNode Voice",
|
|
@@ -2488,7 +2486,7 @@ var VideoClient = class {
|
|
|
2488
2486
|
sessionTotalUsd = 0;
|
|
2489
2487
|
sessionCalls = 0;
|
|
2490
2488
|
constructor(options = {}) {
|
|
2491
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
2489
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
2492
2490
|
const privateKey = options.privateKey || envKey;
|
|
2493
2491
|
if (!privateKey) {
|
|
2494
2492
|
throw new Error(
|
|
@@ -2726,7 +2724,7 @@ var VideoClient = class {
|
|
|
2726
2724
|
this.account.address,
|
|
2727
2725
|
details.recipient,
|
|
2728
2726
|
details.amount,
|
|
2729
|
-
details.network ||
|
|
2727
|
+
details.network || SOLANA_NETWORK,
|
|
2730
2728
|
{
|
|
2731
2729
|
resourceUrl: details.resource?.url || fallbackUrl,
|
|
2732
2730
|
resourceDescription: details.resource?.description || "BridgeNode Video Generation",
|
|
@@ -2798,7 +2796,7 @@ var VoiceClient = class {
|
|
|
2798
2796
|
sessionTotalUsd = 0;
|
|
2799
2797
|
sessionCalls = 0;
|
|
2800
2798
|
constructor(options = {}) {
|
|
2801
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
2799
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
2802
2800
|
const privateKey = options.privateKey || envKey;
|
|
2803
2801
|
if (!privateKey) {
|
|
2804
2802
|
throw new Error(
|
|
@@ -2933,7 +2931,7 @@ var VoiceClient = class {
|
|
|
2933
2931
|
this.account.address,
|
|
2934
2932
|
details.recipient,
|
|
2935
2933
|
details.amount,
|
|
2936
|
-
details.network ||
|
|
2934
|
+
details.network || SOLANA_NETWORK,
|
|
2937
2935
|
{
|
|
2938
2936
|
resourceUrl: details.resource?.url || `${this.apiUrl}/v1/voice/call`,
|
|
2939
2937
|
resourceDescription: details.resource?.description || "BridgeNode Voice Call",
|
|
@@ -3017,7 +3015,7 @@ var PhoneClient = class {
|
|
|
3017
3015
|
sessionTotalUsd = 0;
|
|
3018
3016
|
sessionCalls = 0;
|
|
3019
3017
|
constructor(options = {}) {
|
|
3020
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
3018
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
3021
3019
|
const privateKey = options.privateKey || envKey;
|
|
3022
3020
|
if (!privateKey) {
|
|
3023
3021
|
throw new Error(
|
|
@@ -3147,7 +3145,7 @@ var PhoneClient = class {
|
|
|
3147
3145
|
this.account.address,
|
|
3148
3146
|
details.recipient,
|
|
3149
3147
|
details.amount,
|
|
3150
|
-
details.network ||
|
|
3148
|
+
details.network || SOLANA_NETWORK,
|
|
3151
3149
|
{
|
|
3152
3150
|
resourceUrl: details.resource?.url || url,
|
|
3153
3151
|
resourceDescription: details.resource?.description || "BridgeNode Phone",
|
|
@@ -3217,7 +3215,7 @@ var PortraitClient = class {
|
|
|
3217
3215
|
sessionTotalUsd = 0;
|
|
3218
3216
|
sessionCalls = 0;
|
|
3219
3217
|
constructor(options = {}) {
|
|
3220
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
3218
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
3221
3219
|
const privateKey = options.privateKey || envKey;
|
|
3222
3220
|
if (!privateKey) {
|
|
3223
3221
|
throw new Error(
|
|
@@ -3299,10 +3297,10 @@ var PortraitClient = class {
|
|
|
3299
3297
|
this.account.address,
|
|
3300
3298
|
details.recipient,
|
|
3301
3299
|
details.amount,
|
|
3302
|
-
details.network ||
|
|
3300
|
+
details.network || SOLANA_NETWORK,
|
|
3303
3301
|
{
|
|
3304
3302
|
resourceUrl: details.resource?.url || url,
|
|
3305
|
-
resourceDescription: details.resource?.description || "
|
|
3303
|
+
resourceDescription: details.resource?.description || "BridgeNode Virtual Portrait",
|
|
3306
3304
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
3307
3305
|
extra: details.extra
|
|
3308
3306
|
}
|
|
@@ -3368,7 +3366,7 @@ var SearchClient = class {
|
|
|
3368
3366
|
apiUrl;
|
|
3369
3367
|
timeout;
|
|
3370
3368
|
constructor(options = {}) {
|
|
3371
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
3369
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
3372
3370
|
const privateKey = options.privateKey || envKey;
|
|
3373
3371
|
if (!privateKey) {
|
|
3374
3372
|
throw new Error(
|
|
@@ -3446,7 +3444,7 @@ var SearchClient = class {
|
|
|
3446
3444
|
this.account.address,
|
|
3447
3445
|
details.recipient,
|
|
3448
3446
|
details.amount,
|
|
3449
|
-
details.network ||
|
|
3447
|
+
details.network || SOLANA_NETWORK,
|
|
3450
3448
|
{
|
|
3451
3449
|
resourceUrl: details.resource?.url || url,
|
|
3452
3450
|
resourceDescription: details.resource?.description || "BridgeNode Search",
|
|
@@ -3504,7 +3502,7 @@ var PriceClient = class {
|
|
|
3504
3502
|
apiUrl;
|
|
3505
3503
|
timeout;
|
|
3506
3504
|
constructor(options = {}) {
|
|
3507
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
3505
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
3508
3506
|
const privateKey = options.privateKey || envKey;
|
|
3509
3507
|
const requireWallet = options.requireWallet ?? true;
|
|
3510
3508
|
if (!privateKey && requireWallet) {
|
|
@@ -3636,7 +3634,7 @@ var PriceClient = class {
|
|
|
3636
3634
|
this.account.address,
|
|
3637
3635
|
details.recipient,
|
|
3638
3636
|
details.amount,
|
|
3639
|
-
details.network ||
|
|
3637
|
+
details.network || SOLANA_NETWORK,
|
|
3640
3638
|
{
|
|
3641
3639
|
resourceUrl: details.resource?.url || url,
|
|
3642
3640
|
resourceDescription: details.resource?.description || "BridgeNode Price Data",
|
|
@@ -3709,7 +3707,7 @@ var SurfClient = class {
|
|
|
3709
3707
|
apiUrl;
|
|
3710
3708
|
timeout;
|
|
3711
3709
|
constructor(options = {}) {
|
|
3712
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
3710
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
3713
3711
|
const privateKey = options.privateKey || envKey;
|
|
3714
3712
|
if (!privateKey) {
|
|
3715
3713
|
throw new Error(
|
|
@@ -3798,7 +3796,7 @@ var SurfClient = class {
|
|
|
3798
3796
|
this.account.address,
|
|
3799
3797
|
details.recipient,
|
|
3800
3798
|
details.amount,
|
|
3801
|
-
details.network ||
|
|
3799
|
+
details.network || SOLANA_NETWORK,
|
|
3802
3800
|
{
|
|
3803
3801
|
resourceUrl: details.resource?.url || url,
|
|
3804
3802
|
resourceDescription: details.resource?.description || "BridgeNode Surf",
|
|
@@ -3939,7 +3937,7 @@ var RpcClient = class {
|
|
|
3939
3937
|
sessionTotalUsd = 0;
|
|
3940
3938
|
sessionCalls = 0;
|
|
3941
3939
|
constructor(options = {}) {
|
|
3942
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
3940
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
3943
3941
|
const privateKey = options.privateKey || envKey;
|
|
3944
3942
|
if (!privateKey) {
|
|
3945
3943
|
throw new Error(
|
|
@@ -4056,7 +4054,7 @@ var RpcClient = class {
|
|
|
4056
4054
|
this.account.address,
|
|
4057
4055
|
details.recipient,
|
|
4058
4056
|
details.amount,
|
|
4059
|
-
details.network ||
|
|
4057
|
+
details.network || SOLANA_NETWORK,
|
|
4060
4058
|
{
|
|
4061
4059
|
resourceUrl: details.resource?.url || `${this.apiUrl}${endpoint}`,
|
|
4062
4060
|
resourceDescription: details.resource?.description || "BridgeNode Multi-chain RPC",
|
|
@@ -4106,14 +4104,14 @@ var RpcClient = class {
|
|
|
4106
4104
|
}
|
|
4107
4105
|
};
|
|
4108
4106
|
|
|
4109
|
-
// src/
|
|
4107
|
+
// src/bridgenode.ts
|
|
4110
4108
|
import { privateKeyToAccount as privateKeyToAccount13 } from "viem/accounts";
|
|
4111
4109
|
var DEFAULT_API_URL13 = "https://bridgenode.cc/api";
|
|
4112
4110
|
var DEFAULT_TIMEOUT13 = 6e4;
|
|
4113
4111
|
var DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
4114
4112
|
var DEFAULT_POLL_BUDGET_MS = 3e5;
|
|
4115
4113
|
var MAX_SIGNED_AUTH_SECONDS = 600;
|
|
4116
|
-
var
|
|
4114
|
+
var BridgeNodeClient = class {
|
|
4117
4115
|
account;
|
|
4118
4116
|
privateKey;
|
|
4119
4117
|
apiUrl;
|
|
@@ -4121,7 +4119,7 @@ var BlockrunClient = class {
|
|
|
4121
4119
|
sessionTotalUsd = 0;
|
|
4122
4120
|
sessionCalls = 0;
|
|
4123
4121
|
constructor(options = {}) {
|
|
4124
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
4122
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
4125
4123
|
const privateKey = options.privateKey || envKey;
|
|
4126
4124
|
if (!privateKey) {
|
|
4127
4125
|
throw new Error(
|
|
@@ -4137,7 +4135,7 @@ var BlockrunClient = class {
|
|
|
4137
4135
|
this.timeout = options.timeout || DEFAULT_TIMEOUT13;
|
|
4138
4136
|
}
|
|
4139
4137
|
/**
|
|
4140
|
-
* GET a
|
|
4138
|
+
* GET a BridgeNode endpoint. `path` is everything after `/api` (a leading
|
|
4141
4139
|
* `/api` is tolerated and stripped). Query params are URL-encoded; arrays
|
|
4142
4140
|
* become repeated keys (`?a=1&a=2`); undefined/null are dropped.
|
|
4143
4141
|
*/
|
|
@@ -4146,7 +4144,7 @@ var BlockrunClient = class {
|
|
|
4146
4144
|
return this.requestWithPayment(url, "GET");
|
|
4147
4145
|
}
|
|
4148
4146
|
/**
|
|
4149
|
-
* POST a
|
|
4147
|
+
* POST a BridgeNode endpoint with a JSON body.
|
|
4150
4148
|
*/
|
|
4151
4149
|
async post(path5, body) {
|
|
4152
4150
|
const url = this.buildUrl(path5);
|
|
@@ -4427,7 +4425,7 @@ var BlockrunClient = class {
|
|
|
4427
4425
|
this.account.address,
|
|
4428
4426
|
details.recipient,
|
|
4429
4427
|
details.amount,
|
|
4430
|
-
details.network ||
|
|
4428
|
+
details.network || SOLANA_NETWORK,
|
|
4431
4429
|
{
|
|
4432
4430
|
resourceUrl: details.resource?.url || url,
|
|
4433
4431
|
resourceDescription: details.resource?.description || opts.description,
|
|
@@ -4490,7 +4488,7 @@ import * as fs2 from "fs";
|
|
|
4490
4488
|
import * as path2 from "path";
|
|
4491
4489
|
import * as os2 from "os";
|
|
4492
4490
|
var USDC_BASE_CONTRACT = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
4493
|
-
var
|
|
4491
|
+
var BASE_CHAIN_ID = "8453";
|
|
4494
4492
|
var WALLET_DIR = path2.join(os2.homedir(), ".bridgenode");
|
|
4495
4493
|
var WALLET_FILE = path2.join(WALLET_DIR, ".session");
|
|
4496
4494
|
function createWallet() {
|
|
@@ -4603,12 +4601,12 @@ function formatWalletMigrationNotice(newAddress) {
|
|
|
4603
4601
|
if (addresses.length === 0) return null;
|
|
4604
4602
|
const found = addresses.map((addr) => ` ${addr}`).join("\n");
|
|
4605
4603
|
return `
|
|
4606
|
-
NOTICE:
|
|
4604
|
+
NOTICE: BridgeNode created a new wallet, but also found existing wallet(s)
|
|
4607
4605
|
belonging to other applications on this system:
|
|
4608
4606
|
|
|
4609
4607
|
${found}
|
|
4610
4608
|
|
|
4611
|
-
|
|
4609
|
+
BridgeNode now uses only its own wallet:
|
|
4612
4610
|
|
|
4613
4611
|
${newAddress}
|
|
4614
4612
|
|
|
@@ -4618,7 +4616,7 @@ do not control.
|
|
|
4618
4616
|
|
|
4619
4617
|
If an address above is yours and holds your USDC, adopt it deliberately:
|
|
4620
4618
|
|
|
4621
|
-
import { importWallet } from '@
|
|
4619
|
+
import { importWallet } from '@bridgenode/llm';
|
|
4622
4620
|
importWallet("<address-from-the-list-above>");
|
|
4623
4621
|
|
|
4624
4622
|
Your current wallet is backed up first. You can also set
|
|
@@ -4626,7 +4624,7 @@ BRIDGENODE_WALLET_KEY=<private-key> for a single run without changing anything.
|
|
|
4626
4624
|
`;
|
|
4627
4625
|
}
|
|
4628
4626
|
function getOrCreateWallet() {
|
|
4629
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
4627
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
4630
4628
|
if (envKey) {
|
|
4631
4629
|
const account = privateKeyToAccount14(envKey);
|
|
4632
4630
|
return { address: account.address, privateKey: envKey, isNew: false };
|
|
@@ -4641,7 +4639,7 @@ function getOrCreateWallet() {
|
|
|
4641
4639
|
return { address, privateKey, isNew: true };
|
|
4642
4640
|
}
|
|
4643
4641
|
function getWalletAddress() {
|
|
4644
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.
|
|
4642
|
+
const envKey = typeof process !== "undefined" && process.env ? process.env.BRIDGENODE_WALLET_KEY || process.env.BRIDGENODE_WALLET_KEY : void 0;
|
|
4645
4643
|
if (envKey) {
|
|
4646
4644
|
return privateKeyToAccount14(envKey).address;
|
|
4647
4645
|
}
|
|
@@ -4653,26 +4651,26 @@ function getWalletAddress() {
|
|
|
4653
4651
|
}
|
|
4654
4652
|
function getEip681Uri(address, amountUsdc = 1) {
|
|
4655
4653
|
const amountWei = Math.floor(amountUsdc * 1e6);
|
|
4656
|
-
return `ethereum:${USDC_BASE_CONTRACT}@${
|
|
4654
|
+
return `ethereum:${USDC_BASE_CONTRACT}@${BASE_CHAIN_ID}/transfer?address=${address}&uint256=${amountWei}`;
|
|
4657
4655
|
}
|
|
4658
4656
|
function getPaymentLinks(address) {
|
|
4659
4657
|
return {
|
|
4660
4658
|
basescan: `https://basescan.org/address/${address}`,
|
|
4661
|
-
walletLink: `ethereum:${USDC_BASE_CONTRACT}@${
|
|
4662
|
-
ethereum: `ethereum:${address}@${
|
|
4659
|
+
walletLink: `ethereum:${USDC_BASE_CONTRACT}@${BASE_CHAIN_ID}/transfer?address=${address}`,
|
|
4660
|
+
ethereum: `ethereum:${address}@${BASE_CHAIN_ID}`,
|
|
4663
4661
|
bridgenode: `https://bridgenode.cc/fund?address=${address}`
|
|
4664
4662
|
};
|
|
4665
4663
|
}
|
|
4666
4664
|
function formatWalletCreatedMessage(address) {
|
|
4667
4665
|
const links = getPaymentLinks(address);
|
|
4668
4666
|
return `
|
|
4669
|
-
I'm your
|
|
4667
|
+
I'm your BridgeNode Agent! I can access GPT-4, Grok, image generation, and more.
|
|
4670
4668
|
|
|
4671
|
-
Please send $1-5 USDC
|
|
4669
|
+
Please send $1-5 Solana USDC to start:
|
|
4672
4670
|
|
|
4673
4671
|
${address}
|
|
4674
4672
|
|
|
4675
|
-
What is
|
|
4673
|
+
What is Solana? Solana is a high-performance's blockchain network.
|
|
4676
4674
|
You can buy USDC on Coinbase and send it directly to me.
|
|
4677
4675
|
|
|
4678
4676
|
What $1 USDC gets you:
|
|
@@ -4693,7 +4691,7 @@ Your private key never leaves your machine - only signatures are sent.
|
|
|
4693
4691
|
function formatNeedsFundingMessage(address) {
|
|
4694
4692
|
const links = getPaymentLinks(address);
|
|
4695
4693
|
return `
|
|
4696
|
-
I've run out of funds! Please send more USDC
|
|
4694
|
+
I've run out of funds! Please send more Solana USDC to continue helping you.
|
|
4697
4695
|
|
|
4698
4696
|
Send to my address:
|
|
4699
4697
|
${address}
|
|
@@ -4708,7 +4706,7 @@ Your private key never leaves your machine - only signatures are sent.
|
|
|
4708
4706
|
}
|
|
4709
4707
|
function formatFundingMessageCompact(address) {
|
|
4710
4708
|
const links = getPaymentLinks(address);
|
|
4711
|
-
return `I need a little top-up to keep helping you! Send USDC
|
|
4709
|
+
return `I need a little top-up to keep helping you! Send Solana USDC to: ${address}
|
|
4712
4710
|
Check my balance: ${links.basescan}`;
|
|
4713
4711
|
}
|
|
4714
4712
|
var WALLET_FILE_PATH = WALLET_FILE;
|
|
@@ -4857,12 +4855,12 @@ async function formatSolanaWalletMigrationNotice(newAddress) {
|
|
|
4857
4855
|
if (addresses.length === 0) return null;
|
|
4858
4856
|
const found = addresses.map((addr) => ` ${addr}`).join("\n");
|
|
4859
4857
|
return `
|
|
4860
|
-
NOTICE:
|
|
4858
|
+
NOTICE: BridgeNode created a new Solana wallet, but also found existing
|
|
4861
4859
|
wallet(s) belonging to other applications on this system:
|
|
4862
4860
|
|
|
4863
4861
|
${found}
|
|
4864
4862
|
|
|
4865
|
-
|
|
4863
|
+
BridgeNode now uses only its own wallet:
|
|
4866
4864
|
|
|
4867
4865
|
${newAddress}
|
|
4868
4866
|
|
|
@@ -4872,7 +4870,7 @@ do not control.
|
|
|
4872
4870
|
|
|
4873
4871
|
If an address above is yours and holds your USDC, adopt it deliberately:
|
|
4874
4872
|
|
|
4875
|
-
import { importSolanaWallet } from '@
|
|
4873
|
+
import { importSolanaWallet } from '@bridgenode/llm';
|
|
4876
4874
|
await importSolanaWallet("<address-from-the-list-above>");
|
|
4877
4875
|
|
|
4878
4876
|
Your current wallet is backed up first. You can also set
|
|
@@ -5145,7 +5143,7 @@ var SolanaLLMClient = class {
|
|
|
5145
5143
|
// 0x DEX (swap quotes + gasless) — free passthrough
|
|
5146
5144
|
// ============================================================
|
|
5147
5145
|
/**
|
|
5148
|
-
* Query the 0x Swap / Gasless APIs (free — no x402 payment;
|
|
5146
|
+
* Query the 0x Swap / Gasless APIs (free — no x402 payment; BridgeNode
|
|
5149
5147
|
* takes an on-chain affiliate fee on executed swaps instead).
|
|
5150
5148
|
*
|
|
5151
5149
|
* @param path - "price", "quote", "gasless/price", "gasless/quote",
|
|
@@ -5266,7 +5264,7 @@ var SolanaLLMClient = class {
|
|
|
5266
5264
|
const details = extractPaymentDetails(paymentRequired, SOLANA_NETWORK);
|
|
5267
5265
|
if (!details.network?.startsWith("solana:")) {
|
|
5268
5266
|
throw new PaymentError(
|
|
5269
|
-
`Expected Solana payment network, got: ${details.network}. Use LLMClient for
|
|
5267
|
+
`Expected Solana payment network, got: ${details.network}. Use LLMClient for Solana payments.`
|
|
5270
5268
|
);
|
|
5271
5269
|
}
|
|
5272
5270
|
const feePayer = details.extra?.feePayer;
|
|
@@ -5358,7 +5356,7 @@ var SolanaLLMClient = class {
|
|
|
5358
5356
|
const details = extractPaymentDetails(paymentRequired, SOLANA_NETWORK);
|
|
5359
5357
|
if (!details.network?.startsWith("solana:")) {
|
|
5360
5358
|
throw new PaymentError(
|
|
5361
|
-
`Expected Solana payment network, got: ${details.network}. Use LLMClient for
|
|
5359
|
+
`Expected Solana payment network, got: ${details.network}. Use LLMClient for Solana payments.`
|
|
5362
5360
|
);
|
|
5363
5361
|
}
|
|
5364
5362
|
const feePayer = details.extra?.feePayer;
|
|
@@ -5450,7 +5448,7 @@ var SolanaLLMClient = class {
|
|
|
5450
5448
|
const details = extractPaymentDetails(paymentRequired, SOLANA_NETWORK);
|
|
5451
5449
|
if (!details.network?.startsWith("solana:")) {
|
|
5452
5450
|
throw new PaymentError(
|
|
5453
|
-
`Expected Solana payment network, got: ${details.network}. Use LLMClient for
|
|
5451
|
+
`Expected Solana payment network, got: ${details.network}. Use LLMClient for Solana payments.`
|
|
5454
5452
|
);
|
|
5455
5453
|
}
|
|
5456
5454
|
const feePayer = details.extra?.feePayer;
|
|
@@ -5716,7 +5714,7 @@ function setupAgentWallet(options) {
|
|
|
5716
5714
|
`
|
|
5717
5715
|
BridgeNode Agent Wallet Created!
|
|
5718
5716
|
Address: ${address}
|
|
5719
|
-
Send USDC on
|
|
5717
|
+
Send USDC on Solana to get started.
|
|
5720
5718
|
`
|
|
5721
5719
|
);
|
|
5722
5720
|
}
|
|
@@ -5960,7 +5958,7 @@ var AnthropicClient = class {
|
|
|
5960
5958
|
this._account.address,
|
|
5961
5959
|
details.recipient,
|
|
5962
5960
|
details.amount,
|
|
5963
|
-
details.network ||
|
|
5961
|
+
details.network || SOLANA_NETWORK,
|
|
5964
5962
|
{
|
|
5965
5963
|
resourceUrl: validateResourceUrl(
|
|
5966
5964
|
details.resource?.url || `${this._apiUrl}/v1/messages`,
|
|
@@ -6009,8 +6007,7 @@ var AnthropicClient = class {
|
|
|
6009
6007
|
export {
|
|
6010
6008
|
APIError,
|
|
6011
6009
|
AnthropicClient,
|
|
6012
|
-
|
|
6013
|
-
BlockrunClient as BridgeNodeClient,
|
|
6010
|
+
BridgeNodeClient,
|
|
6014
6011
|
BridgeNodeError,
|
|
6015
6012
|
ImageClient,
|
|
6016
6013
|
KNOWN_PROVIDERS,
|
|
@@ -6033,8 +6030,6 @@ export {
|
|
|
6033
6030
|
SolanaLLMClient,
|
|
6034
6031
|
SpeechClient,
|
|
6035
6032
|
SurfClient,
|
|
6036
|
-
USDC_BASE,
|
|
6037
|
-
USDC_BASE_CONTRACT,
|
|
6038
6033
|
USDC_SOLANA,
|
|
6039
6034
|
VideoClient,
|
|
6040
6035
|
VoiceClient,
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgenode/llm",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "BridgeNode SDK - Pay-per-request AI
|
|
5
|
+
"description": "BridgeNode SDK - Pay-per-request AI via x402 on Solana",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"repository": {
|
|
43
43
|
"type": "git",
|
|
44
|
-
"url": "git+https://github.com/
|
|
44
|
+
"url": "git+https://github.com/applefanaimail-blip/llm"
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://bridgenode.cc",
|
|
47
47
|
"bugs": {
|
|
48
|
-
"url": "https://github.com/
|
|
48
|
+
"url": "https://github.com/applefanaimail-blip/llm/issues"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"bs58": "^6.0.0",
|
|
@@ -84,4 +84,4 @@
|
|
|
84
84
|
"optional": true
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
}
|
|
87
|
+
}
|