@routstr/sdk 0.3.5 → 0.3.7

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/package.json +2 -2
  2. package/dist/client/index.d.mts +0 -411
  3. package/dist/client/index.d.ts +0 -411
  4. package/dist/client/index.js +0 -4819
  5. package/dist/client/index.js.map +0 -1
  6. package/dist/client/index.mjs +0 -4813
  7. package/dist/client/index.mjs.map +0 -1
  8. package/dist/discovery/index.d.mts +0 -196
  9. package/dist/discovery/index.d.ts +0 -196
  10. package/dist/discovery/index.js +0 -616
  11. package/dist/discovery/index.js.map +0 -1
  12. package/dist/discovery/index.mjs +0 -613
  13. package/dist/discovery/index.mjs.map +0 -1
  14. package/dist/index.d.mts +0 -190
  15. package/dist/index.d.ts +0 -190
  16. package/dist/index.js +0 -6114
  17. package/dist/index.js.map +0 -1
  18. package/dist/index.mjs +0 -6065
  19. package/dist/index.mjs.map +0 -1
  20. package/dist/interfaces-Bp0Ngmqv.d.mts +0 -176
  21. package/dist/interfaces-CIfd_phZ.d.ts +0 -112
  22. package/dist/interfaces-Cxi8R4TT.d.mts +0 -112
  23. package/dist/interfaces-D2FDCLyP.d.ts +0 -176
  24. package/dist/storage/index.d.mts +0 -87
  25. package/dist/storage/index.d.ts +0 -87
  26. package/dist/storage/index.js +0 -1734
  27. package/dist/storage/index.js.map +0 -1
  28. package/dist/storage/index.mjs +0 -1712
  29. package/dist/storage/index.mjs.map +0 -1
  30. package/dist/store-BD5zF9Hp.d.ts +0 -172
  31. package/dist/store-CBSyK2qg.d.mts +0 -172
  32. package/dist/types-DPQM6tIG.d.mts +0 -234
  33. package/dist/types-DPQM6tIG.d.ts +0 -234
  34. package/dist/wallet/index.d.mts +0 -245
  35. package/dist/wallet/index.d.ts +0 -245
  36. package/dist/wallet/index.js +0 -1329
  37. package/dist/wallet/index.js.map +0 -1
  38. package/dist/wallet/index.mjs +0 -1326
  39. package/dist/wallet/index.mjs.map +0 -1
@@ -1,613 +0,0 @@
1
- import { RelayPool, onlyEvents } from 'applesauce-relay';
2
- import { EventStore } from 'applesauce-core';
3
- import { tap } from 'rxjs';
4
-
5
- // core/types.ts
6
- function makeConsoleLogger(prefix) {
7
- const fmt = (args) => prefix ? [prefix, ...args] : args;
8
- return {
9
- log: (...args) => console.log(...fmt(args)),
10
- warn: (...args) => console.warn(...fmt(args)),
11
- error: (...args) => console.error(...fmt(args)),
12
- debug: (...args) => console.log(...fmt(args)),
13
- child: (p) => makeConsoleLogger(prefix ? `${prefix}:${p}` : p)
14
- };
15
- }
16
- var consoleLogger = makeConsoleLogger();
17
-
18
- // core/errors.ts
19
- var ProviderBootstrapError = class extends Error {
20
- constructor(failedProviders, message) {
21
- super(
22
- message || `Failed to bootstrap providers. Tried: ${failedProviders.join(", ")}`
23
- );
24
- this.failedProviders = failedProviders;
25
- this.name = "ProviderBootstrapError";
26
- }
27
- };
28
- var NoProvidersAvailableError = class extends Error {
29
- constructor() {
30
- super("No providers are available for model discovery");
31
- this.name = "NoProvidersAvailableError";
32
- }
33
- };
34
- var ModelManager = class _ModelManager {
35
- constructor(adapter, config = {}) {
36
- this.adapter = adapter;
37
- this.providerDirectoryUrl = config.providerDirectoryUrl || "https://api.routstr.com/v1/providers/";
38
- this.cacheTTL = config.cacheTTL || 210 * 60 * 1e3;
39
- this.includeProviderUrls = config.includeProviderUrls || [];
40
- this.excludeProviderUrls = config.excludeProviderUrls || [];
41
- this.logger = (config.logger ?? consoleLogger).child("ModelManager");
42
- }
43
- cacheTTL;
44
- providerDirectoryUrl;
45
- includeProviderUrls;
46
- excludeProviderUrls;
47
- logger;
48
- /**
49
- * Get the list of bootstrapped provider base URLs
50
- * @returns Array of provider base URLs
51
- */
52
- getBaseUrls() {
53
- return this.adapter.getBaseUrlsList();
54
- }
55
- static async init(adapter, config = {}, options = {}) {
56
- const manager = new _ModelManager(adapter, config);
57
- const torMode = options.torMode ?? false;
58
- const forceRefresh = options.forceRefresh ?? false;
59
- const providers = await manager.bootstrapProviders(torMode, forceRefresh);
60
- await manager.fetchModels(providers, forceRefresh);
61
- return manager;
62
- }
63
- /**
64
- * Bootstrap provider list from the provider directory
65
- * First tries to fetch from Nostr (kind 30421), falls back to HTTP
66
- * @param torMode Whether running in Tor context
67
- * @param forceRefresh Ignore provider cache and refresh provider sources
68
- * @returns Array of provider base URLs
69
- * @throws ProviderBootstrapError if all providers fail to fetch
70
- */
71
- async bootstrapProviders(torMode = false, forceRefresh = false) {
72
- if (!forceRefresh) {
73
- const cachedUrls = this.adapter.getBaseUrlsList();
74
- if (cachedUrls.length > 0) {
75
- const lastUpdate = this.adapter.getBaseUrlsLastUpdate();
76
- const cacheValid = lastUpdate && Date.now() - lastUpdate <= this.cacheTTL;
77
- if (cacheValid) {
78
- await this.fetchRoutstr21Models(forceRefresh);
79
- return this.filterBaseUrlsForTor(cachedUrls, torMode);
80
- }
81
- }
82
- }
83
- try {
84
- const nostrProviders = await this.bootstrapFromNostr(38421, torMode);
85
- if (nostrProviders.length > 0) {
86
- const filtered = this.filterBaseUrlsForTor(nostrProviders, torMode);
87
- this.adapter.setBaseUrlsList(filtered);
88
- this.adapter.setBaseUrlsLastUpdate(Date.now());
89
- await this.fetchRoutstr21Models(forceRefresh);
90
- return filtered;
91
- }
92
- } catch (e) {
93
- this.logger.warn("Nostr bootstrap failed, falling back to HTTP:", e);
94
- }
95
- return this.bootstrapFromHttp(torMode, forceRefresh);
96
- }
97
- /**
98
- * Bootstrap providers from Nostr network (kind 30421)
99
- * @param kind The Nostr kind to fetch
100
- * @param torMode Whether running in Tor context
101
- * @returns Array of provider base URLs
102
- */
103
- async bootstrapFromNostr(kind, torMode) {
104
- const DEFAULT_RELAYS = [
105
- "wss://relay.primal.net",
106
- "wss://nos.lol",
107
- "wss://relay.damus.io"
108
- ];
109
- const pool = new RelayPool();
110
- const localEventStore = new EventStore();
111
- const timeoutMs = 5e3;
112
- await new Promise((resolve) => {
113
- pool.req(DEFAULT_RELAYS, {
114
- kinds: [kind],
115
- limit: 100
116
- }).pipe(
117
- onlyEvents(),
118
- tap((event) => {
119
- localEventStore.add(event);
120
- })
121
- ).subscribe({
122
- complete: () => {
123
- resolve();
124
- }
125
- });
126
- setTimeout(() => {
127
- resolve();
128
- }, timeoutMs);
129
- });
130
- const timeline = localEventStore.getTimeline({ kinds: [kind] });
131
- const bases = /* @__PURE__ */ new Set();
132
- for (const event of timeline) {
133
- const eventUrls = [];
134
- for (const tag of event.tags) {
135
- if (tag[0] === "u" && typeof tag[1] === "string") {
136
- eventUrls.push(tag[1]);
137
- }
138
- }
139
- if (eventUrls.length > 0) {
140
- for (const url of eventUrls) {
141
- const normalized = this.normalizeUrl(url);
142
- if (!torMode || normalized.includes(".onion")) {
143
- bases.add(normalized);
144
- }
145
- }
146
- continue;
147
- }
148
- try {
149
- const content = JSON.parse(event.content);
150
- const providers = Array.isArray(content) ? content : content.providers || [];
151
- for (const p of providers) {
152
- const endpoints = this.getProviderEndpoints(p, torMode);
153
- for (const endpoint of endpoints) {
154
- bases.add(endpoint);
155
- }
156
- }
157
- } catch {
158
- try {
159
- const providers = JSON.parse(event.content);
160
- if (Array.isArray(providers)) {
161
- for (const p of providers) {
162
- const endpoints = this.getProviderEndpoints(p, torMode);
163
- for (const endpoint of endpoints) {
164
- bases.add(endpoint);
165
- }
166
- }
167
- }
168
- } catch {
169
- this.logger.warn("NostrBootstrap: failed to parse event content:", event.id);
170
- }
171
- }
172
- }
173
- for (const url of this.includeProviderUrls) {
174
- const normalized = this.normalizeUrl(url);
175
- if (!torMode || normalized.includes(".onion")) {
176
- bases.add(normalized);
177
- }
178
- }
179
- const excluded = new Set(
180
- this.excludeProviderUrls.map((url) => this.normalizeUrl(url))
181
- );
182
- const result = Array.from(bases).filter((base) => !excluded.has(base));
183
- return result;
184
- }
185
- /**
186
- * Bootstrap providers from HTTP endpoint
187
- * @param torMode Whether running in Tor context
188
- * @param forceRefresh Ignore routstr21 cache and fetch fresh data
189
- * @returns Array of provider base URLs
190
- */
191
- async bootstrapFromHttp(torMode, forceRefresh = false) {
192
- try {
193
- const res = await fetch(this.providerDirectoryUrl);
194
- if (!res.ok) {
195
- throw new Error(`Failed to fetch providers: ${res.status}`);
196
- }
197
- const data = await res.json();
198
- const providers = Array.isArray(data?.providers) ? data.providers : [];
199
- const bases = /* @__PURE__ */ new Set();
200
- for (const p of providers) {
201
- const endpoints = this.getProviderEndpoints(p, torMode);
202
- for (const endpoint of endpoints) {
203
- bases.add(endpoint);
204
- }
205
- }
206
- for (const url of this.includeProviderUrls) {
207
- const normalized = this.normalizeUrl(url);
208
- if (!torMode || normalized.includes(".onion")) {
209
- bases.add(normalized);
210
- }
211
- }
212
- const excluded = new Set(
213
- this.excludeProviderUrls.map((url) => this.normalizeUrl(url))
214
- );
215
- const list = Array.from(bases).filter((base) => !excluded.has(base));
216
- if (list.length > 0) {
217
- this.adapter.setBaseUrlsList(list);
218
- this.adapter.setBaseUrlsLastUpdate(Date.now());
219
- await this.fetchRoutstr21Models(forceRefresh);
220
- }
221
- return list;
222
- } catch (e) {
223
- this.logger.error("Failed to bootstrap providers", e);
224
- throw new ProviderBootstrapError([], `Provider bootstrap failed: ${e}`);
225
- }
226
- }
227
- /**
228
- * Fetch models from all providers and select best-priced options
229
- * Uses cache if available and not expired
230
- * @param baseUrls List of provider base URLs to fetch from
231
- * @param forceRefresh Ignore cache and fetch fresh data
232
- * @param onProgress Callback fired after each provider completes with current combined models
233
- * @returns Array of unique models with best prices selected
234
- */
235
- async fetchModels(baseUrls, forceRefresh = false, onProgress) {
236
- if (baseUrls.length === 0) {
237
- throw new NoProvidersAvailableError();
238
- }
239
- const bestById = /* @__PURE__ */ new Map();
240
- const modelsFromAllProviders = {};
241
- const disabledProviders = this.adapter.getDisabledProviders();
242
- const estimateMinCost = (m) => {
243
- return m?.sats_pricing?.completion ?? 0;
244
- };
245
- const emitProgress = () => {
246
- if (onProgress) {
247
- const currentModels = Array.from(bestById.values()).map((v) => v.model);
248
- onProgress(currentModels);
249
- }
250
- };
251
- const fetchPromises = baseUrls.map(async (url) => {
252
- const base = url.endsWith("/") ? url : `${url}/`;
253
- try {
254
- let list;
255
- if (!forceRefresh) {
256
- const lastUpdate = this.adapter.getProviderLastUpdate(base);
257
- const cacheValid = lastUpdate && Date.now() - lastUpdate <= this.cacheTTL;
258
- if (cacheValid) {
259
- const cachedModels = this.adapter.getCachedModels();
260
- const cachedList = cachedModels[base] || [];
261
- list = cachedList;
262
- } else {
263
- list = await this.fetchModelsFromProvider(base);
264
- }
265
- } else {
266
- list = await this.fetchModelsFromProvider(base);
267
- }
268
- modelsFromAllProviders[base] = list;
269
- this.adapter.setProviderLastUpdate(base, Date.now());
270
- if (!disabledProviders.includes(base)) {
271
- for (const m of list) {
272
- const existing = bestById.get(m.id);
273
- if (!m.sats_pricing) continue;
274
- if (!existing) {
275
- bestById.set(m.id, { model: m, base });
276
- continue;
277
- }
278
- const currentCost = estimateMinCost(m);
279
- const existingCost = estimateMinCost(existing.model);
280
- if (currentCost < existingCost && m.sats_pricing) {
281
- bestById.set(m.id, { model: m, base });
282
- }
283
- }
284
- }
285
- emitProgress();
286
- return { success: true, base, list };
287
- } catch (error) {
288
- if (this.isProviderDownError(error)) {
289
- this.logger.warn(`Provider ${base} is down right now.`);
290
- } else {
291
- this.logger.warn(`Failed to fetch models from ${base}:`, error);
292
- }
293
- this.adapter.setProviderLastUpdate(base, Date.now());
294
- return { success: false, base };
295
- }
296
- });
297
- await Promise.allSettled(fetchPromises);
298
- const existingCache = this.adapter.getCachedModels();
299
- this.adapter.setCachedModels({
300
- ...existingCache,
301
- ...modelsFromAllProviders
302
- });
303
- return Array.from(bestById.values()).map((v) => v.model);
304
- }
305
- /**
306
- * Fetch models from a single provider
307
- * @param baseUrl Provider base URL
308
- * @returns Array of models from provider
309
- */
310
- async fetchModelsFromProvider(baseUrl) {
311
- const res = await fetch(`${baseUrl}v1/models`);
312
- if (!res.ok) {
313
- throw new Error(`Failed to fetch models: ${res.status}`);
314
- }
315
- const json = await res.json();
316
- const list = Array.isArray(json?.data) ? json.data : [];
317
- return list;
318
- }
319
- isProviderDownError(error) {
320
- if (!(error instanceof Error)) return false;
321
- const msg = error.message.toLowerCase();
322
- if (msg.includes("fetch failed")) return true;
323
- if (msg.includes("429")) return true;
324
- if (msg.includes("502")) return true;
325
- if (msg.includes("503")) return true;
326
- if (msg.includes("504")) return true;
327
- const cause = error.cause;
328
- return cause?.code === "ENOTFOUND";
329
- }
330
- /**
331
- * Get all cached models from all providers
332
- * @returns Record mapping baseUrl -> models
333
- */
334
- getAllCachedModels() {
335
- return this.adapter.getCachedModels();
336
- }
337
- /**
338
- * Clear cache for a specific provider
339
- * @param baseUrl Provider base URL
340
- */
341
- clearProviderCache(baseUrl) {
342
- const base = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
343
- const cached = this.adapter.getCachedModels();
344
- delete cached[base];
345
- this.adapter.setCachedModels(cached);
346
- this.adapter.setProviderLastUpdate(base, 0);
347
- }
348
- /**
349
- * Clear all model caches
350
- */
351
- clearAllCache() {
352
- this.adapter.setCachedModels({});
353
- }
354
- /**
355
- * Filter base URLs based on Tor context
356
- * @param baseUrls Provider URLs to filter
357
- * @param torMode Whether in Tor context
358
- * @returns Filtered URLs appropriate for Tor mode
359
- */
360
- filterBaseUrlsForTor(baseUrls, torMode) {
361
- if (!torMode) {
362
- return baseUrls.filter((url) => !url.includes(".onion"));
363
- }
364
- return baseUrls.filter((url) => url.includes(".onion"));
365
- }
366
- /**
367
- * Get provider endpoints from provider info
368
- * @param provider Provider object from directory
369
- * @param torMode Whether in Tor context
370
- * @returns Array of endpoint URLs
371
- */
372
- getProviderEndpoints(provider, torMode) {
373
- const endpoints = [];
374
- if (torMode && provider.onion_url) {
375
- endpoints.push(this.normalizeUrl(provider.onion_url));
376
- } else if (provider.endpoint_url) {
377
- endpoints.push(this.normalizeUrl(provider.endpoint_url));
378
- }
379
- return endpoints;
380
- }
381
- /**
382
- * Normalize provider URL with trailing slash
383
- * @param url URL to normalize
384
- * @returns Normalized URL
385
- */
386
- normalizeUrl(url) {
387
- if (!url.startsWith("http")) {
388
- url = `https://${url}`;
389
- }
390
- return url.endsWith("/") ? url : `${url}/`;
391
- }
392
- /**
393
- * Fetch routstr21 models from Nostr network (kind 38423)
394
- * Uses cache if available and not expired
395
- * @returns Array of model IDs or empty array if not found
396
- */
397
- async fetchRoutstr21Models(forceRefresh = false) {
398
- const cachedModels = this.adapter.getRoutstr21Models();
399
- if (!forceRefresh && cachedModels.length > 0) {
400
- const lastUpdate = this.adapter.getRoutstr21ModelsLastUpdate();
401
- const cacheValid = lastUpdate && Date.now() - lastUpdate <= this.cacheTTL;
402
- if (cacheValid) {
403
- return cachedModels;
404
- }
405
- }
406
- const DEFAULT_RELAYS = [
407
- "wss://relay.damus.io",
408
- "wss://nos.lol",
409
- "wss://relay.routstr.com"
410
- ];
411
- const pool = new RelayPool();
412
- const localEventStore = new EventStore();
413
- const timeoutMs = 5e3;
414
- await new Promise((resolve) => {
415
- pool.req(DEFAULT_RELAYS, {
416
- kinds: [38423],
417
- "#d": ["routstr-21-models"],
418
- limit: 1,
419
- authors: [
420
- "4ad6fa2d16e2a9b576c863b4cf7404a70d4dc320c0c447d10ad6ff58993eacc8"
421
- ]
422
- }).pipe(
423
- onlyEvents(),
424
- tap((event2) => {
425
- localEventStore.add(event2);
426
- })
427
- ).subscribe({
428
- complete: () => {
429
- resolve();
430
- }
431
- });
432
- setTimeout(() => {
433
- resolve();
434
- }, timeoutMs);
435
- });
436
- const timeline = localEventStore.getTimeline({ kinds: [38423] });
437
- if (timeline.length === 0) {
438
- return cachedModels.length > 0 ? cachedModels : [];
439
- }
440
- const event = timeline[0];
441
- try {
442
- const content = JSON.parse(event.content);
443
- const models = Array.isArray(content?.models) ? content.models : [];
444
- this.adapter.setRoutstr21Models(models);
445
- this.adapter.setRoutstr21ModelsLastUpdate(Date.now());
446
- return models;
447
- } catch {
448
- this.logger.warn("Routstr21Models: failed to parse Nostr event content:", event.id);
449
- return cachedModels.length > 0 ? cachedModels : [];
450
- }
451
- }
452
- };
453
-
454
- // discovery/MintDiscovery.ts
455
- var MintDiscovery = class {
456
- constructor(adapter, config = {}) {
457
- this.adapter = adapter;
458
- this.cacheTTL = config.cacheTTL || 21 * 60 * 1e3;
459
- this.logger = (config.logger ?? consoleLogger).child("MintDiscovery");
460
- }
461
- cacheTTL;
462
- logger;
463
- /**
464
- * Fetch mints from all providers via their /v1/info endpoints
465
- * Caches mints and full provider info for later access
466
- * @param baseUrls List of provider base URLs to fetch from
467
- * @returns Object with mints and provider info from all providers
468
- */
469
- async discoverMints(baseUrls, options = {}) {
470
- if (baseUrls.length === 0) {
471
- return { mintsFromProviders: {}, infoFromProviders: {} };
472
- }
473
- const mintsFromAllProviders = {};
474
- const infoFromAllProviders = {};
475
- const forceRefresh = options.forceRefresh ?? false;
476
- const fetchPromises = baseUrls.map(async (url) => {
477
- const base = url.endsWith("/") ? url : `${url}/`;
478
- try {
479
- if (!forceRefresh) {
480
- const lastUpdate = this.adapter.getProviderLastUpdate(base);
481
- const cacheValid = lastUpdate && Date.now() - lastUpdate <= this.cacheTTL;
482
- if (cacheValid) {
483
- const cachedMints = this.adapter.getCachedMints()[base] || [];
484
- const cachedInfo = this.adapter.getCachedProviderInfo()[base];
485
- mintsFromAllProviders[base] = cachedMints;
486
- if (cachedInfo) {
487
- infoFromAllProviders[base] = cachedInfo;
488
- }
489
- return {
490
- success: true,
491
- base,
492
- mints: cachedMints,
493
- info: cachedInfo
494
- };
495
- }
496
- }
497
- const res = await fetch(`${base}v1/info`);
498
- if (!res.ok) {
499
- throw new Error(`Failed to fetch info: ${res.status}`);
500
- }
501
- const json = await res.json();
502
- const mints = Array.isArray(json?.mints) ? json.mints : [];
503
- const normalizedMints = mints.map(
504
- (mint) => mint.endsWith("/") ? mint.slice(0, -1) : mint
505
- );
506
- mintsFromAllProviders[base] = normalizedMints;
507
- infoFromAllProviders[base] = json;
508
- this.adapter.setProviderLastUpdate(base, Date.now());
509
- return { success: true, base, mints: normalizedMints, info: json };
510
- } catch (error) {
511
- this.adapter.setProviderLastUpdate(base, Date.now());
512
- if (this.isProviderDownError(error)) {
513
- this.logger.warn(`Provider ${base} is down right now.`);
514
- } else {
515
- this.logger.warn(`Failed to fetch mints from ${base}:`, error);
516
- }
517
- return { success: false, base, mints: [], info: null };
518
- }
519
- });
520
- const results = await Promise.allSettled(fetchPromises);
521
- for (const result of results) {
522
- if (result.status === "fulfilled") {
523
- const { base, mints, info } = result.value;
524
- mintsFromAllProviders[base] = mints;
525
- if (info) {
526
- infoFromAllProviders[base] = info;
527
- }
528
- } else {
529
- this.logger.error("Mint discovery error:", result.reason);
530
- }
531
- }
532
- try {
533
- this.adapter.setCachedMints(mintsFromAllProviders);
534
- this.adapter.setCachedProviderInfo(infoFromAllProviders);
535
- } catch (error) {
536
- this.logger.error("Error caching mint discovery results:", error);
537
- }
538
- return {
539
- mintsFromProviders: mintsFromAllProviders,
540
- infoFromProviders: infoFromAllProviders
541
- };
542
- }
543
- /**
544
- * Get cached mints from all providers
545
- * @returns Record mapping baseUrl -> mint URLs
546
- */
547
- getCachedMints() {
548
- return this.adapter.getCachedMints();
549
- }
550
- /**
551
- * Get cached provider info from all providers
552
- * @returns Record mapping baseUrl -> provider info
553
- */
554
- getCachedProviderInfo() {
555
- return this.adapter.getCachedProviderInfo();
556
- }
557
- /**
558
- * Get mints for a specific provider
559
- * @param baseUrl Provider base URL
560
- * @returns Array of mint URLs for the provider
561
- */
562
- getProviderMints(baseUrl) {
563
- const normalized = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
564
- const allMints = this.getCachedMints();
565
- return allMints[normalized] || [];
566
- }
567
- /**
568
- * Get info for a specific provider
569
- * @param baseUrl Provider base URL
570
- * @returns Provider info object or null if not found
571
- */
572
- getProviderInfo(baseUrl) {
573
- const normalized = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
574
- const allInfo = this.getCachedProviderInfo();
575
- return allInfo[normalized] || null;
576
- }
577
- /**
578
- * Clear mint cache for a specific provider
579
- * @param baseUrl Provider base URL
580
- */
581
- clearProviderMintCache(baseUrl) {
582
- const normalized = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
583
- const mints = this.getCachedMints();
584
- delete mints[normalized];
585
- this.adapter.setCachedMints(mints);
586
- const info = this.getCachedProviderInfo();
587
- delete info[normalized];
588
- this.adapter.setCachedProviderInfo(info);
589
- }
590
- /**
591
- * Clear all mint caches
592
- */
593
- clearAllCache() {
594
- this.adapter.setCachedMints({});
595
- this.adapter.setCachedProviderInfo({});
596
- }
597
- isProviderDownError(error) {
598
- if (!(error instanceof Error)) return false;
599
- const msg = error.message.toLowerCase();
600
- if (msg.includes("fetch failed")) return true;
601
- if (msg.includes("429")) return true;
602
- if (msg.includes("502")) return true;
603
- if (msg.includes("503")) return true;
604
- if (msg.includes("504")) return true;
605
- const cause = error.cause;
606
- if (cause?.code === "ENOTFOUND") return true;
607
- return false;
608
- }
609
- };
610
-
611
- export { MintDiscovery, ModelManager };
612
- //# sourceMappingURL=index.mjs.map
613
- //# sourceMappingURL=index.mjs.map