@routstr/sdk 0.1.0 → 0.1.2
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 +293 -0
- package/dist/client/index.d.ts +293 -0
- package/dist/client/index.js +2663 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +2659 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/discovery/index.d.mts +186 -0
- package/dist/discovery/index.d.ts +186 -0
- package/dist/discovery/index.js +581 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/index.mjs +578 -0
- package/dist/discovery/index.mjs.map +1 -0
- package/dist/index.d.mts +28 -4777
- package/dist/index.d.ts +28 -4777
- package/dist/index.js +1450 -681
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1447 -682
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces-B85Wx7ni.d.mts +171 -0
- package/dist/interfaces-BVNyAmKu.d.ts +171 -0
- package/dist/interfaces-Dnrvxr6N.d.ts +102 -0
- package/dist/interfaces-nanJOqdW.d.mts +102 -0
- package/dist/storage/index.d.mts +134 -0
- package/dist/storage/index.d.ts +134 -0
- package/dist/storage/index.js +861 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.mjs +846 -0
- package/dist/storage/index.mjs.map +1 -0
- package/dist/types-BlHjmWRK.d.mts +222 -0
- package/dist/types-BlHjmWRK.d.ts +222 -0
- package/dist/wallet/index.d.mts +218 -0
- package/dist/wallet/index.d.ts +218 -0
- package/dist/wallet/index.js +1204 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/index.mjs +1201 -0
- package/dist/wallet/index.mjs.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { P as ProviderInfo, M as Model, a as Message, T as TransactionHistory } from './types-BlHjmWRK.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interfaces for the Routstr SDK wallet abstraction layer
|
|
5
|
+
* These interfaces allow the SDK to be framework-agnostic
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* WalletAdapter - Abstracts wallet operations (NIP-60 or legacy)
|
|
10
|
+
* The React app implements this using its hooks
|
|
11
|
+
*/
|
|
12
|
+
interface WalletAdapter {
|
|
13
|
+
/** Get balances for all mints (mintUrl -> balance in sats) */
|
|
14
|
+
getBalances(): Promise<Record<string, number>>;
|
|
15
|
+
/** Get unit type for each mint (mintUrl -> 'sat' | 'msat') */
|
|
16
|
+
getMintUnits(): Record<string, "sat" | "msat">;
|
|
17
|
+
/** Get the currently active mint URL */
|
|
18
|
+
getActiveMintUrl(): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Create and send a cashu token from a mint
|
|
21
|
+
* @param mintUrl The mint URL to send from
|
|
22
|
+
* @param amount Amount in sats
|
|
23
|
+
* @param p2pkPubkey Optional P2PK public key
|
|
24
|
+
* @returns Encoded cashu token string
|
|
25
|
+
*/
|
|
26
|
+
sendToken(mintUrl: string, amount: number, p2pkPubkey?: string): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Receive/store a cashu token
|
|
29
|
+
* Handles both NIP-60 and legacy storage internally
|
|
30
|
+
* @param token Encoded cashu token string
|
|
31
|
+
* @returns Result with success flag and amount received
|
|
32
|
+
*/
|
|
33
|
+
receiveToken(token: string): Promise<{
|
|
34
|
+
success: boolean;
|
|
35
|
+
amount: number;
|
|
36
|
+
unit: "sat" | "msat";
|
|
37
|
+
message?: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* StorageAdapter - Abstracts local storage operations
|
|
42
|
+
* Separates token storage from wallet operations
|
|
43
|
+
*/
|
|
44
|
+
interface ApiKeyEntry {
|
|
45
|
+
baseUrl: string;
|
|
46
|
+
key: string;
|
|
47
|
+
balance: number;
|
|
48
|
+
lastUsed: number | null;
|
|
49
|
+
}
|
|
50
|
+
interface ChildKeyEntry {
|
|
51
|
+
parentBaseUrl: string;
|
|
52
|
+
childKey: string;
|
|
53
|
+
balance: number;
|
|
54
|
+
balanceLimit?: number;
|
|
55
|
+
validityDate?: number;
|
|
56
|
+
createdAt: number;
|
|
57
|
+
}
|
|
58
|
+
interface StorageAdapter {
|
|
59
|
+
/** Get stored API token for a provider */
|
|
60
|
+
getToken(baseUrl: string): string | null;
|
|
61
|
+
/** Store API token for a provider */
|
|
62
|
+
setToken(baseUrl: string, token: string): void;
|
|
63
|
+
/** Remove API token for a provider */
|
|
64
|
+
removeToken(baseUrl: string): void;
|
|
65
|
+
/** Update balance for an existing stored token */
|
|
66
|
+
updateTokenBalance(baseUrl: string, balance: number): void;
|
|
67
|
+
/** Get all stored tokens as distribution (baseUrl -> amount in sats) */
|
|
68
|
+
getCachedTokenDistribution(): Array<{
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
amount: number;
|
|
71
|
+
}>;
|
|
72
|
+
/** Save provider info to cache */
|
|
73
|
+
saveProviderInfo(baseUrl: string, info: ProviderInfo): void;
|
|
74
|
+
/** Get cached provider info */
|
|
75
|
+
getProviderInfo(baseUrl: string): ProviderInfo | null;
|
|
76
|
+
/** Get stored API key entry for a provider */
|
|
77
|
+
getApiKey(baseUrl: string): ApiKeyEntry | null;
|
|
78
|
+
/** Store API key for a provider */
|
|
79
|
+
setApiKey(baseUrl: string, key: string): void;
|
|
80
|
+
/** Update balance for an existing stored API key (based on provider response) */
|
|
81
|
+
updateApiKeyBalance(baseUrl: string, balance: number): void;
|
|
82
|
+
/** Remove API key for a provider */
|
|
83
|
+
removeApiKey(baseUrl: string): void;
|
|
84
|
+
/** Get all stored API keys */
|
|
85
|
+
getAllApiKeys(): ApiKeyEntry[];
|
|
86
|
+
/** Get all stored API keys as distribution (baseUrl -> amount in sats) */
|
|
87
|
+
getApiKeyDistribution(): Array<{
|
|
88
|
+
baseUrl: string;
|
|
89
|
+
amount: number;
|
|
90
|
+
}>;
|
|
91
|
+
/** Get stored child key for a parent provider */
|
|
92
|
+
getChildKey(parentBaseUrl: string): ChildKeyEntry | null;
|
|
93
|
+
/** Store a child key for a parent provider */
|
|
94
|
+
setChildKey(parentBaseUrl: string, childKey: string, balance?: number, validityDate?: number, balanceLimit?: number): void;
|
|
95
|
+
/** Update balance for an existing child key */
|
|
96
|
+
updateChildKeyBalance(parentBaseUrl: string, balance: number): void;
|
|
97
|
+
/** Remove child key for a parent provider */
|
|
98
|
+
removeChildKey(parentBaseUrl: string): void;
|
|
99
|
+
/** Get all stored child keys */
|
|
100
|
+
getAllChildKeys(): ChildKeyEntry[];
|
|
101
|
+
/** Get cached receive tokens (tokens that failed to receive due to mint errors) */
|
|
102
|
+
getCachedReceiveTokens(): Array<{
|
|
103
|
+
token: string;
|
|
104
|
+
amount: number;
|
|
105
|
+
unit: "sat" | "msat";
|
|
106
|
+
createdAt: number;
|
|
107
|
+
}>;
|
|
108
|
+
/** Set cached receive tokens */
|
|
109
|
+
setCachedReceiveTokens(tokens: Array<{
|
|
110
|
+
token: string;
|
|
111
|
+
amount: number;
|
|
112
|
+
unit: "sat" | "msat";
|
|
113
|
+
createdAt?: number;
|
|
114
|
+
}>): void;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* ProviderRegistry - Provides access to provider/model data
|
|
118
|
+
* Used by ProviderManager for failover logic
|
|
119
|
+
*/
|
|
120
|
+
interface ProviderRegistry {
|
|
121
|
+
/** Get all models available from a provider */
|
|
122
|
+
getModelsForProvider(baseUrl: string): Model[];
|
|
123
|
+
/** Get list of disabled provider URLs */
|
|
124
|
+
getDisabledProviders(): string[];
|
|
125
|
+
/** Get mints accepted by a provider */
|
|
126
|
+
getProviderMints(baseUrl: string): string[];
|
|
127
|
+
/**
|
|
128
|
+
* Get provider info (version, etc.)
|
|
129
|
+
* Should fetch from network if not cached, or return cached version
|
|
130
|
+
*/
|
|
131
|
+
getProviderInfo(baseUrl: string): Promise<ProviderInfo | null>;
|
|
132
|
+
/** Get all providers with their models */
|
|
133
|
+
getAllProvidersModels(): Record<string, Model[]>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* StreamingCallbacks - Callbacks for real-time updates during API calls
|
|
137
|
+
* Used by RoutstrClient to communicate with the UI
|
|
138
|
+
*/
|
|
139
|
+
interface StreamingCallbacks {
|
|
140
|
+
/** Called when new content arrives from the stream */
|
|
141
|
+
onStreamingUpdate: (content: string) => void;
|
|
142
|
+
/** Called when thinking/reasoning content arrives */
|
|
143
|
+
onThinkingUpdate: (content: string) => void;
|
|
144
|
+
/** Called when a complete message should be appended */
|
|
145
|
+
onMessageAppend: (message: Message) => void;
|
|
146
|
+
/** Called when balance changes */
|
|
147
|
+
onBalanceUpdate: (balance: number) => void;
|
|
148
|
+
/** Called when a transaction is recorded */
|
|
149
|
+
onTransactionUpdate: (transaction: TransactionHistory) => void;
|
|
150
|
+
/** Called when a new token is created (amount in sats) */
|
|
151
|
+
onTokenCreated?: (amount: number) => void;
|
|
152
|
+
/** Called when payment processing starts/stops */
|
|
153
|
+
onPaymentProcessing?: (isProcessing: boolean) => void;
|
|
154
|
+
/** Called when sats spent on the last message is known */
|
|
155
|
+
onLastMessageSatsUpdate?: (satsSpent: number, estimatedCosts: number) => void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Options for creating a RoutstrClient
|
|
159
|
+
*/
|
|
160
|
+
interface RoutstrClientOptions {
|
|
161
|
+
/** Wallet adapter for cashu operations */
|
|
162
|
+
walletAdapter: WalletAdapter;
|
|
163
|
+
/** Storage adapter for token management */
|
|
164
|
+
storageAdapter: StorageAdapter;
|
|
165
|
+
/** Provider registry for failover logic */
|
|
166
|
+
providerRegistry: ProviderRegistry;
|
|
167
|
+
/** Nostr relay URLs (for future nostr-based features) */
|
|
168
|
+
relayUrls?: string[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type { ApiKeyEntry as A, ChildKeyEntry as C, ProviderRegistry as P, RoutstrClientOptions as R, StorageAdapter as S, WalletAdapter as W, StreamingCallbacks as a };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { P as ProviderInfo, M as Model, a as Message, T as TransactionHistory } from './types-BlHjmWRK.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interfaces for the Routstr SDK wallet abstraction layer
|
|
5
|
+
* These interfaces allow the SDK to be framework-agnostic
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* WalletAdapter - Abstracts wallet operations (NIP-60 or legacy)
|
|
10
|
+
* The React app implements this using its hooks
|
|
11
|
+
*/
|
|
12
|
+
interface WalletAdapter {
|
|
13
|
+
/** Get balances for all mints (mintUrl -> balance in sats) */
|
|
14
|
+
getBalances(): Promise<Record<string, number>>;
|
|
15
|
+
/** Get unit type for each mint (mintUrl -> 'sat' | 'msat') */
|
|
16
|
+
getMintUnits(): Record<string, "sat" | "msat">;
|
|
17
|
+
/** Get the currently active mint URL */
|
|
18
|
+
getActiveMintUrl(): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Create and send a cashu token from a mint
|
|
21
|
+
* @param mintUrl The mint URL to send from
|
|
22
|
+
* @param amount Amount in sats
|
|
23
|
+
* @param p2pkPubkey Optional P2PK public key
|
|
24
|
+
* @returns Encoded cashu token string
|
|
25
|
+
*/
|
|
26
|
+
sendToken(mintUrl: string, amount: number, p2pkPubkey?: string): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Receive/store a cashu token
|
|
29
|
+
* Handles both NIP-60 and legacy storage internally
|
|
30
|
+
* @param token Encoded cashu token string
|
|
31
|
+
* @returns Result with success flag and amount received
|
|
32
|
+
*/
|
|
33
|
+
receiveToken(token: string): Promise<{
|
|
34
|
+
success: boolean;
|
|
35
|
+
amount: number;
|
|
36
|
+
unit: "sat" | "msat";
|
|
37
|
+
message?: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* StorageAdapter - Abstracts local storage operations
|
|
42
|
+
* Separates token storage from wallet operations
|
|
43
|
+
*/
|
|
44
|
+
interface ApiKeyEntry {
|
|
45
|
+
baseUrl: string;
|
|
46
|
+
key: string;
|
|
47
|
+
balance: number;
|
|
48
|
+
lastUsed: number | null;
|
|
49
|
+
}
|
|
50
|
+
interface ChildKeyEntry {
|
|
51
|
+
parentBaseUrl: string;
|
|
52
|
+
childKey: string;
|
|
53
|
+
balance: number;
|
|
54
|
+
balanceLimit?: number;
|
|
55
|
+
validityDate?: number;
|
|
56
|
+
createdAt: number;
|
|
57
|
+
}
|
|
58
|
+
interface StorageAdapter {
|
|
59
|
+
/** Get stored API token for a provider */
|
|
60
|
+
getToken(baseUrl: string): string | null;
|
|
61
|
+
/** Store API token for a provider */
|
|
62
|
+
setToken(baseUrl: string, token: string): void;
|
|
63
|
+
/** Remove API token for a provider */
|
|
64
|
+
removeToken(baseUrl: string): void;
|
|
65
|
+
/** Update balance for an existing stored token */
|
|
66
|
+
updateTokenBalance(baseUrl: string, balance: number): void;
|
|
67
|
+
/** Get all stored tokens as distribution (baseUrl -> amount in sats) */
|
|
68
|
+
getCachedTokenDistribution(): Array<{
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
amount: number;
|
|
71
|
+
}>;
|
|
72
|
+
/** Save provider info to cache */
|
|
73
|
+
saveProviderInfo(baseUrl: string, info: ProviderInfo): void;
|
|
74
|
+
/** Get cached provider info */
|
|
75
|
+
getProviderInfo(baseUrl: string): ProviderInfo | null;
|
|
76
|
+
/** Get stored API key entry for a provider */
|
|
77
|
+
getApiKey(baseUrl: string): ApiKeyEntry | null;
|
|
78
|
+
/** Store API key for a provider */
|
|
79
|
+
setApiKey(baseUrl: string, key: string): void;
|
|
80
|
+
/** Update balance for an existing stored API key (based on provider response) */
|
|
81
|
+
updateApiKeyBalance(baseUrl: string, balance: number): void;
|
|
82
|
+
/** Remove API key for a provider */
|
|
83
|
+
removeApiKey(baseUrl: string): void;
|
|
84
|
+
/** Get all stored API keys */
|
|
85
|
+
getAllApiKeys(): ApiKeyEntry[];
|
|
86
|
+
/** Get all stored API keys as distribution (baseUrl -> amount in sats) */
|
|
87
|
+
getApiKeyDistribution(): Array<{
|
|
88
|
+
baseUrl: string;
|
|
89
|
+
amount: number;
|
|
90
|
+
}>;
|
|
91
|
+
/** Get stored child key for a parent provider */
|
|
92
|
+
getChildKey(parentBaseUrl: string): ChildKeyEntry | null;
|
|
93
|
+
/** Store a child key for a parent provider */
|
|
94
|
+
setChildKey(parentBaseUrl: string, childKey: string, balance?: number, validityDate?: number, balanceLimit?: number): void;
|
|
95
|
+
/** Update balance for an existing child key */
|
|
96
|
+
updateChildKeyBalance(parentBaseUrl: string, balance: number): void;
|
|
97
|
+
/** Remove child key for a parent provider */
|
|
98
|
+
removeChildKey(parentBaseUrl: string): void;
|
|
99
|
+
/** Get all stored child keys */
|
|
100
|
+
getAllChildKeys(): ChildKeyEntry[];
|
|
101
|
+
/** Get cached receive tokens (tokens that failed to receive due to mint errors) */
|
|
102
|
+
getCachedReceiveTokens(): Array<{
|
|
103
|
+
token: string;
|
|
104
|
+
amount: number;
|
|
105
|
+
unit: "sat" | "msat";
|
|
106
|
+
createdAt: number;
|
|
107
|
+
}>;
|
|
108
|
+
/** Set cached receive tokens */
|
|
109
|
+
setCachedReceiveTokens(tokens: Array<{
|
|
110
|
+
token: string;
|
|
111
|
+
amount: number;
|
|
112
|
+
unit: "sat" | "msat";
|
|
113
|
+
createdAt?: number;
|
|
114
|
+
}>): void;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* ProviderRegistry - Provides access to provider/model data
|
|
118
|
+
* Used by ProviderManager for failover logic
|
|
119
|
+
*/
|
|
120
|
+
interface ProviderRegistry {
|
|
121
|
+
/** Get all models available from a provider */
|
|
122
|
+
getModelsForProvider(baseUrl: string): Model[];
|
|
123
|
+
/** Get list of disabled provider URLs */
|
|
124
|
+
getDisabledProviders(): string[];
|
|
125
|
+
/** Get mints accepted by a provider */
|
|
126
|
+
getProviderMints(baseUrl: string): string[];
|
|
127
|
+
/**
|
|
128
|
+
* Get provider info (version, etc.)
|
|
129
|
+
* Should fetch from network if not cached, or return cached version
|
|
130
|
+
*/
|
|
131
|
+
getProviderInfo(baseUrl: string): Promise<ProviderInfo | null>;
|
|
132
|
+
/** Get all providers with their models */
|
|
133
|
+
getAllProvidersModels(): Record<string, Model[]>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* StreamingCallbacks - Callbacks for real-time updates during API calls
|
|
137
|
+
* Used by RoutstrClient to communicate with the UI
|
|
138
|
+
*/
|
|
139
|
+
interface StreamingCallbacks {
|
|
140
|
+
/** Called when new content arrives from the stream */
|
|
141
|
+
onStreamingUpdate: (content: string) => void;
|
|
142
|
+
/** Called when thinking/reasoning content arrives */
|
|
143
|
+
onThinkingUpdate: (content: string) => void;
|
|
144
|
+
/** Called when a complete message should be appended */
|
|
145
|
+
onMessageAppend: (message: Message) => void;
|
|
146
|
+
/** Called when balance changes */
|
|
147
|
+
onBalanceUpdate: (balance: number) => void;
|
|
148
|
+
/** Called when a transaction is recorded */
|
|
149
|
+
onTransactionUpdate: (transaction: TransactionHistory) => void;
|
|
150
|
+
/** Called when a new token is created (amount in sats) */
|
|
151
|
+
onTokenCreated?: (amount: number) => void;
|
|
152
|
+
/** Called when payment processing starts/stops */
|
|
153
|
+
onPaymentProcessing?: (isProcessing: boolean) => void;
|
|
154
|
+
/** Called when sats spent on the last message is known */
|
|
155
|
+
onLastMessageSatsUpdate?: (satsSpent: number, estimatedCosts: number) => void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Options for creating a RoutstrClient
|
|
159
|
+
*/
|
|
160
|
+
interface RoutstrClientOptions {
|
|
161
|
+
/** Wallet adapter for cashu operations */
|
|
162
|
+
walletAdapter: WalletAdapter;
|
|
163
|
+
/** Storage adapter for token management */
|
|
164
|
+
storageAdapter: StorageAdapter;
|
|
165
|
+
/** Provider registry for failover logic */
|
|
166
|
+
providerRegistry: ProviderRegistry;
|
|
167
|
+
/** Nostr relay URLs (for future nostr-based features) */
|
|
168
|
+
relayUrls?: string[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type { ApiKeyEntry as A, ChildKeyEntry as C, ProviderRegistry as P, RoutstrClientOptions as R, StorageAdapter as S, WalletAdapter as W, StreamingCallbacks as a };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { M as Model, P as ProviderInfo } from './types-BlHjmWRK.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interfaces for the model and provider discovery system
|
|
5
|
+
* These abstractions allow the discovery logic to be independent of storage implementation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Discovery adapter for managing cached provider and model data
|
|
10
|
+
* Abstracts localStorage operations so discovery logic is testable and reusable
|
|
11
|
+
*/
|
|
12
|
+
interface DiscoveryAdapter {
|
|
13
|
+
/**
|
|
14
|
+
* Get cached models from all providers
|
|
15
|
+
* @returns Record mapping baseUrl -> array of models
|
|
16
|
+
*/
|
|
17
|
+
getCachedModels(): Record<string, Model[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Save models cache
|
|
20
|
+
* @param models Record mapping baseUrl -> array of models
|
|
21
|
+
*/
|
|
22
|
+
setCachedModels(models: Record<string, Model[]>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Get cached mints from all providers
|
|
25
|
+
* @returns Record mapping baseUrl -> array of mint URLs
|
|
26
|
+
*/
|
|
27
|
+
getCachedMints(): Record<string, string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Save mints cache
|
|
30
|
+
* @param mints Record mapping baseUrl -> array of mint URLs
|
|
31
|
+
*/
|
|
32
|
+
setCachedMints(mints: Record<string, string[]>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get cached provider info from all providers
|
|
35
|
+
* @returns Record mapping baseUrl -> provider info object
|
|
36
|
+
*/
|
|
37
|
+
getCachedProviderInfo(): Record<string, ProviderInfo>;
|
|
38
|
+
/**
|
|
39
|
+
* Save provider info cache
|
|
40
|
+
* @param info Record mapping baseUrl -> provider info object
|
|
41
|
+
*/
|
|
42
|
+
setCachedProviderInfo(info: Record<string, ProviderInfo>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get provider last update timestamp
|
|
45
|
+
* @param baseUrl Provider base URL
|
|
46
|
+
* @returns Timestamp in milliseconds or null if never updated
|
|
47
|
+
*/
|
|
48
|
+
getProviderLastUpdate(baseUrl: string): number | null;
|
|
49
|
+
/**
|
|
50
|
+
* Set provider last update timestamp
|
|
51
|
+
* @param baseUrl Provider base URL
|
|
52
|
+
* @param timestamp Timestamp in milliseconds
|
|
53
|
+
*/
|
|
54
|
+
setProviderLastUpdate(baseUrl: string, timestamp: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get last used model ID
|
|
57
|
+
* @returns Model ID or null if none
|
|
58
|
+
*/
|
|
59
|
+
getLastUsedModel(): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Save last used model ID
|
|
62
|
+
* @param modelId Model ID to save
|
|
63
|
+
*/
|
|
64
|
+
setLastUsedModel(modelId: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get list of disabled provider base URLs
|
|
67
|
+
* @returns Array of disabled provider URLs
|
|
68
|
+
*/
|
|
69
|
+
getDisabledProviders(): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Get list of configured provider base URLs
|
|
72
|
+
* @returns Array of provider base URLs
|
|
73
|
+
*/
|
|
74
|
+
getBaseUrlsList(): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Get base URLs list last update timestamp
|
|
77
|
+
* @returns Timestamp in milliseconds or null if never updated
|
|
78
|
+
*/
|
|
79
|
+
getBaseUrlsLastUpdate(): number | null;
|
|
80
|
+
/**
|
|
81
|
+
* Save list of provider base URLs
|
|
82
|
+
* @param urls Array of provider base URLs
|
|
83
|
+
*/
|
|
84
|
+
setBaseUrlsList(urls: string[]): void;
|
|
85
|
+
/**
|
|
86
|
+
* Set base URLs list last update timestamp
|
|
87
|
+
* @param timestamp Timestamp in milliseconds
|
|
88
|
+
*/
|
|
89
|
+
setBaseUrlsLastUpdate(timestamp: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Get list of routstr21 models
|
|
92
|
+
* @returns Array of model IDs
|
|
93
|
+
*/
|
|
94
|
+
getRoutstr21Models(): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Save routstr21 models list
|
|
97
|
+
* @param models Array of model IDs
|
|
98
|
+
*/
|
|
99
|
+
setRoutstr21Models(models: string[]): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type { DiscoveryAdapter as D };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { M as Model, P as ProviderInfo } from './types-BlHjmWRK.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interfaces for the model and provider discovery system
|
|
5
|
+
* These abstractions allow the discovery logic to be independent of storage implementation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Discovery adapter for managing cached provider and model data
|
|
10
|
+
* Abstracts localStorage operations so discovery logic is testable and reusable
|
|
11
|
+
*/
|
|
12
|
+
interface DiscoveryAdapter {
|
|
13
|
+
/**
|
|
14
|
+
* Get cached models from all providers
|
|
15
|
+
* @returns Record mapping baseUrl -> array of models
|
|
16
|
+
*/
|
|
17
|
+
getCachedModels(): Record<string, Model[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Save models cache
|
|
20
|
+
* @param models Record mapping baseUrl -> array of models
|
|
21
|
+
*/
|
|
22
|
+
setCachedModels(models: Record<string, Model[]>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Get cached mints from all providers
|
|
25
|
+
* @returns Record mapping baseUrl -> array of mint URLs
|
|
26
|
+
*/
|
|
27
|
+
getCachedMints(): Record<string, string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Save mints cache
|
|
30
|
+
* @param mints Record mapping baseUrl -> array of mint URLs
|
|
31
|
+
*/
|
|
32
|
+
setCachedMints(mints: Record<string, string[]>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get cached provider info from all providers
|
|
35
|
+
* @returns Record mapping baseUrl -> provider info object
|
|
36
|
+
*/
|
|
37
|
+
getCachedProviderInfo(): Record<string, ProviderInfo>;
|
|
38
|
+
/**
|
|
39
|
+
* Save provider info cache
|
|
40
|
+
* @param info Record mapping baseUrl -> provider info object
|
|
41
|
+
*/
|
|
42
|
+
setCachedProviderInfo(info: Record<string, ProviderInfo>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get provider last update timestamp
|
|
45
|
+
* @param baseUrl Provider base URL
|
|
46
|
+
* @returns Timestamp in milliseconds or null if never updated
|
|
47
|
+
*/
|
|
48
|
+
getProviderLastUpdate(baseUrl: string): number | null;
|
|
49
|
+
/**
|
|
50
|
+
* Set provider last update timestamp
|
|
51
|
+
* @param baseUrl Provider base URL
|
|
52
|
+
* @param timestamp Timestamp in milliseconds
|
|
53
|
+
*/
|
|
54
|
+
setProviderLastUpdate(baseUrl: string, timestamp: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get last used model ID
|
|
57
|
+
* @returns Model ID or null if none
|
|
58
|
+
*/
|
|
59
|
+
getLastUsedModel(): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Save last used model ID
|
|
62
|
+
* @param modelId Model ID to save
|
|
63
|
+
*/
|
|
64
|
+
setLastUsedModel(modelId: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get list of disabled provider base URLs
|
|
67
|
+
* @returns Array of disabled provider URLs
|
|
68
|
+
*/
|
|
69
|
+
getDisabledProviders(): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Get list of configured provider base URLs
|
|
72
|
+
* @returns Array of provider base URLs
|
|
73
|
+
*/
|
|
74
|
+
getBaseUrlsList(): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Get base URLs list last update timestamp
|
|
77
|
+
* @returns Timestamp in milliseconds or null if never updated
|
|
78
|
+
*/
|
|
79
|
+
getBaseUrlsLastUpdate(): number | null;
|
|
80
|
+
/**
|
|
81
|
+
* Save list of provider base URLs
|
|
82
|
+
* @param urls Array of provider base URLs
|
|
83
|
+
*/
|
|
84
|
+
setBaseUrlsList(urls: string[]): void;
|
|
85
|
+
/**
|
|
86
|
+
* Set base URLs list last update timestamp
|
|
87
|
+
* @param timestamp Timestamp in milliseconds
|
|
88
|
+
*/
|
|
89
|
+
setBaseUrlsLastUpdate(timestamp: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Get list of routstr21 models
|
|
92
|
+
* @returns Array of model IDs
|
|
93
|
+
*/
|
|
94
|
+
getRoutstr21Models(): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Save routstr21 models list
|
|
97
|
+
* @param models Array of model IDs
|
|
98
|
+
*/
|
|
99
|
+
setRoutstr21Models(models: string[]): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type { DiscoveryAdapter as D };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { M as Model, P as ProviderInfo } from '../types-BlHjmWRK.mjs';
|
|
2
|
+
import { StoreApi } from 'zustand/vanilla';
|
|
3
|
+
import { D as DiscoveryAdapter } from '../interfaces-nanJOqdW.mjs';
|
|
4
|
+
import { P as ProviderRegistry, S as StorageAdapter } from '../interfaces-B85Wx7ni.mjs';
|
|
5
|
+
|
|
6
|
+
interface StorageDriver {
|
|
7
|
+
getItem<T>(key: string, defaultValue: T): Promise<T>;
|
|
8
|
+
setItem<T>(key: string, value: T): Promise<void>;
|
|
9
|
+
removeItem(key: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
interface SdkStorageState {
|
|
12
|
+
modelsFromAllProviders: Record<string, Model[]>;
|
|
13
|
+
lastUsedModel: string | null;
|
|
14
|
+
baseUrlsList: string[];
|
|
15
|
+
disabledProviders: string[];
|
|
16
|
+
mintsFromAllProviders: Record<string, string[]>;
|
|
17
|
+
infoFromAllProviders: Record<string, ProviderInfo>;
|
|
18
|
+
lastModelsUpdate: Record<string, number>;
|
|
19
|
+
lastBaseUrlsUpdate: number | null;
|
|
20
|
+
cachedTokens: Array<{
|
|
21
|
+
baseUrl: string;
|
|
22
|
+
token: string;
|
|
23
|
+
balance: number;
|
|
24
|
+
lastUsed: number | null;
|
|
25
|
+
}>;
|
|
26
|
+
apiKeys: Array<{
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
key: string;
|
|
29
|
+
balance: number;
|
|
30
|
+
lastUsed: number | null;
|
|
31
|
+
}>;
|
|
32
|
+
childKeys: Array<{
|
|
33
|
+
parentBaseUrl: string;
|
|
34
|
+
childKey: string;
|
|
35
|
+
balance: number;
|
|
36
|
+
balanceLimit?: number;
|
|
37
|
+
validityDate?: number;
|
|
38
|
+
createdAt: number;
|
|
39
|
+
}>;
|
|
40
|
+
routstr21Models: string[];
|
|
41
|
+
cachedReceiveTokens: Array<{
|
|
42
|
+
token: string;
|
|
43
|
+
amount: number;
|
|
44
|
+
unit: "sat" | "msat";
|
|
45
|
+
createdAt: number;
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare const localStorageDriver: StorageDriver;
|
|
50
|
+
|
|
51
|
+
declare const createMemoryDriver: (seed?: Record<string, string>) => StorageDriver;
|
|
52
|
+
|
|
53
|
+
interface SqliteDriverOptions {
|
|
54
|
+
dbPath?: string;
|
|
55
|
+
tableName?: string;
|
|
56
|
+
}
|
|
57
|
+
declare const createSqliteDriver: (options?: SqliteDriverOptions) => StorageDriver;
|
|
58
|
+
|
|
59
|
+
interface IndexedDBDriverOptions {
|
|
60
|
+
dbName?: string;
|
|
61
|
+
storeName?: string;
|
|
62
|
+
}
|
|
63
|
+
declare const createIndexedDBDriver: (options?: IndexedDBDriverOptions) => StorageDriver;
|
|
64
|
+
|
|
65
|
+
interface SdkStoreOptions {
|
|
66
|
+
driver: StorageDriver;
|
|
67
|
+
}
|
|
68
|
+
interface SdkStorageStore extends SdkStorageState {
|
|
69
|
+
setModelsFromAllProviders: (value: Record<string, Model[]>) => void;
|
|
70
|
+
setLastUsedModel: (value: string | null) => void;
|
|
71
|
+
setBaseUrlsList: (value: string[]) => void;
|
|
72
|
+
setBaseUrlsLastUpdate: (value: number | null) => void;
|
|
73
|
+
setDisabledProviders: (value: string[]) => void;
|
|
74
|
+
setMintsFromAllProviders: (value: Record<string, string[]>) => void;
|
|
75
|
+
setInfoFromAllProviders: (value: Record<string, ProviderInfo>) => void;
|
|
76
|
+
setLastModelsUpdate: (value: Record<string, number>) => void;
|
|
77
|
+
setCachedTokens: (value: Array<{
|
|
78
|
+
baseUrl: string;
|
|
79
|
+
token: string;
|
|
80
|
+
balance?: number;
|
|
81
|
+
lastUsed?: number | null;
|
|
82
|
+
}> | ((current: SdkStorageStore["cachedTokens"]) => SdkStorageStore["cachedTokens"])) => void;
|
|
83
|
+
setApiKeys: (value: Array<{
|
|
84
|
+
baseUrl: string;
|
|
85
|
+
key: string;
|
|
86
|
+
balance?: number;
|
|
87
|
+
lastUsed?: number | null;
|
|
88
|
+
}> | ((current: SdkStorageStore["apiKeys"]) => SdkStorageStore["apiKeys"])) => void;
|
|
89
|
+
setChildKeys: (value: Array<{
|
|
90
|
+
parentBaseUrl: string;
|
|
91
|
+
childKey: string;
|
|
92
|
+
balance?: number;
|
|
93
|
+
balanceLimit?: number;
|
|
94
|
+
validityDate?: number;
|
|
95
|
+
createdAt?: number;
|
|
96
|
+
}>) => void;
|
|
97
|
+
setRoutstr21Models: (value: string[]) => void;
|
|
98
|
+
setCachedReceiveTokens: (value: Array<{
|
|
99
|
+
token: string;
|
|
100
|
+
amount: number;
|
|
101
|
+
unit: "sat" | "msat";
|
|
102
|
+
createdAt?: number;
|
|
103
|
+
}>) => void;
|
|
104
|
+
}
|
|
105
|
+
/** Store type returned after async initialization */
|
|
106
|
+
type SdkStore = StoreApi<SdkStorageStore>;
|
|
107
|
+
declare const createSdkStore: ({ driver, }: SdkStoreOptions) => Promise<SdkStore>;
|
|
108
|
+
declare const createDiscoveryAdapterFromStore: (store: SdkStore) => DiscoveryAdapter;
|
|
109
|
+
declare const createStorageAdapterFromStore: (store: SdkStore) => StorageAdapter;
|
|
110
|
+
declare const createProviderRegistryFromStore: (store: SdkStore) => ProviderRegistry;
|
|
111
|
+
|
|
112
|
+
declare const SDK_STORAGE_KEYS: {
|
|
113
|
+
readonly MODELS_FROM_ALL_PROVIDERS: "modelsFromAllProviders";
|
|
114
|
+
readonly LAST_USED_MODEL: "lastUsedModel";
|
|
115
|
+
readonly BASE_URLS_LIST: "base_urls_list";
|
|
116
|
+
readonly DISABLED_PROVIDERS: "disabled_providers";
|
|
117
|
+
readonly MINTS_FROM_ALL_PROVIDERS: "mints_from_all_providers";
|
|
118
|
+
readonly INFO_FROM_ALL_PROVIDERS: "info_from_all_providers";
|
|
119
|
+
readonly LAST_MODELS_UPDATE: "lastModelsUpdate";
|
|
120
|
+
readonly LAST_BASE_URLS_UPDATE: "lastBaseUrlsUpdate";
|
|
121
|
+
readonly LOCAL_CASHU_TOKENS: "local_cashu_tokens";
|
|
122
|
+
readonly API_KEYS: "api_keys";
|
|
123
|
+
readonly CHILD_KEYS: "child_keys";
|
|
124
|
+
readonly ROUTSTR21_MODELS: "routstr21Models";
|
|
125
|
+
readonly CACHED_RECEIVE_TOKENS: "cached_receive_tokens";
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
declare const getDefaultSdkDriver: () => StorageDriver;
|
|
129
|
+
declare const getDefaultSdkStore: () => Promise<SdkStore>;
|
|
130
|
+
declare const getDefaultDiscoveryAdapter: () => Promise<DiscoveryAdapter>;
|
|
131
|
+
declare const getDefaultStorageAdapter: () => Promise<StorageAdapter>;
|
|
132
|
+
declare const getDefaultProviderRegistry: () => Promise<ProviderRegistry>;
|
|
133
|
+
|
|
134
|
+
export { DiscoveryAdapter, ProviderRegistry, SDK_STORAGE_KEYS, type SdkStore, StorageAdapter, type StorageDriver, createDiscoveryAdapterFromStore, createIndexedDBDriver, createMemoryDriver, createProviderRegistryFromStore, createSdkStore, createSqliteDriver, createStorageAdapterFromStore, getDefaultDiscoveryAdapter, getDefaultProviderRegistry, getDefaultSdkDriver, getDefaultSdkStore, getDefaultStorageAdapter, localStorageDriver };
|