@routstr/sdk 0.3.6 → 0.3.8
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/client/index.d.mts +4 -4
- package/dist/client/index.d.ts +4 -4
- package/dist/client/index.js +69 -10
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +69 -10
- package/dist/client/index.mjs.map +1 -1
- package/dist/discovery/index.d.mts +2 -2
- package/dist/discovery/index.d.ts +2 -2
- package/dist/discovery/index.js +3 -0
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +3 -0
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/index.d.mts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +81 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -14
- package/dist/index.mjs.map +1 -1
- package/dist/{interfaces-D2FDCLyP.d.ts → interfaces-C-DYd9Jy.d.ts} +1 -1
- package/dist/{interfaces-Bp0Ngmqv.d.mts → interfaces-Csn8Uq04.d.mts} +1 -1
- package/dist/{interfaces-Cqkt41QR.d.mts → interfaces-Cv1k2EUK.d.mts} +1 -1
- package/dist/{interfaces-D9qI1ym6.d.ts → interfaces-iL7CWeG5.d.ts} +1 -1
- package/dist/storage/index.d.mts +6 -6
- package/dist/storage/index.d.ts +6 -6
- package/dist/{store-BFUGGr_v.d.ts → store-58VcEUoA.d.ts} +3 -3
- package/dist/{store-C4FyyOnO.d.mts → store-C6dfj1cc.d.mts} +3 -3
- package/dist/{types-DPQM6tIG.d.mts → types-_21yYFZG.d.mts} +1 -1
- package/dist/{types-DPQM6tIG.d.ts → types-_21yYFZG.d.ts} +1 -1
- package/dist/wallet/index.d.mts +4 -4
- package/dist/wallet/index.d.ts +4 -4
- package/dist/wallet/index.js +55 -8
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +55 -8
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { k as ProviderInfo, e as Model, M as Message, n as TransactionHistory } from './types-_21yYFZG.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Interfaces for the Routstr SDK wallet abstraction layer
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { k as ProviderInfo, e as Model, M as Message, n as TransactionHistory } from './types-_21yYFZG.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Interfaces for the Routstr SDK wallet abstraction layer
|
package/dist/storage/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as StorageDriver, U as UsageTrackingDriver, b as UsageTrackingEntry, S as SdkStore } from '../store-
|
|
2
|
-
export { L as ListUsageTrackingOptions, c as createDiscoveryAdapterFromStore, d as createProviderRegistryFromStore, e as createSdkStore, f as createStorageAdapterFromStore } from '../store-
|
|
3
|
-
import { S as SdkLogger } from '../types-
|
|
4
|
-
import { D as DiscoveryAdapter } from '../interfaces-
|
|
5
|
-
import { P as ProviderRegistry, S as StorageAdapter } from '../interfaces-
|
|
6
|
-
export { X as XCashuTokenEntry } from '../interfaces-
|
|
1
|
+
import { a as StorageDriver, U as UsageTrackingDriver, b as UsageTrackingEntry, S as SdkStore } from '../store-C6dfj1cc.mjs';
|
|
2
|
+
export { L as ListUsageTrackingOptions, c as createDiscoveryAdapterFromStore, d as createProviderRegistryFromStore, e as createSdkStore, f as createStorageAdapterFromStore } from '../store-C6dfj1cc.mjs';
|
|
3
|
+
import { S as SdkLogger } from '../types-_21yYFZG.mjs';
|
|
4
|
+
import { D as DiscoveryAdapter } from '../interfaces-Cv1k2EUK.mjs';
|
|
5
|
+
import { P as ProviderRegistry, S as StorageAdapter } from '../interfaces-Csn8Uq04.mjs';
|
|
6
|
+
export { X as XCashuTokenEntry } from '../interfaces-Csn8Uq04.mjs';
|
|
7
7
|
import 'zustand/vanilla';
|
|
8
8
|
|
|
9
9
|
interface IndexedDBUsageTrackingDriverOptions {
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as StorageDriver, U as UsageTrackingDriver, b as UsageTrackingEntry, S as SdkStore } from '../store-
|
|
2
|
-
export { L as ListUsageTrackingOptions, c as createDiscoveryAdapterFromStore, d as createProviderRegistryFromStore, e as createSdkStore, f as createStorageAdapterFromStore } from '../store-
|
|
3
|
-
import { S as SdkLogger } from '../types-
|
|
4
|
-
import { D as DiscoveryAdapter } from '../interfaces-
|
|
5
|
-
import { P as ProviderRegistry, S as StorageAdapter } from '../interfaces-
|
|
6
|
-
export { X as XCashuTokenEntry } from '../interfaces-
|
|
1
|
+
import { a as StorageDriver, U as UsageTrackingDriver, b as UsageTrackingEntry, S as SdkStore } from '../store-58VcEUoA.js';
|
|
2
|
+
export { L as ListUsageTrackingOptions, c as createDiscoveryAdapterFromStore, d as createProviderRegistryFromStore, e as createSdkStore, f as createStorageAdapterFromStore } from '../store-58VcEUoA.js';
|
|
3
|
+
import { S as SdkLogger } from '../types-_21yYFZG.js';
|
|
4
|
+
import { D as DiscoveryAdapter } from '../interfaces-iL7CWeG5.js';
|
|
5
|
+
import { P as ProviderRegistry, S as StorageAdapter } from '../interfaces-C-DYd9Jy.js';
|
|
6
|
+
export { X as XCashuTokenEntry } from '../interfaces-C-DYd9Jy.js';
|
|
7
7
|
import 'zustand/vanilla';
|
|
8
8
|
|
|
9
9
|
interface IndexedDBUsageTrackingDriverOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StoreApi } from 'zustand/vanilla';
|
|
2
|
-
import { D as DiscoveryAdapter } from './interfaces-
|
|
3
|
-
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-
|
|
4
|
-
import {
|
|
2
|
+
import { D as DiscoveryAdapter } from './interfaces-iL7CWeG5.js';
|
|
3
|
+
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-C-DYd9Jy.js';
|
|
4
|
+
import { e as Model, k as ProviderInfo, S as SdkLogger } from './types-_21yYFZG.js';
|
|
5
5
|
|
|
6
6
|
interface UsageTrackingEntry {
|
|
7
7
|
id: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StoreApi } from 'zustand/vanilla';
|
|
2
|
-
import { D as DiscoveryAdapter } from './interfaces-
|
|
3
|
-
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-
|
|
4
|
-
import {
|
|
2
|
+
import { D as DiscoveryAdapter } from './interfaces-Cv1k2EUK.mjs';
|
|
3
|
+
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-Csn8Uq04.mjs';
|
|
4
|
+
import { e as Model, k as ProviderInfo, S as SdkLogger } from './types-_21yYFZG.mjs';
|
|
5
5
|
|
|
6
6
|
interface UsageTrackingEntry {
|
|
7
7
|
id: string;
|
|
@@ -231,4 +231,4 @@ interface MintDiscoveryResult {
|
|
|
231
231
|
infoFromProviders: Record<string, ProviderInfo>;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
export { type APIErrorVerdict as A, type CandidateProvider as C, type FetchAIResponseParams as F, type ImageData as I, type
|
|
234
|
+
export { type APIErrorVerdict as A, type CandidateProvider as C, type FetchAIResponseParams as F, type ImageData as I, type Message as M, type PendingTokenEntry as P, type RefundResult as R, type SdkLogger as S, type TopUpResult as T, type UsageStats as U, type AnnotationData as a, type MessageContentType as b, type MintDiscoveryResult as c, type MintSelection as d, type Model as e, type ModelArchitecture as f, type ModelDiscoveryResult as g, type ModelPricing as h, type ModelSatsPricing as i, type PerRequestLimits as j, type ProviderInfo as k, type SpendResult as l, type StreamingResult as m, type TransactionHistory as n, consoleLogger as o, noopLogger as p };
|
|
@@ -231,4 +231,4 @@ interface MintDiscoveryResult {
|
|
|
231
231
|
infoFromProviders: Record<string, ProviderInfo>;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
export { type APIErrorVerdict as A, type CandidateProvider as C, type FetchAIResponseParams as F, type ImageData as I, type
|
|
234
|
+
export { type APIErrorVerdict as A, type CandidateProvider as C, type FetchAIResponseParams as F, type ImageData as I, type Message as M, type PendingTokenEntry as P, type RefundResult as R, type SdkLogger as S, type TopUpResult as T, type UsageStats as U, type AnnotationData as a, type MessageContentType as b, type MintDiscoveryResult as c, type MintSelection as d, type Model as e, type ModelArchitecture as f, type ModelDiscoveryResult as g, type ModelPricing as h, type ModelSatsPricing as i, type PerRequestLimits as j, type ProviderInfo as k, type SpendResult as l, type StreamingResult as m, type TransactionHistory as n, consoleLogger as o, noopLogger as p };
|
package/dist/wallet/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-
|
|
2
|
-
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-
|
|
3
|
-
import { S as SdkLogger, R as RefundResult,
|
|
4
|
-
export {
|
|
1
|
+
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-Csn8Uq04.mjs';
|
|
2
|
+
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-Csn8Uq04.mjs';
|
|
3
|
+
import { S as SdkLogger, R as RefundResult, T as TopUpResult, l as SpendResult } from '../types-_21yYFZG.mjs';
|
|
4
|
+
export { k as ProviderInfo } from '../types-_21yYFZG.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* BalanceManager - Handles refunding and topping up tokens from providers
|
package/dist/wallet/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-
|
|
2
|
-
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-
|
|
3
|
-
import { S as SdkLogger, R as RefundResult,
|
|
4
|
-
export {
|
|
1
|
+
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-C-DYd9Jy.js';
|
|
2
|
+
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-C-DYd9Jy.js';
|
|
3
|
+
import { S as SdkLogger, R as RefundResult, T as TopUpResult, l as SpendResult } from '../types-_21yYFZG.js';
|
|
4
|
+
export { k as ProviderInfo } from '../types-_21yYFZG.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* BalanceManager - Handles refunding and topping up tokens from providers
|
package/dist/wallet/index.js
CHANGED
|
@@ -27,6 +27,10 @@ var InsufficientBalanceError = class extends Error {
|
|
|
27
27
|
this.maxMintUrl = maxMintUrl;
|
|
28
28
|
this.name = "InsufficientBalanceError";
|
|
29
29
|
}
|
|
30
|
+
required;
|
|
31
|
+
available;
|
|
32
|
+
maxMintBalance;
|
|
33
|
+
maxMintUrl;
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
// wallet/AuditLogger.ts
|
|
@@ -100,6 +104,10 @@ var CashuSpender = class {
|
|
|
100
104
|
this.balanceManager = balanceManager;
|
|
101
105
|
this.logger = (logger ?? consoleLogger).child("CashuSpender");
|
|
102
106
|
}
|
|
107
|
+
walletAdapter;
|
|
108
|
+
storageAdapter;
|
|
109
|
+
_providerRegistry;
|
|
110
|
+
balanceManager;
|
|
103
111
|
_isBusy = false;
|
|
104
112
|
debugLevel = "WARN";
|
|
105
113
|
logger;
|
|
@@ -558,6 +566,9 @@ var CashuSpender = class {
|
|
|
558
566
|
apiKeyEntry.baseUrl
|
|
559
567
|
);
|
|
560
568
|
if (balanceResult.isInvalidApiKey) {
|
|
569
|
+
this.logger.warn(
|
|
570
|
+
`refundProviders: ${apiKeyEntry.baseUrl} returned invalid API key; removing local key and treating as success`
|
|
571
|
+
);
|
|
561
572
|
this.storageAdapter.removeApiKey(apiKeyEntry.baseUrl);
|
|
562
573
|
results.push({
|
|
563
574
|
baseUrl: apiKeyEntry.baseUrl,
|
|
@@ -571,13 +582,23 @@ var CashuSpender = class {
|
|
|
571
582
|
apiKeyEntry.baseUrl,
|
|
572
583
|
balanceSat
|
|
573
584
|
);
|
|
585
|
+
} else {
|
|
586
|
+
this.logger.warn(
|
|
587
|
+
`refundProviders: balance refresh for ${apiKeyEntry.baseUrl} returned negative amount; keeping stale local balance=${apiKeyEntryFull.balance}`
|
|
588
|
+
);
|
|
574
589
|
}
|
|
575
|
-
} catch {
|
|
590
|
+
} catch (error) {
|
|
591
|
+
this.logger.warn(
|
|
592
|
+
`refundProviders: balance refresh threw for ${apiKeyEntry.baseUrl}; proceeding with stale local balance`,
|
|
593
|
+
error
|
|
594
|
+
);
|
|
576
595
|
}
|
|
577
596
|
const refreshedEntry = this.storageAdapter.getApiKey(
|
|
578
597
|
apiKeyEntry.baseUrl
|
|
579
598
|
);
|
|
580
|
-
if (!refreshedEntry)
|
|
599
|
+
if (!refreshedEntry) {
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
581
602
|
const refundResult = await this.balanceManager.refundApiKey({
|
|
582
603
|
mintUrl,
|
|
583
604
|
baseUrl: apiKeyEntry.baseUrl,
|
|
@@ -590,6 +611,9 @@ var CashuSpender = class {
|
|
|
590
611
|
const currentEntry = this.storageAdapter.getApiKey(
|
|
591
612
|
apiKeyEntry.baseUrl
|
|
592
613
|
);
|
|
614
|
+
this.logger.warn(
|
|
615
|
+
`refundProviders: refund failed for ${apiKeyEntry.baseUrl}; currentEntry=${Boolean(currentEntry)} balance=${currentEntry?.balance ?? "none"}. Touching lastUsed to rate-limit retries.`
|
|
616
|
+
);
|
|
593
617
|
if (currentEntry) {
|
|
594
618
|
this.storageAdapter.updateApiKeyBalance(
|
|
595
619
|
apiKeyEntry.baseUrl,
|
|
@@ -602,6 +626,9 @@ var CashuSpender = class {
|
|
|
602
626
|
success: refundResult.success
|
|
603
627
|
});
|
|
604
628
|
} else {
|
|
629
|
+
this.logger.warn(
|
|
630
|
+
`refundProviders: cannot refund ${apiKeyEntry.baseUrl}; apiKeyEntryFull=${Boolean(apiKeyEntryFull)} balanceManager=${Boolean(this.balanceManager)}`
|
|
631
|
+
);
|
|
605
632
|
results.push({
|
|
606
633
|
baseUrl: apiKeyEntry.baseUrl,
|
|
607
634
|
success: false
|
|
@@ -674,10 +701,14 @@ var BalanceManager = class _BalanceManager {
|
|
|
674
701
|
walletAdapter,
|
|
675
702
|
storageAdapter,
|
|
676
703
|
providerRegistry,
|
|
677
|
-
this
|
|
704
|
+
this,
|
|
705
|
+
this.logger
|
|
678
706
|
);
|
|
679
707
|
}
|
|
680
708
|
}
|
|
709
|
+
walletAdapter;
|
|
710
|
+
storageAdapter;
|
|
711
|
+
providerRegistry;
|
|
681
712
|
cashuSpender;
|
|
682
713
|
/** In-memory guard for per-provider wallet mutations (topup / refund) */
|
|
683
714
|
providerWalletOps = /* @__PURE__ */ new Map();
|
|
@@ -771,6 +802,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
771
802
|
async _refundApiKeyImpl(options) {
|
|
772
803
|
const { mintUrl, baseUrl, apiKey, forceRefund } = options;
|
|
773
804
|
if (!apiKey) {
|
|
805
|
+
this.logger.warn(`refundApiKey: aborting for ${baseUrl} - no API key`);
|
|
774
806
|
return { success: false, message: "No API key to refund" };
|
|
775
807
|
}
|
|
776
808
|
if (!forceRefund) {
|
|
@@ -778,7 +810,9 @@ var BalanceManager = class _BalanceManager {
|
|
|
778
810
|
if (apiKeyEntry?.lastUsed) {
|
|
779
811
|
const fiveMinutesAgo = Date.now() - 5 * 60 * 1e3;
|
|
780
812
|
if (apiKeyEntry.lastUsed > fiveMinutesAgo) {
|
|
781
|
-
this.logger.log(
|
|
813
|
+
this.logger.log(
|
|
814
|
+
`refundApiKey: skipping ${baseUrl} - used ${Math.round((Date.now() - apiKeyEntry.lastUsed) / 1e3)}s ago`
|
|
815
|
+
);
|
|
782
816
|
return {
|
|
783
817
|
success: false,
|
|
784
818
|
message: "API key was used recently, skipping refund"
|
|
@@ -789,7 +823,15 @@ var BalanceManager = class _BalanceManager {
|
|
|
789
823
|
let fetchResult;
|
|
790
824
|
try {
|
|
791
825
|
fetchResult = await this.fetchRefundToken(baseUrl, apiKey);
|
|
826
|
+
if (fetchResult.error === "No balance to refund") {
|
|
827
|
+
this.logger.log(`refundApiKey: provider says no balance for ${baseUrl}; removing API key`);
|
|
828
|
+
this.storageAdapter.removeApiKey(baseUrl);
|
|
829
|
+
return { success: true, message: "No balance to refund, key cleaned up" };
|
|
830
|
+
}
|
|
792
831
|
if (!fetchResult.success) {
|
|
832
|
+
this.logger.warn(
|
|
833
|
+
`refundApiKey: fetch failed for ${baseUrl}: ${fetchResult.error || "API key refund failed"}`
|
|
834
|
+
);
|
|
793
835
|
return {
|
|
794
836
|
success: false,
|
|
795
837
|
message: fetchResult.error || "API key refund failed",
|
|
@@ -797,22 +839,23 @@ var BalanceManager = class _BalanceManager {
|
|
|
797
839
|
};
|
|
798
840
|
}
|
|
799
841
|
if (!fetchResult.token) {
|
|
842
|
+
this.logger.warn(`refundApiKey: no token received for ${baseUrl}`);
|
|
800
843
|
return {
|
|
801
844
|
success: false,
|
|
802
845
|
message: "No token received from API key refund",
|
|
803
846
|
requestId: fetchResult.requestId
|
|
804
847
|
};
|
|
805
848
|
}
|
|
806
|
-
if (fetchResult.error === "No balance to refund") {
|
|
807
|
-
this.storageAdapter.removeApiKey(baseUrl);
|
|
808
|
-
return { success: true, message: "No balance to refund, key cleaned up" };
|
|
809
|
-
}
|
|
810
849
|
const receiveResult = await this.cashuSpender.receiveToken(
|
|
811
850
|
fetchResult.token
|
|
812
851
|
);
|
|
813
852
|
const totalAmountMsat = receiveResult.unit === "msat" ? receiveResult.amount : receiveResult.amount * 1e3;
|
|
814
853
|
if (receiveResult.success) {
|
|
815
854
|
this.storageAdapter.removeApiKey(baseUrl);
|
|
855
|
+
} else {
|
|
856
|
+
this.logger.warn(
|
|
857
|
+
`refundApiKey: receive failed for ${baseUrl}; keeping API key. message=${receiveResult.message ?? "none"}`
|
|
858
|
+
);
|
|
816
859
|
}
|
|
817
860
|
return {
|
|
818
861
|
success: receiveResult.success,
|
|
@@ -859,6 +902,10 @@ var BalanceManager = class _BalanceManager {
|
|
|
859
902
|
const requestId = response.headers.get("x-routstr-request-id") || void 0;
|
|
860
903
|
if (!response.ok) {
|
|
861
904
|
const errorData = await response.json().catch(() => ({}));
|
|
905
|
+
this.logger.warn(
|
|
906
|
+
`fetchRefundToken: non-ok response for ${url} status=${response.status} statusText=${response.statusText}`,
|
|
907
|
+
errorData
|
|
908
|
+
);
|
|
862
909
|
return {
|
|
863
910
|
success: false,
|
|
864
911
|
requestId,
|