@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,186 @@
|
|
|
1
|
+
import { D as DiscoveryAdapter } from '../interfaces-nanJOqdW.mjs';
|
|
2
|
+
import { M as Model, P as ProviderInfo } from '../types-BlHjmWRK.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ModelManager class for discovering, fetching, and managing models from providers
|
|
6
|
+
* Core responsibility: fetching models from providers, caching them, and selecting the best option
|
|
7
|
+
* (lowest cost) across multiple providers
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for ModelManager
|
|
12
|
+
*/
|
|
13
|
+
interface ModelManagerConfig {
|
|
14
|
+
/** URL to fetch provider directory from */
|
|
15
|
+
providerDirectoryUrl?: string;
|
|
16
|
+
/** Additional provider base URLs to include */
|
|
17
|
+
includeProviderUrls?: string[];
|
|
18
|
+
/** Provider base URLs to exclude */
|
|
19
|
+
excludeProviderUrls?: string[];
|
|
20
|
+
/** Cache TTL in milliseconds (default: 21 minutes) */
|
|
21
|
+
cacheTTL?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* ModelManager handles all model discovery and caching logic
|
|
25
|
+
* Abstracts away storage details via DiscoveryAdapter
|
|
26
|
+
*/
|
|
27
|
+
declare class ModelManager {
|
|
28
|
+
private adapter;
|
|
29
|
+
private readonly cacheTTL;
|
|
30
|
+
private readonly providerDirectoryUrl;
|
|
31
|
+
private readonly includeProviderUrls;
|
|
32
|
+
private readonly excludeProviderUrls;
|
|
33
|
+
constructor(adapter: DiscoveryAdapter, config?: ModelManagerConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Get the list of bootstrapped provider base URLs
|
|
36
|
+
* @returns Array of provider base URLs
|
|
37
|
+
*/
|
|
38
|
+
getBaseUrls(): string[];
|
|
39
|
+
static init(adapter: DiscoveryAdapter, config?: ModelManagerConfig, options?: {
|
|
40
|
+
torMode?: boolean;
|
|
41
|
+
forceRefresh?: boolean;
|
|
42
|
+
}): Promise<ModelManager>;
|
|
43
|
+
/**
|
|
44
|
+
* Bootstrap provider list from the provider directory
|
|
45
|
+
* First tries to fetch from Nostr (kind 30421), falls back to HTTP
|
|
46
|
+
* @param torMode Whether running in Tor context
|
|
47
|
+
* @returns Array of provider base URLs
|
|
48
|
+
* @throws ProviderBootstrapError if all providers fail to fetch
|
|
49
|
+
*/
|
|
50
|
+
bootstrapProviders(torMode?: boolean): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Bootstrap providers from Nostr network (kind 30421)
|
|
53
|
+
* @param kind The Nostr kind to fetch
|
|
54
|
+
* @param torMode Whether running in Tor context
|
|
55
|
+
* @returns Array of provider base URLs
|
|
56
|
+
*/
|
|
57
|
+
private bootstrapFromNostr;
|
|
58
|
+
/**
|
|
59
|
+
* Bootstrap providers from HTTP endpoint
|
|
60
|
+
* @param torMode Whether running in Tor context
|
|
61
|
+
* @returns Array of provider base URLs
|
|
62
|
+
*/
|
|
63
|
+
private bootstrapFromHttp;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch models from all providers and select best-priced options
|
|
66
|
+
* Uses cache if available and not expired
|
|
67
|
+
* @param baseUrls List of provider base URLs to fetch from
|
|
68
|
+
* @param forceRefresh Ignore cache and fetch fresh data
|
|
69
|
+
* @returns Array of unique models with best prices selected
|
|
70
|
+
*/
|
|
71
|
+
fetchModels(baseUrls: string[], forceRefresh?: boolean): Promise<Model[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Fetch models from a single provider
|
|
74
|
+
* @param baseUrl Provider base URL
|
|
75
|
+
* @returns Array of models from provider
|
|
76
|
+
*/
|
|
77
|
+
private fetchModelsFromProvider;
|
|
78
|
+
private isProviderDownError;
|
|
79
|
+
/**
|
|
80
|
+
* Get all cached models from all providers
|
|
81
|
+
* @returns Record mapping baseUrl -> models
|
|
82
|
+
*/
|
|
83
|
+
getAllCachedModels(): Record<string, Model[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Clear cache for a specific provider
|
|
86
|
+
* @param baseUrl Provider base URL
|
|
87
|
+
*/
|
|
88
|
+
clearProviderCache(baseUrl: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Clear all model caches
|
|
91
|
+
*/
|
|
92
|
+
clearAllCache(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Filter base URLs based on Tor context
|
|
95
|
+
* @param baseUrls Provider URLs to filter
|
|
96
|
+
* @param torMode Whether in Tor context
|
|
97
|
+
* @returns Filtered URLs appropriate for Tor mode
|
|
98
|
+
*/
|
|
99
|
+
filterBaseUrlsForTor(baseUrls: string[], torMode: boolean): string[];
|
|
100
|
+
/**
|
|
101
|
+
* Get provider endpoints from provider info
|
|
102
|
+
* @param provider Provider object from directory
|
|
103
|
+
* @param torMode Whether in Tor context
|
|
104
|
+
* @returns Array of endpoint URLs
|
|
105
|
+
*/
|
|
106
|
+
private getProviderEndpoints;
|
|
107
|
+
/**
|
|
108
|
+
* Normalize provider URL with trailing slash
|
|
109
|
+
* @param url URL to normalize
|
|
110
|
+
* @returns Normalized URL
|
|
111
|
+
*/
|
|
112
|
+
private normalizeUrl;
|
|
113
|
+
/**
|
|
114
|
+
* Fetch routstr21 models from Nostr network (kind 38423)
|
|
115
|
+
* @returns Array of model IDs or empty array if not found
|
|
116
|
+
*/
|
|
117
|
+
fetchRoutstr21Models(): Promise<string[]>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* MintDiscovery class for discovering mints and provider info
|
|
122
|
+
* Core responsibility: fetching mint information from providers and caching it
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Configuration for MintDiscovery
|
|
127
|
+
*/
|
|
128
|
+
interface MintDiscoveryConfig {
|
|
129
|
+
/** Cache TTL in milliseconds (default: 21 minutes) */
|
|
130
|
+
cacheTTL?: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* MintDiscovery handles mint and provider info discovery
|
|
134
|
+
* Abstracts away storage details via DiscoveryAdapter
|
|
135
|
+
*/
|
|
136
|
+
declare class MintDiscovery {
|
|
137
|
+
private adapter;
|
|
138
|
+
private readonly cacheTTL;
|
|
139
|
+
constructor(adapter: DiscoveryAdapter, config?: MintDiscoveryConfig);
|
|
140
|
+
/**
|
|
141
|
+
* Fetch mints from all providers via their /v1/info endpoints
|
|
142
|
+
* Caches mints and full provider info for later access
|
|
143
|
+
* @param baseUrls List of provider base URLs to fetch from
|
|
144
|
+
* @returns Object with mints and provider info from all providers
|
|
145
|
+
*/
|
|
146
|
+
discoverMints(baseUrls: string[], options?: {
|
|
147
|
+
forceRefresh?: boolean;
|
|
148
|
+
}): Promise<{
|
|
149
|
+
mintsFromProviders: Record<string, string[]>;
|
|
150
|
+
infoFromProviders: Record<string, ProviderInfo>;
|
|
151
|
+
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Get cached mints from all providers
|
|
154
|
+
* @returns Record mapping baseUrl -> mint URLs
|
|
155
|
+
*/
|
|
156
|
+
getCachedMints(): Record<string, string[]>;
|
|
157
|
+
/**
|
|
158
|
+
* Get cached provider info from all providers
|
|
159
|
+
* @returns Record mapping baseUrl -> provider info
|
|
160
|
+
*/
|
|
161
|
+
getCachedProviderInfo(): Record<string, ProviderInfo>;
|
|
162
|
+
/**
|
|
163
|
+
* Get mints for a specific provider
|
|
164
|
+
* @param baseUrl Provider base URL
|
|
165
|
+
* @returns Array of mint URLs for the provider
|
|
166
|
+
*/
|
|
167
|
+
getProviderMints(baseUrl: string): string[];
|
|
168
|
+
/**
|
|
169
|
+
* Get info for a specific provider
|
|
170
|
+
* @param baseUrl Provider base URL
|
|
171
|
+
* @returns Provider info object or null if not found
|
|
172
|
+
*/
|
|
173
|
+
getProviderInfo(baseUrl: string): ProviderInfo | null;
|
|
174
|
+
/**
|
|
175
|
+
* Clear mint cache for a specific provider
|
|
176
|
+
* @param baseUrl Provider base URL
|
|
177
|
+
*/
|
|
178
|
+
clearProviderMintCache(baseUrl: string): void;
|
|
179
|
+
/**
|
|
180
|
+
* Clear all mint caches
|
|
181
|
+
*/
|
|
182
|
+
clearAllCache(): void;
|
|
183
|
+
private isProviderDownError;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { DiscoveryAdapter, MintDiscovery, ModelManager, type ModelManagerConfig, ProviderInfo };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { D as DiscoveryAdapter } from '../interfaces-Dnrvxr6N.js';
|
|
2
|
+
import { M as Model, P as ProviderInfo } from '../types-BlHjmWRK.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ModelManager class for discovering, fetching, and managing models from providers
|
|
6
|
+
* Core responsibility: fetching models from providers, caching them, and selecting the best option
|
|
7
|
+
* (lowest cost) across multiple providers
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for ModelManager
|
|
12
|
+
*/
|
|
13
|
+
interface ModelManagerConfig {
|
|
14
|
+
/** URL to fetch provider directory from */
|
|
15
|
+
providerDirectoryUrl?: string;
|
|
16
|
+
/** Additional provider base URLs to include */
|
|
17
|
+
includeProviderUrls?: string[];
|
|
18
|
+
/** Provider base URLs to exclude */
|
|
19
|
+
excludeProviderUrls?: string[];
|
|
20
|
+
/** Cache TTL in milliseconds (default: 21 minutes) */
|
|
21
|
+
cacheTTL?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* ModelManager handles all model discovery and caching logic
|
|
25
|
+
* Abstracts away storage details via DiscoveryAdapter
|
|
26
|
+
*/
|
|
27
|
+
declare class ModelManager {
|
|
28
|
+
private adapter;
|
|
29
|
+
private readonly cacheTTL;
|
|
30
|
+
private readonly providerDirectoryUrl;
|
|
31
|
+
private readonly includeProviderUrls;
|
|
32
|
+
private readonly excludeProviderUrls;
|
|
33
|
+
constructor(adapter: DiscoveryAdapter, config?: ModelManagerConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Get the list of bootstrapped provider base URLs
|
|
36
|
+
* @returns Array of provider base URLs
|
|
37
|
+
*/
|
|
38
|
+
getBaseUrls(): string[];
|
|
39
|
+
static init(adapter: DiscoveryAdapter, config?: ModelManagerConfig, options?: {
|
|
40
|
+
torMode?: boolean;
|
|
41
|
+
forceRefresh?: boolean;
|
|
42
|
+
}): Promise<ModelManager>;
|
|
43
|
+
/**
|
|
44
|
+
* Bootstrap provider list from the provider directory
|
|
45
|
+
* First tries to fetch from Nostr (kind 30421), falls back to HTTP
|
|
46
|
+
* @param torMode Whether running in Tor context
|
|
47
|
+
* @returns Array of provider base URLs
|
|
48
|
+
* @throws ProviderBootstrapError if all providers fail to fetch
|
|
49
|
+
*/
|
|
50
|
+
bootstrapProviders(torMode?: boolean): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Bootstrap providers from Nostr network (kind 30421)
|
|
53
|
+
* @param kind The Nostr kind to fetch
|
|
54
|
+
* @param torMode Whether running in Tor context
|
|
55
|
+
* @returns Array of provider base URLs
|
|
56
|
+
*/
|
|
57
|
+
private bootstrapFromNostr;
|
|
58
|
+
/**
|
|
59
|
+
* Bootstrap providers from HTTP endpoint
|
|
60
|
+
* @param torMode Whether running in Tor context
|
|
61
|
+
* @returns Array of provider base URLs
|
|
62
|
+
*/
|
|
63
|
+
private bootstrapFromHttp;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch models from all providers and select best-priced options
|
|
66
|
+
* Uses cache if available and not expired
|
|
67
|
+
* @param baseUrls List of provider base URLs to fetch from
|
|
68
|
+
* @param forceRefresh Ignore cache and fetch fresh data
|
|
69
|
+
* @returns Array of unique models with best prices selected
|
|
70
|
+
*/
|
|
71
|
+
fetchModels(baseUrls: string[], forceRefresh?: boolean): Promise<Model[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Fetch models from a single provider
|
|
74
|
+
* @param baseUrl Provider base URL
|
|
75
|
+
* @returns Array of models from provider
|
|
76
|
+
*/
|
|
77
|
+
private fetchModelsFromProvider;
|
|
78
|
+
private isProviderDownError;
|
|
79
|
+
/**
|
|
80
|
+
* Get all cached models from all providers
|
|
81
|
+
* @returns Record mapping baseUrl -> models
|
|
82
|
+
*/
|
|
83
|
+
getAllCachedModels(): Record<string, Model[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Clear cache for a specific provider
|
|
86
|
+
* @param baseUrl Provider base URL
|
|
87
|
+
*/
|
|
88
|
+
clearProviderCache(baseUrl: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Clear all model caches
|
|
91
|
+
*/
|
|
92
|
+
clearAllCache(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Filter base URLs based on Tor context
|
|
95
|
+
* @param baseUrls Provider URLs to filter
|
|
96
|
+
* @param torMode Whether in Tor context
|
|
97
|
+
* @returns Filtered URLs appropriate for Tor mode
|
|
98
|
+
*/
|
|
99
|
+
filterBaseUrlsForTor(baseUrls: string[], torMode: boolean): string[];
|
|
100
|
+
/**
|
|
101
|
+
* Get provider endpoints from provider info
|
|
102
|
+
* @param provider Provider object from directory
|
|
103
|
+
* @param torMode Whether in Tor context
|
|
104
|
+
* @returns Array of endpoint URLs
|
|
105
|
+
*/
|
|
106
|
+
private getProviderEndpoints;
|
|
107
|
+
/**
|
|
108
|
+
* Normalize provider URL with trailing slash
|
|
109
|
+
* @param url URL to normalize
|
|
110
|
+
* @returns Normalized URL
|
|
111
|
+
*/
|
|
112
|
+
private normalizeUrl;
|
|
113
|
+
/**
|
|
114
|
+
* Fetch routstr21 models from Nostr network (kind 38423)
|
|
115
|
+
* @returns Array of model IDs or empty array if not found
|
|
116
|
+
*/
|
|
117
|
+
fetchRoutstr21Models(): Promise<string[]>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* MintDiscovery class for discovering mints and provider info
|
|
122
|
+
* Core responsibility: fetching mint information from providers and caching it
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Configuration for MintDiscovery
|
|
127
|
+
*/
|
|
128
|
+
interface MintDiscoveryConfig {
|
|
129
|
+
/** Cache TTL in milliseconds (default: 21 minutes) */
|
|
130
|
+
cacheTTL?: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* MintDiscovery handles mint and provider info discovery
|
|
134
|
+
* Abstracts away storage details via DiscoveryAdapter
|
|
135
|
+
*/
|
|
136
|
+
declare class MintDiscovery {
|
|
137
|
+
private adapter;
|
|
138
|
+
private readonly cacheTTL;
|
|
139
|
+
constructor(adapter: DiscoveryAdapter, config?: MintDiscoveryConfig);
|
|
140
|
+
/**
|
|
141
|
+
* Fetch mints from all providers via their /v1/info endpoints
|
|
142
|
+
* Caches mints and full provider info for later access
|
|
143
|
+
* @param baseUrls List of provider base URLs to fetch from
|
|
144
|
+
* @returns Object with mints and provider info from all providers
|
|
145
|
+
*/
|
|
146
|
+
discoverMints(baseUrls: string[], options?: {
|
|
147
|
+
forceRefresh?: boolean;
|
|
148
|
+
}): Promise<{
|
|
149
|
+
mintsFromProviders: Record<string, string[]>;
|
|
150
|
+
infoFromProviders: Record<string, ProviderInfo>;
|
|
151
|
+
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Get cached mints from all providers
|
|
154
|
+
* @returns Record mapping baseUrl -> mint URLs
|
|
155
|
+
*/
|
|
156
|
+
getCachedMints(): Record<string, string[]>;
|
|
157
|
+
/**
|
|
158
|
+
* Get cached provider info from all providers
|
|
159
|
+
* @returns Record mapping baseUrl -> provider info
|
|
160
|
+
*/
|
|
161
|
+
getCachedProviderInfo(): Record<string, ProviderInfo>;
|
|
162
|
+
/**
|
|
163
|
+
* Get mints for a specific provider
|
|
164
|
+
* @param baseUrl Provider base URL
|
|
165
|
+
* @returns Array of mint URLs for the provider
|
|
166
|
+
*/
|
|
167
|
+
getProviderMints(baseUrl: string): string[];
|
|
168
|
+
/**
|
|
169
|
+
* Get info for a specific provider
|
|
170
|
+
* @param baseUrl Provider base URL
|
|
171
|
+
* @returns Provider info object or null if not found
|
|
172
|
+
*/
|
|
173
|
+
getProviderInfo(baseUrl: string): ProviderInfo | null;
|
|
174
|
+
/**
|
|
175
|
+
* Clear mint cache for a specific provider
|
|
176
|
+
* @param baseUrl Provider base URL
|
|
177
|
+
*/
|
|
178
|
+
clearProviderMintCache(baseUrl: string): void;
|
|
179
|
+
/**
|
|
180
|
+
* Clear all mint caches
|
|
181
|
+
*/
|
|
182
|
+
clearAllCache(): void;
|
|
183
|
+
private isProviderDownError;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { DiscoveryAdapter, MintDiscovery, ModelManager, type ModelManagerConfig, ProviderInfo };
|