@blockrun/clawrouter 0.12.102 → 0.12.104
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/cli.d.ts +0 -15
- package/dist/cli.js +80068 -407
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1406 -34
- package/dist/index.js +81085 -1075
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scripts/reinstall.sh +43 -7
- package/scripts/update.sh +35 -1
- package/dist/auth.d.ts +0 -82
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -388
- package/dist/auth.js.map +0 -1
- package/dist/balance.d.ts +0 -97
- package/dist/balance.d.ts.map +0 -1
- package/dist/balance.js +0 -157
- package/dist/balance.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/compression/codebook.d.ts +0 -24
- package/dist/compression/codebook.d.ts.map +0 -1
- package/dist/compression/codebook.js +0 -119
- package/dist/compression/codebook.js.map +0 -1
- package/dist/compression/index.d.ts +0 -33
- package/dist/compression/index.d.ts.map +0 -1
- package/dist/compression/index.js +0 -246
- package/dist/compression/index.js.map +0 -1
- package/dist/compression/layers/deduplication.d.ts +0 -28
- package/dist/compression/layers/deduplication.d.ts.map +0 -1
- package/dist/compression/layers/deduplication.js +0 -101
- package/dist/compression/layers/deduplication.js.map +0 -1
- package/dist/compression/layers/dictionary.d.ts +0 -21
- package/dist/compression/layers/dictionary.d.ts.map +0 -1
- package/dist/compression/layers/dictionary.js +0 -73
- package/dist/compression/layers/dictionary.js.map +0 -1
- package/dist/compression/layers/dynamic-codebook.d.ts +0 -26
- package/dist/compression/layers/dynamic-codebook.d.ts.map +0 -1
- package/dist/compression/layers/dynamic-codebook.js +0 -149
- package/dist/compression/layers/dynamic-codebook.js.map +0 -1
- package/dist/compression/layers/json-compact.d.ts +0 -23
- package/dist/compression/layers/json-compact.d.ts.map +0 -1
- package/dist/compression/layers/json-compact.js +0 -79
- package/dist/compression/layers/json-compact.js.map +0 -1
- package/dist/compression/layers/observation.d.ts +0 -21
- package/dist/compression/layers/observation.d.ts.map +0 -1
- package/dist/compression/layers/observation.js +0 -130
- package/dist/compression/layers/observation.js.map +0 -1
- package/dist/compression/layers/paths.d.ts +0 -24
- package/dist/compression/layers/paths.d.ts.map +0 -1
- package/dist/compression/layers/paths.js +0 -110
- package/dist/compression/layers/paths.js.map +0 -1
- package/dist/compression/layers/whitespace.d.ts +0 -27
- package/dist/compression/layers/whitespace.d.ts.map +0 -1
- package/dist/compression/layers/whitespace.js +0 -60
- package/dist/compression/layers/whitespace.js.map +0 -1
- package/dist/compression/types.d.ts +0 -84
- package/dist/compression/types.d.ts.map +0 -1
- package/dist/compression/types.js +0 -27
- package/dist/compression/types.js.map +0 -1
- package/dist/config.d.ts +0 -12
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -22
- package/dist/config.js.map +0 -1
- package/dist/dedup.d.ts +0 -34
- package/dist/dedup.d.ts.map +0 -1
- package/dist/dedup.js +0 -150
- package/dist/dedup.js.map +0 -1
- package/dist/doctor.d.ts +0 -8
- package/dist/doctor.d.ts.map +0 -1
- package/dist/doctor.js +0 -375
- package/dist/doctor.js.map +0 -1
- package/dist/error-classification.test.d.ts +0 -2
- package/dist/error-classification.test.d.ts.map +0 -1
- package/dist/error-classification.test.js +0 -59
- package/dist/error-classification.test.js.map +0 -1
- package/dist/errors.d.ts +0 -54
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -85
- package/dist/errors.js.map +0 -1
- package/dist/exclude-models.d.ts +0 -28
- package/dist/exclude-models.d.ts.map +0 -1
- package/dist/exclude-models.integration.test.d.ts +0 -2
- package/dist/exclude-models.integration.test.d.ts.map +0 -1
- package/dist/exclude-models.integration.test.js +0 -46
- package/dist/exclude-models.integration.test.js.map +0 -1
- package/dist/exclude-models.js +0 -70
- package/dist/exclude-models.js.map +0 -1
- package/dist/exclude-models.test.d.ts +0 -5
- package/dist/exclude-models.test.d.ts.map +0 -1
- package/dist/exclude-models.test.js +0 -95
- package/dist/exclude-models.test.js.map +0 -1
- package/dist/fs-read.d.ts +0 -11
- package/dist/fs-read.d.ts.map +0 -1
- package/dist/fs-read.js +0 -47
- package/dist/fs-read.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/journal.d.ts +0 -67
- package/dist/journal.d.ts.map +0 -1
- package/dist/journal.js +0 -184
- package/dist/journal.js.map +0 -1
- package/dist/journal.test.d.ts +0 -2
- package/dist/journal.test.d.ts.map +0 -1
- package/dist/journal.test.js +0 -201
- package/dist/journal.test.js.map +0 -1
- package/dist/logger.d.ts +0 -33
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -35
- package/dist/logger.js.map +0 -1
- package/dist/models.d.ts +0 -107
- package/dist/models.d.ts.map +0 -1
- package/dist/models.js +0 -941
- package/dist/models.js.map +0 -1
- package/dist/models.test.d.ts +0 -2
- package/dist/models.test.d.ts.map +0 -1
- package/dist/models.test.js +0 -38
- package/dist/models.test.js.map +0 -1
- package/dist/partners/index.d.ts +0 -8
- package/dist/partners/index.d.ts.map +0 -1
- package/dist/partners/index.js +0 -6
- package/dist/partners/index.js.map +0 -1
- package/dist/partners/registry.d.ts +0 -51
- package/dist/partners/registry.d.ts.map +0 -1
- package/dist/partners/registry.js +0 -256
- package/dist/partners/registry.js.map +0 -1
- package/dist/partners/tools.d.ts +0 -24
- package/dist/partners/tools.d.ts.map +0 -1
- package/dist/partners/tools.js +0 -97
- package/dist/partners/tools.js.map +0 -1
- package/dist/payment-preauth.d.ts +0 -17
- package/dist/payment-preauth.d.ts.map +0 -1
- package/dist/payment-preauth.js +0 -102
- package/dist/payment-preauth.js.map +0 -1
- package/dist/provider.d.ts +0 -19
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -45
- package/dist/provider.js.map +0 -1
- package/dist/proxy.d.ts +0 -210
- package/dist/proxy.d.ts.map +0 -1
- package/dist/proxy.debrand.test.d.ts +0 -2
- package/dist/proxy.debrand.test.d.ts.map +0 -1
- package/dist/proxy.debrand.test.js +0 -101
- package/dist/proxy.debrand.test.js.map +0 -1
- package/dist/proxy.degraded-response.test.d.ts +0 -2
- package/dist/proxy.degraded-response.test.d.ts.map +0 -1
- package/dist/proxy.degraded-response.test.js +0 -105
- package/dist/proxy.degraded-response.test.js.map +0 -1
- package/dist/proxy.image-download.test.d.ts +0 -2
- package/dist/proxy.image-download.test.d.ts.map +0 -1
- package/dist/proxy.image-download.test.js +0 -92
- package/dist/proxy.image-download.test.js.map +0 -1
- package/dist/proxy.js +0 -3810
- package/dist/proxy.js.map +0 -1
- package/dist/proxy.models-endpoint.test.d.ts +0 -2
- package/dist/proxy.models-endpoint.test.d.ts.map +0 -1
- package/dist/proxy.models-endpoint.test.js +0 -19
- package/dist/proxy.models-endpoint.test.js.map +0 -1
- package/dist/proxy.multiturn-thinking.test.d.ts +0 -2
- package/dist/proxy.multiturn-thinking.test.d.ts.map +0 -1
- package/dist/proxy.multiturn-thinking.test.js +0 -82
- package/dist/proxy.multiturn-thinking.test.js.map +0 -1
- package/dist/proxy.payment-chain-reuse.test.d.ts +0 -2
- package/dist/proxy.payment-chain-reuse.test.d.ts.map +0 -1
- package/dist/proxy.payment-chain-reuse.test.js +0 -30
- package/dist/proxy.payment-chain-reuse.test.js.map +0 -1
- package/dist/proxy.solana-resilience.test.d.ts +0 -12
- package/dist/proxy.solana-resilience.test.d.ts.map +0 -1
- package/dist/proxy.solana-resilience.test.js +0 -39
- package/dist/proxy.solana-resilience.test.js.map +0 -1
- package/dist/report.d.ts +0 -6
- package/dist/report.d.ts.map +0 -1
- package/dist/report.js +0 -44
- package/dist/report.js.map +0 -1
- package/dist/response-cache.advanced.test.d.ts +0 -2
- package/dist/response-cache.advanced.test.d.ts.map +0 -1
- package/dist/response-cache.advanced.test.js +0 -566
- package/dist/response-cache.advanced.test.js.map +0 -1
- package/dist/response-cache.d.ts +0 -85
- package/dist/response-cache.d.ts.map +0 -1
- package/dist/response-cache.edge-cases.test.d.ts +0 -2
- package/dist/response-cache.edge-cases.test.d.ts.map +0 -1
- package/dist/response-cache.edge-cases.test.js +0 -488
- package/dist/response-cache.edge-cases.test.js.map +0 -1
- package/dist/response-cache.extreme.test.d.ts +0 -2
- package/dist/response-cache.extreme.test.d.ts.map +0 -1
- package/dist/response-cache.extreme.test.js +0 -561
- package/dist/response-cache.extreme.test.js.map +0 -1
- package/dist/response-cache.js +0 -240
- package/dist/response-cache.js.map +0 -1
- package/dist/response-cache.test.d.ts +0 -2
- package/dist/response-cache.test.d.ts.map +0 -1
- package/dist/response-cache.test.js +0 -242
- package/dist/response-cache.test.js.map +0 -1
- package/dist/retry.d.ts +0 -42
- package/dist/retry.d.ts.map +0 -1
- package/dist/retry.js +0 -99
- package/dist/retry.js.map +0 -1
- package/dist/router/config.d.ts +0 -11
- package/dist/router/config.d.ts.map +0 -1
- package/dist/router/config.js +0 -1215
- package/dist/router/config.js.map +0 -1
- package/dist/router/index.d.ts +0 -18
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/index.js +0 -19
- package/dist/router/index.js.map +0 -1
- package/dist/router/llm-classifier.d.ts +0 -29
- package/dist/router/llm-classifier.d.ts.map +0 -1
- package/dist/router/llm-classifier.js +0 -99
- package/dist/router/llm-classifier.js.map +0 -1
- package/dist/router/rules.d.ts +0 -12
- package/dist/router/rules.d.ts.map +0 -1
- package/dist/router/rules.js +0 -202
- package/dist/router/rules.js.map +0 -1
- package/dist/router/selector.d.ts +0 -58
- package/dist/router/selector.d.ts.map +0 -1
- package/dist/router/selector.js +0 -165
- package/dist/router/selector.js.map +0 -1
- package/dist/router/selector.test.d.ts +0 -2
- package/dist/router/selector.test.d.ts.map +0 -1
- package/dist/router/selector.test.js +0 -67
- package/dist/router/selector.test.js.map +0 -1
- package/dist/router/strategy.d.ts +0 -19
- package/dist/router/strategy.d.ts.map +0 -1
- package/dist/router/strategy.js +0 -138
- package/dist/router/strategy.js.map +0 -1
- package/dist/router/strategy.test.d.ts +0 -2
- package/dist/router/strategy.test.d.ts.map +0 -1
- package/dist/router/strategy.test.js +0 -131
- package/dist/router/strategy.test.js.map +0 -1
- package/dist/router/types.d.ts +0 -127
- package/dist/router/types.d.ts.map +0 -1
- package/dist/router/types.js +0 -11
- package/dist/router/types.js.map +0 -1
- package/dist/session.d.ts +0 -124
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -256
- package/dist/session.js.map +0 -1
- package/dist/session.test.d.ts +0 -2
- package/dist/session.test.d.ts.map +0 -1
- package/dist/session.test.js +0 -163
- package/dist/session.test.js.map +0 -1
- package/dist/solana-balance.d.ts +0 -48
- package/dist/solana-balance.d.ts.map +0 -1
- package/dist/solana-balance.js +0 -142
- package/dist/solana-balance.js.map +0 -1
- package/dist/spend-control.d.ts +0 -112
- package/dist/spend-control.d.ts.map +0 -1
- package/dist/spend-control.js +0 -278
- package/dist/spend-control.js.map +0 -1
- package/dist/spend-control.test.d.ts +0 -5
- package/dist/spend-control.test.d.ts.map +0 -1
- package/dist/spend-control.test.js +0 -210
- package/dist/spend-control.test.js.map +0 -1
- package/dist/stats.d.ts +0 -64
- package/dist/stats.d.ts.map +0 -1
- package/dist/stats.js +0 -295
- package/dist/stats.js.map +0 -1
- package/dist/types.d.ts +0 -150
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -9
- package/dist/types.js.map +0 -1
- package/dist/update-hint.test.d.ts +0 -9
- package/dist/update-hint.test.d.ts.map +0 -1
- package/dist/update-hint.test.js +0 -156
- package/dist/update-hint.test.js.map +0 -1
- package/dist/updater.d.ts +0 -10
- package/dist/updater.d.ts.map +0 -1
- package/dist/updater.js +0 -55
- package/dist/updater.js.map +0 -1
- package/dist/version.d.ts +0 -3
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -16
- package/dist/version.js.map +0 -1
- package/dist/wallet.d.ts +0 -52
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -94
- package/dist/wallet.js.map +0 -1
- package/dist/wallet.test.d.ts +0 -6
- package/dist/wallet.test.d.ts.map +0 -1
- package/dist/wallet.test.js +0 -117
- package/dist/wallet.test.js.map +0 -1
- package/dist/x402-sdk.test.d.ts +0 -6
- package/dist/x402-sdk.test.d.ts.map +0 -1
- package/dist/x402-sdk.test.js +0 -161
- package/dist/x402-sdk.test.js.map +0 -1
package/dist/balance.d.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Balance Monitor for ClawRouter
|
|
3
|
-
*
|
|
4
|
-
* Monitors USDC balance on Base network with intelligent caching.
|
|
5
|
-
* Provides pre-request balance checks to prevent failed payments.
|
|
6
|
-
*
|
|
7
|
-
* Caching Strategy:
|
|
8
|
-
* - TTL: 30 seconds (balance is cached to avoid excessive RPC calls)
|
|
9
|
-
* - Optimistic deduction: after successful payment, subtract estimated cost from cache
|
|
10
|
-
* - Invalidation: on payment failure, immediately refresh from RPC
|
|
11
|
-
*/
|
|
12
|
-
/** Balance thresholds in USDC smallest unit (6 decimals) */
|
|
13
|
-
export declare const BALANCE_THRESHOLDS: {
|
|
14
|
-
/** Low balance warning threshold: $1.00 */
|
|
15
|
-
readonly LOW_BALANCE_MICROS: 1000000n;
|
|
16
|
-
/** Effectively zero threshold: $0.0001 (covers dust/rounding) */
|
|
17
|
-
readonly ZERO_THRESHOLD: 100n;
|
|
18
|
-
};
|
|
19
|
-
/** Balance information returned by checkBalance() */
|
|
20
|
-
export type BalanceInfo = {
|
|
21
|
-
/** Raw balance in USDC smallest unit (6 decimals) */
|
|
22
|
-
balance: bigint;
|
|
23
|
-
/** Formatted balance as "$X.XX" */
|
|
24
|
-
balanceUSD: string;
|
|
25
|
-
/** True if balance < $1.00 */
|
|
26
|
-
isLow: boolean;
|
|
27
|
-
/** True if balance < $0.0001 (effectively zero) */
|
|
28
|
-
isEmpty: boolean;
|
|
29
|
-
/** Wallet address for funding instructions */
|
|
30
|
-
walletAddress: string;
|
|
31
|
-
};
|
|
32
|
-
/** Result from checkSufficient() */
|
|
33
|
-
export type SufficiencyResult = {
|
|
34
|
-
/** True if balance >= estimated cost */
|
|
35
|
-
sufficient: boolean;
|
|
36
|
-
/** Current balance info */
|
|
37
|
-
info: BalanceInfo;
|
|
38
|
-
/** If insufficient, the shortfall as "$X.XX" */
|
|
39
|
-
shortfall?: string;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Monitors USDC balance on Base network.
|
|
43
|
-
*
|
|
44
|
-
* Usage:
|
|
45
|
-
* const monitor = new BalanceMonitor("0x...");
|
|
46
|
-
* const info = await monitor.checkBalance();
|
|
47
|
-
* if (info.isLow) console.warn("Low balance!");
|
|
48
|
-
*/
|
|
49
|
-
export declare class BalanceMonitor {
|
|
50
|
-
private readonly client;
|
|
51
|
-
private readonly walletAddress;
|
|
52
|
-
/** Cached balance (null = not yet fetched) */
|
|
53
|
-
private cachedBalance;
|
|
54
|
-
/** Timestamp when cache was last updated */
|
|
55
|
-
private cachedAt;
|
|
56
|
-
constructor(walletAddress: string);
|
|
57
|
-
/**
|
|
58
|
-
* Check current USDC balance.
|
|
59
|
-
* Uses cache if valid, otherwise fetches from RPC.
|
|
60
|
-
*/
|
|
61
|
-
checkBalance(): Promise<BalanceInfo>;
|
|
62
|
-
/**
|
|
63
|
-
* Check if balance is sufficient for an estimated cost.
|
|
64
|
-
*
|
|
65
|
-
* @param estimatedCostMicros - Estimated cost in USDC smallest unit (6 decimals)
|
|
66
|
-
*/
|
|
67
|
-
checkSufficient(estimatedCostMicros: bigint): Promise<SufficiencyResult>;
|
|
68
|
-
/**
|
|
69
|
-
* Optimistically deduct estimated cost from cached balance.
|
|
70
|
-
* Call this after a successful payment to keep cache accurate.
|
|
71
|
-
*
|
|
72
|
-
* @param amountMicros - Amount to deduct in USDC smallest unit
|
|
73
|
-
*/
|
|
74
|
-
deductEstimated(amountMicros: bigint): void;
|
|
75
|
-
/**
|
|
76
|
-
* Invalidate cache, forcing next checkBalance() to fetch from RPC.
|
|
77
|
-
* Call this after a payment failure to get accurate balance.
|
|
78
|
-
*/
|
|
79
|
-
invalidate(): void;
|
|
80
|
-
/**
|
|
81
|
-
* Force refresh balance from RPC (ignores cache).
|
|
82
|
-
*/
|
|
83
|
-
refresh(): Promise<BalanceInfo>;
|
|
84
|
-
/**
|
|
85
|
-
* Format USDC amount (in micros) as "$X.XX".
|
|
86
|
-
*/
|
|
87
|
-
formatUSDC(amountMicros: bigint): string;
|
|
88
|
-
/**
|
|
89
|
-
* Get the wallet address being monitored.
|
|
90
|
-
*/
|
|
91
|
-
getWalletAddress(): string;
|
|
92
|
-
/** Fetch balance from RPC */
|
|
93
|
-
private fetchBalance;
|
|
94
|
-
/** Build BalanceInfo from raw balance */
|
|
95
|
-
private buildInfo;
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=balance.d.ts.map
|
package/dist/balance.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../src/balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB;IAC7B,2CAA2C;;IAE3C,iEAAiE;;CAEzD,CAAC;AAEX,qDAAqD;AACrD,MAAM,MAAM,WAAW,GAAG;IACxB,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,8BAA8B;IAC9B,KAAK,EAAE,OAAO,CAAC;IACf,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,oCAAoC;AACpC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,2BAA2B;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAE9C,8CAA8C;IAC9C,OAAO,CAAC,aAAa,CAAuB;IAC5C,4CAA4C;IAC5C,OAAO,CAAC,QAAQ,CAAK;gBAET,aAAa,EAAE,MAAM;IAUjC;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC;IAwB1C;;;;OAIG;IACG,eAAe,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAe9E;;;;;OAKG;IACH,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAM3C;;;OAGG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IAKrC;;OAEG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAMxC;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAI1B,6BAA6B;YACf,YAAY;IAgB1B,yCAAyC;IACzC,OAAO,CAAC,SAAS;CASlB"}
|
package/dist/balance.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Balance Monitor for ClawRouter
|
|
3
|
-
*
|
|
4
|
-
* Monitors USDC balance on Base network with intelligent caching.
|
|
5
|
-
* Provides pre-request balance checks to prevent failed payments.
|
|
6
|
-
*
|
|
7
|
-
* Caching Strategy:
|
|
8
|
-
* - TTL: 30 seconds (balance is cached to avoid excessive RPC calls)
|
|
9
|
-
* - Optimistic deduction: after successful payment, subtract estimated cost from cache
|
|
10
|
-
* - Invalidation: on payment failure, immediately refresh from RPC
|
|
11
|
-
*/
|
|
12
|
-
import { createPublicClient, http, erc20Abi } from "viem";
|
|
13
|
-
import { base } from "viem/chains";
|
|
14
|
-
import { RpcError } from "./errors.js";
|
|
15
|
-
/** USDC contract address on Base mainnet */
|
|
16
|
-
const USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
17
|
-
/** Cache TTL in milliseconds (30 seconds) */
|
|
18
|
-
const CACHE_TTL_MS = 30_000;
|
|
19
|
-
/** Balance thresholds in USDC smallest unit (6 decimals) */
|
|
20
|
-
export const BALANCE_THRESHOLDS = {
|
|
21
|
-
/** Low balance warning threshold: $1.00 */
|
|
22
|
-
LOW_BALANCE_MICROS: 1000000n,
|
|
23
|
-
/** Effectively zero threshold: $0.0001 (covers dust/rounding) */
|
|
24
|
-
ZERO_THRESHOLD: 100n,
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Monitors USDC balance on Base network.
|
|
28
|
-
*
|
|
29
|
-
* Usage:
|
|
30
|
-
* const monitor = new BalanceMonitor("0x...");
|
|
31
|
-
* const info = await monitor.checkBalance();
|
|
32
|
-
* if (info.isLow) console.warn("Low balance!");
|
|
33
|
-
*/
|
|
34
|
-
export class BalanceMonitor {
|
|
35
|
-
client;
|
|
36
|
-
walletAddress;
|
|
37
|
-
/** Cached balance (null = not yet fetched) */
|
|
38
|
-
cachedBalance = null;
|
|
39
|
-
/** Timestamp when cache was last updated */
|
|
40
|
-
cachedAt = 0;
|
|
41
|
-
constructor(walletAddress) {
|
|
42
|
-
this.walletAddress = walletAddress;
|
|
43
|
-
this.client = createPublicClient({
|
|
44
|
-
chain: base,
|
|
45
|
-
transport: http(undefined, {
|
|
46
|
-
timeout: 10_000, // 10 second timeout to prevent hanging on slow RPC
|
|
47
|
-
}),
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Check current USDC balance.
|
|
52
|
-
* Uses cache if valid, otherwise fetches from RPC.
|
|
53
|
-
*/
|
|
54
|
-
async checkBalance() {
|
|
55
|
-
const now = Date.now();
|
|
56
|
-
// Use cache only when balance is positive and still fresh.
|
|
57
|
-
// Zero balance is never cached — always re-fetch so a funded wallet is
|
|
58
|
-
// detected on the next request without waiting for cache expiry.
|
|
59
|
-
if (this.cachedBalance !== null &&
|
|
60
|
-
this.cachedBalance > 0n &&
|
|
61
|
-
now - this.cachedAt < CACHE_TTL_MS) {
|
|
62
|
-
return this.buildInfo(this.cachedBalance);
|
|
63
|
-
}
|
|
64
|
-
// Fetch from RPC
|
|
65
|
-
const balance = await this.fetchBalance();
|
|
66
|
-
if (balance > 0n) {
|
|
67
|
-
this.cachedBalance = balance;
|
|
68
|
-
this.cachedAt = now;
|
|
69
|
-
}
|
|
70
|
-
return this.buildInfo(balance);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Check if balance is sufficient for an estimated cost.
|
|
74
|
-
*
|
|
75
|
-
* @param estimatedCostMicros - Estimated cost in USDC smallest unit (6 decimals)
|
|
76
|
-
*/
|
|
77
|
-
async checkSufficient(estimatedCostMicros) {
|
|
78
|
-
const info = await this.checkBalance();
|
|
79
|
-
if (info.balance >= estimatedCostMicros) {
|
|
80
|
-
return { sufficient: true, info };
|
|
81
|
-
}
|
|
82
|
-
const shortfall = estimatedCostMicros - info.balance;
|
|
83
|
-
return {
|
|
84
|
-
sufficient: false,
|
|
85
|
-
info,
|
|
86
|
-
shortfall: this.formatUSDC(shortfall),
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Optimistically deduct estimated cost from cached balance.
|
|
91
|
-
* Call this after a successful payment to keep cache accurate.
|
|
92
|
-
*
|
|
93
|
-
* @param amountMicros - Amount to deduct in USDC smallest unit
|
|
94
|
-
*/
|
|
95
|
-
deductEstimated(amountMicros) {
|
|
96
|
-
if (this.cachedBalance !== null && this.cachedBalance >= amountMicros) {
|
|
97
|
-
this.cachedBalance -= amountMicros;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Invalidate cache, forcing next checkBalance() to fetch from RPC.
|
|
102
|
-
* Call this after a payment failure to get accurate balance.
|
|
103
|
-
*/
|
|
104
|
-
invalidate() {
|
|
105
|
-
this.cachedBalance = null;
|
|
106
|
-
this.cachedAt = 0;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Force refresh balance from RPC (ignores cache).
|
|
110
|
-
*/
|
|
111
|
-
async refresh() {
|
|
112
|
-
this.invalidate();
|
|
113
|
-
return this.checkBalance();
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Format USDC amount (in micros) as "$X.XX".
|
|
117
|
-
*/
|
|
118
|
-
formatUSDC(amountMicros) {
|
|
119
|
-
// USDC has 6 decimals
|
|
120
|
-
const dollars = Number(amountMicros) / 1_000_000;
|
|
121
|
-
return `$${dollars.toFixed(2)}`;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Get the wallet address being monitored.
|
|
125
|
-
*/
|
|
126
|
-
getWalletAddress() {
|
|
127
|
-
return this.walletAddress;
|
|
128
|
-
}
|
|
129
|
-
/** Fetch balance from RPC */
|
|
130
|
-
async fetchBalance() {
|
|
131
|
-
try {
|
|
132
|
-
const balance = await this.client.readContract({
|
|
133
|
-
address: USDC_BASE,
|
|
134
|
-
abi: erc20Abi,
|
|
135
|
-
functionName: "balanceOf",
|
|
136
|
-
args: [this.walletAddress],
|
|
137
|
-
});
|
|
138
|
-
return balance;
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
// Throw typed error instead of silently returning 0
|
|
142
|
-
// This allows callers to distinguish "node down" from "wallet empty"
|
|
143
|
-
throw new RpcError(error instanceof Error ? error.message : "Unknown error", error);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/** Build BalanceInfo from raw balance */
|
|
147
|
-
buildInfo(balance) {
|
|
148
|
-
return {
|
|
149
|
-
balance,
|
|
150
|
-
balanceUSD: this.formatUSDC(balance),
|
|
151
|
-
isLow: balance < BALANCE_THRESHOLDS.LOW_BALANCE_MICROS,
|
|
152
|
-
isEmpty: balance < BALANCE_THRESHOLDS.ZERO_THRESHOLD,
|
|
153
|
-
walletAddress: this.walletAddress,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
//# sourceMappingURL=balance.js.map
|
package/dist/balance.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../src/balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,4CAA4C;AAC5C,MAAM,SAAS,GAAG,4CAAqD,CAAC;AAExE,6CAA6C;AAC7C,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,4DAA4D;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,2CAA2C;IAC3C,kBAAkB,EAAE,QAAU;IAC9B,iEAAiE;IACjE,cAAc,EAAE,IAAI;CACZ,CAAC;AA0BX;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IACR,MAAM,CAAC;IACP,aAAa,CAAgB;IAE9C,8CAA8C;IACtC,aAAa,GAAkB,IAAI,CAAC;IAC5C,4CAA4C;IACpC,QAAQ,GAAG,CAAC,CAAC;IAErB,YAAY,aAAqB;QAC/B,IAAI,CAAC,aAAa,GAAG,aAA8B,CAAC;QACpD,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC;YAC/B,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE;gBACzB,OAAO,EAAE,MAAM,EAAE,mDAAmD;aACrE,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY;QAChB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,2DAA2D;QAC3D,uEAAuE;QACvE,iEAAiE;QACjE,IACE,IAAI,CAAC,a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
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dictionary Codebook
|
|
3
|
-
*
|
|
4
|
-
* Static dictionary of frequently repeated phrases observed in LLM prompts.
|
|
5
|
-
* Built from analysis of BlockRun production logs.
|
|
6
|
-
*
|
|
7
|
-
* Format: Short code ($XX) -> Long phrase
|
|
8
|
-
* The LLM receives a codebook header and decodes in-context.
|
|
9
|
-
*/
|
|
10
|
-
export declare const STATIC_CODEBOOK: Record<string, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Get the inverse codebook for decompression.
|
|
13
|
-
*/
|
|
14
|
-
export declare function getInverseCodebook(): Record<string, string>;
|
|
15
|
-
/**
|
|
16
|
-
* Generate the codebook header for inclusion in system message.
|
|
17
|
-
* LLMs can decode in-context using this header.
|
|
18
|
-
*/
|
|
19
|
-
export declare function generateCodebookHeader(usedCodes: Set<string>, pathMap?: Record<string, string>): string;
|
|
20
|
-
/**
|
|
21
|
-
* Decompress a string using the codebook (for logging).
|
|
22
|
-
*/
|
|
23
|
-
export declare function decompressContent(content: string, codebook?: Record<string, string>): string;
|
|
24
|
-
//# sourceMappingURL=codebook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codebook.d.ts","sourceRoot":"","sources":["../../src/compression/codebook.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuElD,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAM3D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EACtB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,MAAM,CAwBR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAmB,GACjD,MAAM,CAMR"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dictionary Codebook
|
|
3
|
-
*
|
|
4
|
-
* Static dictionary of frequently repeated phrases observed in LLM prompts.
|
|
5
|
-
* Built from analysis of BlockRun production logs.
|
|
6
|
-
*
|
|
7
|
-
* Format: Short code ($XX) -> Long phrase
|
|
8
|
-
* The LLM receives a codebook header and decodes in-context.
|
|
9
|
-
*/
|
|
10
|
-
// Static codebook - common patterns from system prompts
|
|
11
|
-
// Ordered by expected frequency and impact
|
|
12
|
-
export const STATIC_CODEBOOK = {
|
|
13
|
-
// High-impact: OpenClaw/Agent system prompt patterns (very common)
|
|
14
|
-
$OC01: "unbrowse_", // Common prefix in tool names
|
|
15
|
-
$OC02: "<location>",
|
|
16
|
-
$OC03: "</location>",
|
|
17
|
-
$OC04: "<name>",
|
|
18
|
-
$OC05: "</name>",
|
|
19
|
-
$OC06: "<description>",
|
|
20
|
-
$OC07: "</description>",
|
|
21
|
-
$OC08: "(may need login)",
|
|
22
|
-
$OC09: "API skill for OpenClaw",
|
|
23
|
-
$OC10: "endpoints",
|
|
24
|
-
// Skill/tool markers
|
|
25
|
-
$SK01: "<available_skills>",
|
|
26
|
-
$SK02: "</available_skills>",
|
|
27
|
-
$SK03: "<skill>",
|
|
28
|
-
$SK04: "</skill>",
|
|
29
|
-
// Schema patterns (very common in tool definitions)
|
|
30
|
-
$T01: 'type: "function"',
|
|
31
|
-
$T02: '"type": "function"',
|
|
32
|
-
$T03: '"type": "string"',
|
|
33
|
-
$T04: '"type": "object"',
|
|
34
|
-
$T05: '"type": "array"',
|
|
35
|
-
$T06: '"type": "boolean"',
|
|
36
|
-
$T07: '"type": "number"',
|
|
37
|
-
// Common descriptions
|
|
38
|
-
$D01: "description:",
|
|
39
|
-
$D02: '"description":',
|
|
40
|
-
// Common instructions
|
|
41
|
-
$I01: "You are a personal assistant",
|
|
42
|
-
$I02: "Tool names are case-sensitive",
|
|
43
|
-
$I03: "Call tools exactly as listed",
|
|
44
|
-
$I04: "Use when",
|
|
45
|
-
$I05: "without asking",
|
|
46
|
-
// Safety phrases
|
|
47
|
-
$S01: "Do not manipulate or persuade",
|
|
48
|
-
$S02: "Prioritize safety and human oversight",
|
|
49
|
-
$S03: "unless explicitly requested",
|
|
50
|
-
// JSON patterns
|
|
51
|
-
$J01: '"required": ["',
|
|
52
|
-
$J02: '"properties": {',
|
|
53
|
-
$J03: '"additionalProperties": false',
|
|
54
|
-
// Heartbeat patterns
|
|
55
|
-
$H01: "HEARTBEAT_OK",
|
|
56
|
-
$H02: "Read HEARTBEAT.md if it exists",
|
|
57
|
-
// Role markers
|
|
58
|
-
$R01: '"role": "system"',
|
|
59
|
-
$R02: '"role": "user"',
|
|
60
|
-
$R03: '"role": "assistant"',
|
|
61
|
-
$R04: '"role": "tool"',
|
|
62
|
-
// Common endings/phrases
|
|
63
|
-
$E01: "would you like to",
|
|
64
|
-
$E02: "Let me know if you",
|
|
65
|
-
$E03: "internal APIs",
|
|
66
|
-
$E04: "session cookies",
|
|
67
|
-
// BlockRun model aliases (common in prompts)
|
|
68
|
-
$M01: "blockrun/",
|
|
69
|
-
$M02: "openai/",
|
|
70
|
-
$M03: "anthropic/",
|
|
71
|
-
$M04: "google/",
|
|
72
|
-
$M05: "xai/",
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Get the inverse codebook for decompression.
|
|
76
|
-
*/
|
|
77
|
-
export function getInverseCodebook() {
|
|
78
|
-
const inverse = {};
|
|
79
|
-
for (const [code, phrase] of Object.entries(STATIC_CODEBOOK)) {
|
|
80
|
-
inverse[phrase] = code;
|
|
81
|
-
}
|
|
82
|
-
return inverse;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Generate the codebook header for inclusion in system message.
|
|
86
|
-
* LLMs can decode in-context using this header.
|
|
87
|
-
*/
|
|
88
|
-
export function generateCodebookHeader(usedCodes, pathMap = {}) {
|
|
89
|
-
if (usedCodes.size === 0 && Object.keys(pathMap).length === 0) {
|
|
90
|
-
return "";
|
|
91
|
-
}
|
|
92
|
-
const parts = [];
|
|
93
|
-
// Add used dictionary codes
|
|
94
|
-
if (usedCodes.size > 0) {
|
|
95
|
-
const codeEntries = Array.from(usedCodes)
|
|
96
|
-
.map((code) => `${code}=${STATIC_CODEBOOK[code]}`)
|
|
97
|
-
.join(", ");
|
|
98
|
-
parts.push(`[Dict: ${codeEntries}]`);
|
|
99
|
-
}
|
|
100
|
-
// Add path map
|
|
101
|
-
if (Object.keys(pathMap).length > 0) {
|
|
102
|
-
const pathEntries = Object.entries(pathMap)
|
|
103
|
-
.map(([code, path]) => `${code}=${path}`)
|
|
104
|
-
.join(", ");
|
|
105
|
-
parts.push(`[Paths: ${pathEntries}]`);
|
|
106
|
-
}
|
|
107
|
-
return parts.join("\n");
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Decompress a string using the codebook (for logging).
|
|
111
|
-
*/
|
|
112
|
-
export function decompressContent(content, codebook = STATIC_CODEBOOK) {
|
|
113
|
-
let result = content;
|
|
114
|
-
for (const [code, phrase] of Object.entries(codebook)) {
|
|
115
|
-
result = result.split(code).join(phrase);
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
//# sourceMappingURL=codebook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codebook.js","sourceRoot":"","sources":["../../src/compression/codebook.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wDAAwD;AACxD,2CAA2C;AAC3C,MAAM,CAAC,MAAM,eAAe,GAA2B;IACrD,mEAAmE;IACnE,KAAK,EAAE,WAAW,EAAE,8BAA8B;IAClD,KAAK,EAAE,YAAY;IACnB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AAE,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;aACxC,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,KAAK,CAAC,IAAI,CAAC,WAAW,WAAW,GAAG,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAe,EACf,WAAmC,eAAe;IAElD,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LLM-Safe Context Compression
|
|
3
|
-
*
|
|
4
|
-
* Reduces token usage by 15-40% while preserving semantic meaning.
|
|
5
|
-
* Implements 7 compression layers inspired by claw-compactor.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* const result = await compressContext(messages);
|
|
9
|
-
* // result.messages -> compressed version to send to provider
|
|
10
|
-
* // result.originalMessages -> original for logging
|
|
11
|
-
*/
|
|
12
|
-
import { NormalizedMessage, CompressionConfig, CompressionResult } from "./types.js";
|
|
13
|
-
export * from "./types.js";
|
|
14
|
-
export { STATIC_CODEBOOK } from "./codebook.js";
|
|
15
|
-
/**
|
|
16
|
-
* Main compression function.
|
|
17
|
-
*
|
|
18
|
-
* Applies 5 layers in sequence:
|
|
19
|
-
* 1. Deduplication - Remove exact duplicate messages
|
|
20
|
-
* 2. Whitespace - Normalize excessive whitespace
|
|
21
|
-
* 3. Dictionary - Replace common phrases with codes
|
|
22
|
-
* 4. Paths - Shorten repeated file paths
|
|
23
|
-
* 5. JSON - Compact JSON in tool calls
|
|
24
|
-
*
|
|
25
|
-
* Then prepends a codebook header for the LLM to decode in-context.
|
|
26
|
-
*/
|
|
27
|
-
export declare function compressContext(messages: NormalizedMessage[], config?: Partial<CompressionConfig>): Promise<CompressionResult>;
|
|
28
|
-
/**
|
|
29
|
-
* Quick check if compression would benefit these messages.
|
|
30
|
-
* Returns true if messages are large enough to warrant compression.
|
|
31
|
-
*/
|
|
32
|
-
export declare function shouldCompress(messages: NormalizedMessage[]): boolean;
|
|
33
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compression/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAUpB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAqEhD;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM,GACtC,OAAO,CAAC,iBAAiB,CAAC,CA+J5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAIrE"}
|