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