@routstr/sdk 0.3.7 → 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.
Files changed (39) hide show
  1. package/dist/client/index.d.mts +411 -0
  2. package/dist/client/index.d.ts +411 -0
  3. package/dist/client/index.js +4883 -0
  4. package/dist/client/index.js.map +1 -0
  5. package/dist/client/index.mjs +4877 -0
  6. package/dist/client/index.mjs.map +1 -0
  7. package/dist/discovery/index.d.mts +213 -0
  8. package/dist/discovery/index.d.ts +213 -0
  9. package/dist/discovery/index.js +738 -0
  10. package/dist/discovery/index.js.map +1 -0
  11. package/dist/discovery/index.mjs +735 -0
  12. package/dist/discovery/index.mjs.map +1 -0
  13. package/dist/index.d.mts +194 -0
  14. package/dist/index.d.ts +194 -0
  15. package/dist/index.js +6307 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/index.mjs +6258 -0
  18. package/dist/index.mjs.map +1 -0
  19. package/dist/interfaces-C-DYd9Jy.d.ts +176 -0
  20. package/dist/interfaces-Csn8Uq04.d.mts +176 -0
  21. package/dist/interfaces-Cv1k2EUK.d.mts +118 -0
  22. package/dist/interfaces-iL7CWeG5.d.ts +118 -0
  23. package/dist/storage/index.d.mts +87 -0
  24. package/dist/storage/index.d.ts +87 -0
  25. package/dist/storage/index.js +1740 -0
  26. package/dist/storage/index.js.map +1 -0
  27. package/dist/storage/index.mjs +1718 -0
  28. package/dist/storage/index.mjs.map +1 -0
  29. package/dist/store-58VcEUoA.d.ts +172 -0
  30. package/dist/store-C6dfj1cc.d.mts +172 -0
  31. package/dist/types-_21yYFZG.d.mts +234 -0
  32. package/dist/types-_21yYFZG.d.ts +234 -0
  33. package/dist/wallet/index.d.mts +245 -0
  34. package/dist/wallet/index.d.ts +245 -0
  35. package/dist/wallet/index.js +1376 -0
  36. package/dist/wallet/index.js.map +1 -0
  37. package/dist/wallet/index.mjs +1373 -0
  38. package/dist/wallet/index.mjs.map +1 -0
  39. package/package.json +1 -1
@@ -0,0 +1,213 @@
1
+ import { D as DiscoveryAdapter } from '../interfaces-Cv1k2EUK.mjs';
2
+ import { S as SdkLogger, e as Model, k as ProviderInfo } from '../types-_21yYFZG.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
+ /** Nostr pubkey for routstr review/model events (kind 38425/38423). Defaults to routstr's key. */
23
+ routstrPubkey?: string;
24
+ /** Optional injectable logger */
25
+ logger?: SdkLogger;
26
+ }
27
+ /**
28
+ * ModelManager handles all model discovery and caching logic
29
+ * Abstracts away storage details via DiscoveryAdapter
30
+ */
31
+ declare class ModelManager {
32
+ private adapter;
33
+ private readonly cacheTTL;
34
+ private readonly providerDirectoryUrl;
35
+ private readonly includeProviderUrls;
36
+ private readonly excludeProviderUrls;
37
+ private readonly routstrPubkey;
38
+ private readonly logger;
39
+ private providerNodePubkeysByUrl;
40
+ constructor(adapter: DiscoveryAdapter, config?: ModelManagerConfig);
41
+ /**
42
+ * Get the list of bootstrapped provider base URLs
43
+ * @returns Array of provider base URLs
44
+ */
45
+ getBaseUrls(): string[];
46
+ static init(adapter: DiscoveryAdapter, config?: ModelManagerConfig, options?: {
47
+ torMode?: boolean;
48
+ forceRefresh?: boolean;
49
+ }): Promise<ModelManager>;
50
+ /**
51
+ * Bootstrap provider list from the provider directory
52
+ * First tries to fetch from Nostr (kind 30421), falls back to HTTP
53
+ * @param torMode Whether running in Tor context
54
+ * @param forceRefresh Ignore provider cache and refresh provider sources
55
+ * @returns Array of provider base URLs
56
+ * @throws ProviderBootstrapError if all providers fail to fetch
57
+ */
58
+ bootstrapProviders(torMode?: boolean, forceRefresh?: boolean): Promise<string[]>;
59
+ /**
60
+ * Bootstrap providers from Nostr network (kind 30421)
61
+ * @param kind The Nostr kind to fetch
62
+ * @param torMode Whether running in Tor context
63
+ * @returns Array of provider base URLs
64
+ */
65
+ private bootstrapFromNostr;
66
+ /**
67
+ * Bootstrap providers from HTTP endpoint
68
+ * @param torMode Whether running in Tor context
69
+ * @param forceRefresh Ignore routstr21 cache and fetch fresh data
70
+ * @returns Array of provider base URLs
71
+ */
72
+ private bootstrapFromHttp;
73
+ /**
74
+ * Fetch Routstr review events from Nostr (kind 38425) and disable providers
75
+ * whose 38421 node pubkey does not have at least one review tagged `t=lgtm`.
76
+ *
77
+ * Review events are expected to have:
78
+ * - `node`: the reviewed 38421 provider event pubkey
79
+ * - `t`: review label, where `lgtm` means the node looks good
80
+ *
81
+ * @param baseUrls Current provider base URLs to evaluate
82
+ * @returns Array of provider base URLs disabled by the review set
83
+ */
84
+ syncReviewedProvidersFromNostr(baseUrls?: string[], providerNodes?: Map<string, Set<string>>): Promise<string[]>;
85
+ private addProviderNode;
86
+ /**
87
+ * Fetch models from all providers and select best-priced options
88
+ * Uses cache if available and not expired
89
+ * @param baseUrls List of provider base URLs to fetch from
90
+ * @param forceRefresh Ignore cache and fetch fresh data
91
+ * @param onProgress Callback fired after each provider completes with current combined models
92
+ * @returns Array of unique models with best prices selected
93
+ */
94
+ fetchModels(baseUrls: string[], forceRefresh?: boolean, onProgress?: (models: Model[]) => void): Promise<Model[]>;
95
+ /**
96
+ * Fetch models from a single provider
97
+ * @param baseUrl Provider base URL
98
+ * @returns Array of models from provider
99
+ */
100
+ private fetchModelsFromProvider;
101
+ private isProviderDownError;
102
+ /**
103
+ * Get all cached models from all providers
104
+ * @returns Record mapping baseUrl -> models
105
+ */
106
+ getAllCachedModels(): Record<string, Model[]>;
107
+ /**
108
+ * Clear cache for a specific provider
109
+ * @param baseUrl Provider base URL
110
+ */
111
+ clearProviderCache(baseUrl: string): void;
112
+ /**
113
+ * Clear all model caches
114
+ */
115
+ clearAllCache(): void;
116
+ /**
117
+ * Filter base URLs based on Tor context
118
+ * @param baseUrls Provider URLs to filter
119
+ * @param torMode Whether in Tor context
120
+ * @returns Filtered URLs appropriate for Tor mode
121
+ */
122
+ filterBaseUrlsForTor(baseUrls: string[], torMode: boolean): string[];
123
+ /**
124
+ * Get provider endpoints from provider info
125
+ * @param provider Provider object from directory
126
+ * @param torMode Whether in Tor context
127
+ * @returns Array of endpoint URLs
128
+ */
129
+ private getProviderEndpoints;
130
+ /**
131
+ * Normalize provider URL with trailing slash
132
+ * @param url URL to normalize
133
+ * @returns Normalized URL
134
+ */
135
+ private normalizeUrl;
136
+ /**
137
+ * Fetch routstr21 models from Nostr network (kind 38423)
138
+ * Uses cache if available and not expired
139
+ * @returns Array of model IDs or empty array if not found
140
+ */
141
+ fetchRoutstr21Models(forceRefresh?: boolean): Promise<string[]>;
142
+ }
143
+
144
+ /**
145
+ * MintDiscovery class for discovering mints and provider info
146
+ * Core responsibility: fetching mint information from providers and caching it
147
+ */
148
+
149
+ /**
150
+ * Configuration for MintDiscovery
151
+ */
152
+ interface MintDiscoveryConfig {
153
+ /** Cache TTL in milliseconds (default: 21 minutes) */
154
+ cacheTTL?: number;
155
+ /** Optional injectable logger */
156
+ logger?: SdkLogger;
157
+ }
158
+ /**
159
+ * MintDiscovery handles mint and provider info discovery
160
+ * Abstracts away storage details via DiscoveryAdapter
161
+ */
162
+ declare class MintDiscovery {
163
+ private adapter;
164
+ private readonly cacheTTL;
165
+ private readonly logger;
166
+ constructor(adapter: DiscoveryAdapter, config?: MintDiscoveryConfig);
167
+ /**
168
+ * Fetch mints from all providers via their /v1/info endpoints
169
+ * Caches mints and full provider info for later access
170
+ * @param baseUrls List of provider base URLs to fetch from
171
+ * @returns Object with mints and provider info from all providers
172
+ */
173
+ discoverMints(baseUrls: string[], options?: {
174
+ forceRefresh?: boolean;
175
+ }): Promise<{
176
+ mintsFromProviders: Record<string, string[]>;
177
+ infoFromProviders: Record<string, ProviderInfo>;
178
+ }>;
179
+ /**
180
+ * Get cached mints from all providers
181
+ * @returns Record mapping baseUrl -> mint URLs
182
+ */
183
+ getCachedMints(): Record<string, string[]>;
184
+ /**
185
+ * Get cached provider info from all providers
186
+ * @returns Record mapping baseUrl -> provider info
187
+ */
188
+ getCachedProviderInfo(): Record<string, ProviderInfo>;
189
+ /**
190
+ * Get mints for a specific provider
191
+ * @param baseUrl Provider base URL
192
+ * @returns Array of mint URLs for the provider
193
+ */
194
+ getProviderMints(baseUrl: string): string[];
195
+ /**
196
+ * Get info for a specific provider
197
+ * @param baseUrl Provider base URL
198
+ * @returns Provider info object or null if not found
199
+ */
200
+ getProviderInfo(baseUrl: string): ProviderInfo | null;
201
+ /**
202
+ * Clear mint cache for a specific provider
203
+ * @param baseUrl Provider base URL
204
+ */
205
+ clearProviderMintCache(baseUrl: string): void;
206
+ /**
207
+ * Clear all mint caches
208
+ */
209
+ clearAllCache(): void;
210
+ private isProviderDownError;
211
+ }
212
+
213
+ export { DiscoveryAdapter, MintDiscovery, ModelManager, type ModelManagerConfig, ProviderInfo };
@@ -0,0 +1,213 @@
1
+ import { D as DiscoveryAdapter } from '../interfaces-iL7CWeG5.js';
2
+ import { S as SdkLogger, e as Model, k as ProviderInfo } from '../types-_21yYFZG.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
+ /** Nostr pubkey for routstr review/model events (kind 38425/38423). Defaults to routstr's key. */
23
+ routstrPubkey?: string;
24
+ /** Optional injectable logger */
25
+ logger?: SdkLogger;
26
+ }
27
+ /**
28
+ * ModelManager handles all model discovery and caching logic
29
+ * Abstracts away storage details via DiscoveryAdapter
30
+ */
31
+ declare class ModelManager {
32
+ private adapter;
33
+ private readonly cacheTTL;
34
+ private readonly providerDirectoryUrl;
35
+ private readonly includeProviderUrls;
36
+ private readonly excludeProviderUrls;
37
+ private readonly routstrPubkey;
38
+ private readonly logger;
39
+ private providerNodePubkeysByUrl;
40
+ constructor(adapter: DiscoveryAdapter, config?: ModelManagerConfig);
41
+ /**
42
+ * Get the list of bootstrapped provider base URLs
43
+ * @returns Array of provider base URLs
44
+ */
45
+ getBaseUrls(): string[];
46
+ static init(adapter: DiscoveryAdapter, config?: ModelManagerConfig, options?: {
47
+ torMode?: boolean;
48
+ forceRefresh?: boolean;
49
+ }): Promise<ModelManager>;
50
+ /**
51
+ * Bootstrap provider list from the provider directory
52
+ * First tries to fetch from Nostr (kind 30421), falls back to HTTP
53
+ * @param torMode Whether running in Tor context
54
+ * @param forceRefresh Ignore provider cache and refresh provider sources
55
+ * @returns Array of provider base URLs
56
+ * @throws ProviderBootstrapError if all providers fail to fetch
57
+ */
58
+ bootstrapProviders(torMode?: boolean, forceRefresh?: boolean): Promise<string[]>;
59
+ /**
60
+ * Bootstrap providers from Nostr network (kind 30421)
61
+ * @param kind The Nostr kind to fetch
62
+ * @param torMode Whether running in Tor context
63
+ * @returns Array of provider base URLs
64
+ */
65
+ private bootstrapFromNostr;
66
+ /**
67
+ * Bootstrap providers from HTTP endpoint
68
+ * @param torMode Whether running in Tor context
69
+ * @param forceRefresh Ignore routstr21 cache and fetch fresh data
70
+ * @returns Array of provider base URLs
71
+ */
72
+ private bootstrapFromHttp;
73
+ /**
74
+ * Fetch Routstr review events from Nostr (kind 38425) and disable providers
75
+ * whose 38421 node pubkey does not have at least one review tagged `t=lgtm`.
76
+ *
77
+ * Review events are expected to have:
78
+ * - `node`: the reviewed 38421 provider event pubkey
79
+ * - `t`: review label, where `lgtm` means the node looks good
80
+ *
81
+ * @param baseUrls Current provider base URLs to evaluate
82
+ * @returns Array of provider base URLs disabled by the review set
83
+ */
84
+ syncReviewedProvidersFromNostr(baseUrls?: string[], providerNodes?: Map<string, Set<string>>): Promise<string[]>;
85
+ private addProviderNode;
86
+ /**
87
+ * Fetch models from all providers and select best-priced options
88
+ * Uses cache if available and not expired
89
+ * @param baseUrls List of provider base URLs to fetch from
90
+ * @param forceRefresh Ignore cache and fetch fresh data
91
+ * @param onProgress Callback fired after each provider completes with current combined models
92
+ * @returns Array of unique models with best prices selected
93
+ */
94
+ fetchModels(baseUrls: string[], forceRefresh?: boolean, onProgress?: (models: Model[]) => void): Promise<Model[]>;
95
+ /**
96
+ * Fetch models from a single provider
97
+ * @param baseUrl Provider base URL
98
+ * @returns Array of models from provider
99
+ */
100
+ private fetchModelsFromProvider;
101
+ private isProviderDownError;
102
+ /**
103
+ * Get all cached models from all providers
104
+ * @returns Record mapping baseUrl -> models
105
+ */
106
+ getAllCachedModels(): Record<string, Model[]>;
107
+ /**
108
+ * Clear cache for a specific provider
109
+ * @param baseUrl Provider base URL
110
+ */
111
+ clearProviderCache(baseUrl: string): void;
112
+ /**
113
+ * Clear all model caches
114
+ */
115
+ clearAllCache(): void;
116
+ /**
117
+ * Filter base URLs based on Tor context
118
+ * @param baseUrls Provider URLs to filter
119
+ * @param torMode Whether in Tor context
120
+ * @returns Filtered URLs appropriate for Tor mode
121
+ */
122
+ filterBaseUrlsForTor(baseUrls: string[], torMode: boolean): string[];
123
+ /**
124
+ * Get provider endpoints from provider info
125
+ * @param provider Provider object from directory
126
+ * @param torMode Whether in Tor context
127
+ * @returns Array of endpoint URLs
128
+ */
129
+ private getProviderEndpoints;
130
+ /**
131
+ * Normalize provider URL with trailing slash
132
+ * @param url URL to normalize
133
+ * @returns Normalized URL
134
+ */
135
+ private normalizeUrl;
136
+ /**
137
+ * Fetch routstr21 models from Nostr network (kind 38423)
138
+ * Uses cache if available and not expired
139
+ * @returns Array of model IDs or empty array if not found
140
+ */
141
+ fetchRoutstr21Models(forceRefresh?: boolean): Promise<string[]>;
142
+ }
143
+
144
+ /**
145
+ * MintDiscovery class for discovering mints and provider info
146
+ * Core responsibility: fetching mint information from providers and caching it
147
+ */
148
+
149
+ /**
150
+ * Configuration for MintDiscovery
151
+ */
152
+ interface MintDiscoveryConfig {
153
+ /** Cache TTL in milliseconds (default: 21 minutes) */
154
+ cacheTTL?: number;
155
+ /** Optional injectable logger */
156
+ logger?: SdkLogger;
157
+ }
158
+ /**
159
+ * MintDiscovery handles mint and provider info discovery
160
+ * Abstracts away storage details via DiscoveryAdapter
161
+ */
162
+ declare class MintDiscovery {
163
+ private adapter;
164
+ private readonly cacheTTL;
165
+ private readonly logger;
166
+ constructor(adapter: DiscoveryAdapter, config?: MintDiscoveryConfig);
167
+ /**
168
+ * Fetch mints from all providers via their /v1/info endpoints
169
+ * Caches mints and full provider info for later access
170
+ * @param baseUrls List of provider base URLs to fetch from
171
+ * @returns Object with mints and provider info from all providers
172
+ */
173
+ discoverMints(baseUrls: string[], options?: {
174
+ forceRefresh?: boolean;
175
+ }): Promise<{
176
+ mintsFromProviders: Record<string, string[]>;
177
+ infoFromProviders: Record<string, ProviderInfo>;
178
+ }>;
179
+ /**
180
+ * Get cached mints from all providers
181
+ * @returns Record mapping baseUrl -> mint URLs
182
+ */
183
+ getCachedMints(): Record<string, string[]>;
184
+ /**
185
+ * Get cached provider info from all providers
186
+ * @returns Record mapping baseUrl -> provider info
187
+ */
188
+ getCachedProviderInfo(): Record<string, ProviderInfo>;
189
+ /**
190
+ * Get mints for a specific provider
191
+ * @param baseUrl Provider base URL
192
+ * @returns Array of mint URLs for the provider
193
+ */
194
+ getProviderMints(baseUrl: string): string[];
195
+ /**
196
+ * Get info for a specific provider
197
+ * @param baseUrl Provider base URL
198
+ * @returns Provider info object or null if not found
199
+ */
200
+ getProviderInfo(baseUrl: string): ProviderInfo | null;
201
+ /**
202
+ * Clear mint cache for a specific provider
203
+ * @param baseUrl Provider base URL
204
+ */
205
+ clearProviderMintCache(baseUrl: string): void;
206
+ /**
207
+ * Clear all mint caches
208
+ */
209
+ clearAllCache(): void;
210
+ private isProviderDownError;
211
+ }
212
+
213
+ export { DiscoveryAdapter, MintDiscovery, ModelManager, type ModelManagerConfig, ProviderInfo };