@routstr/sdk 0.3.9 → 0.3.11
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/browser.d.mts +12 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.js +6413 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.mjs +6361 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/bun.d.mts +29 -0
- package/dist/bun.d.ts +29 -0
- package/dist/bun.js +6791 -0
- package/dist/bun.js.map +1 -0
- package/dist/bun.mjs +6733 -0
- package/dist/bun.mjs.map +1 -0
- package/dist/bunSqlite-BmXWNc25.d.ts +18 -0
- package/dist/bunSqlite-Bro9efsl.d.mts +18 -0
- package/dist/client/index.d.mts +85 -42
- package/dist/client/index.d.ts +85 -42
- package/dist/client/index.js +1243 -1584
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +1239 -1585
- package/dist/client/index.mjs.map +1 -1
- package/dist/discovery/index.d.mts +33 -3
- package/dist/discovery/index.d.ts +33 -3
- package/dist/discovery/index.js +30 -31
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +30 -31
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/index.d.mts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.js +1264 -1648
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1260 -1645
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +22 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.js +6857 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +6801 -0
- package/dist/node.mjs.map +1 -0
- package/dist/storage/bun.d.mts +16 -0
- package/dist/storage/bun.d.ts +16 -0
- package/dist/storage/bun.js +1970 -0
- package/dist/storage/bun.js.map +1 -0
- package/dist/storage/bun.mjs +1946 -0
- package/dist/storage/bun.mjs.map +1 -0
- package/dist/storage/index.d.mts +4 -30
- package/dist/storage/index.d.ts +4 -30
- package/dist/storage/index.js +238 -650
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +239 -647
- package/dist/storage/index.mjs.map +1 -1
- package/dist/storage/node.d.mts +22 -0
- package/dist/storage/node.d.ts +22 -0
- package/dist/storage/node.js +2034 -0
- package/dist/storage/node.js.map +1 -0
- package/dist/storage/node.mjs +2012 -0
- package/dist/storage/node.mjs.map +1 -0
- package/dist/{store-58VcEUoA.d.ts → store-CAQLSbEj.d.ts} +52 -1
- package/dist/{store-C6dfj1cc.d.mts → store-CuXwe5Rg.d.mts} +52 -1
- package/dist/wallet/index.js +38 -24
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +38 -24
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +26 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { D as DiscoveryAdapter } from '../interfaces-Cv1k2EUK.mjs';
|
|
2
2
|
import { S as SdkLogger, e as Model, k as ProviderInfo } from '../types-_21yYFZG.mjs';
|
|
3
|
-
import { EventStore } from 'applesauce-core';
|
|
3
|
+
import { IEventDatabase, EventStore } from 'applesauce-core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* ModelManager class for discovering, fetching, and managing models from providers
|
|
@@ -8,6 +8,18 @@ import { EventStore } from 'applesauce-core';
|
|
|
8
8
|
* (lowest cost) across multiple providers
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
type SqliteStatement = {
|
|
12
|
+
run?: (...params: any[]) => unknown;
|
|
13
|
+
get?: (...params: any[]) => any;
|
|
14
|
+
};
|
|
15
|
+
type PersistentEventDatabase = IEventDatabase & {
|
|
16
|
+
db?: {
|
|
17
|
+
exec: (sql: string) => void;
|
|
18
|
+
prepare: (sql: string) => SqliteStatement;
|
|
19
|
+
};
|
|
20
|
+
close?: () => void;
|
|
21
|
+
};
|
|
22
|
+
type PersistentEventDatabaseFactory = (dbPath: string) => Promise<PersistentEventDatabase> | PersistentEventDatabase;
|
|
11
23
|
/**
|
|
12
24
|
* Configuration for ModelManager
|
|
13
25
|
*/
|
|
@@ -22,13 +34,24 @@ interface ModelManagerConfig {
|
|
|
22
34
|
cacheTTL?: number;
|
|
23
35
|
/** Nostr pubkey for routstr review/model events (kind 38425/38423). Defaults to routstr's key. */
|
|
24
36
|
routstrPubkey?: string;
|
|
37
|
+
/** Nostr relay URLs for provider/model discovery.
|
|
38
|
+
* When set, these relays are used for all Nostr queries (kinds 38421, 38423, 38425).
|
|
39
|
+
* When unset, DEFAULT_NOSTR_RELAYS is used for all Nostr queries. */
|
|
40
|
+
nostrRelays?: string[];
|
|
25
41
|
/** Optional injectable logger */
|
|
26
42
|
logger?: SdkLogger;
|
|
27
|
-
/** Path to
|
|
43
|
+
/** Path to database for persistent Nostr event storage.
|
|
28
44
|
* If provided, events fetched by ModelManager from relays (kinds 38421,
|
|
29
45
|
* 38423, 38425) are persisted and survive process restarts. The underlying
|
|
30
|
-
* EventStore can also be accessed for advanced/manual event management.
|
|
46
|
+
* EventStore can also be accessed for advanced/manual event management.
|
|
47
|
+
*
|
|
48
|
+
* Runtime-specific SQLite implementations are intentionally not imported by
|
|
49
|
+
* the browser-safe default SDK entrypoint. Use @routstr/sdk/node or
|
|
50
|
+
* @routstr/sdk/bun to get a ModelManager preconfigured with a SQLite-backed
|
|
51
|
+
* persistentEventDatabaseFactory, or inject your own factory here. */
|
|
31
52
|
eventStoreDbPath?: string;
|
|
53
|
+
/** Factory used with eventStoreDbPath to create the persistent event DB. */
|
|
54
|
+
persistentEventDatabaseFactory?: PersistentEventDatabaseFactory;
|
|
32
55
|
}
|
|
33
56
|
/**
|
|
34
57
|
* ModelManager handles all model discovery and caching logic
|
|
@@ -41,6 +64,7 @@ declare class ModelManager {
|
|
|
41
64
|
private readonly includeProviderUrls;
|
|
42
65
|
private readonly excludeProviderUrls;
|
|
43
66
|
private readonly routstrPubkey;
|
|
67
|
+
private readonly nostrRelays;
|
|
44
68
|
private readonly logger;
|
|
45
69
|
private providerNodePubkeysByUrl;
|
|
46
70
|
/** Persistent event store for relay-fetched events (null if not configured/initialized) */
|
|
@@ -48,6 +72,7 @@ declare class ModelManager {
|
|
|
48
72
|
private eventStoreDb;
|
|
49
73
|
private eventStoreInitPromise;
|
|
50
74
|
private readonly eventStoreDbPath?;
|
|
75
|
+
private readonly persistentEventDatabaseFactory?;
|
|
51
76
|
constructor(adapter: DiscoveryAdapter, config?: ModelManagerConfig);
|
|
52
77
|
/**
|
|
53
78
|
* Get the list of bootstrapped provider base URLs
|
|
@@ -90,6 +115,11 @@ declare class ModelManager {
|
|
|
90
115
|
* @throws ProviderBootstrapError if all providers fail to fetch
|
|
91
116
|
*/
|
|
92
117
|
bootstrapProviders(torMode?: boolean, forceRefresh?: boolean): Promise<string[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Resolve Nostr relay URLs.
|
|
120
|
+
* Returns user-configured relays if set, otherwise the shared defaults.
|
|
121
|
+
*/
|
|
122
|
+
private getNostrRelays;
|
|
93
123
|
/**
|
|
94
124
|
* Bootstrap providers from Nostr network (kind 38421)
|
|
95
125
|
* @param kind The Nostr kind to fetch
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { D as DiscoveryAdapter } from '../interfaces-iL7CWeG5.js';
|
|
2
2
|
import { S as SdkLogger, e as Model, k as ProviderInfo } from '../types-_21yYFZG.js';
|
|
3
|
-
import { EventStore } from 'applesauce-core';
|
|
3
|
+
import { IEventDatabase, EventStore } from 'applesauce-core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* ModelManager class for discovering, fetching, and managing models from providers
|
|
@@ -8,6 +8,18 @@ import { EventStore } from 'applesauce-core';
|
|
|
8
8
|
* (lowest cost) across multiple providers
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
type SqliteStatement = {
|
|
12
|
+
run?: (...params: any[]) => unknown;
|
|
13
|
+
get?: (...params: any[]) => any;
|
|
14
|
+
};
|
|
15
|
+
type PersistentEventDatabase = IEventDatabase & {
|
|
16
|
+
db?: {
|
|
17
|
+
exec: (sql: string) => void;
|
|
18
|
+
prepare: (sql: string) => SqliteStatement;
|
|
19
|
+
};
|
|
20
|
+
close?: () => void;
|
|
21
|
+
};
|
|
22
|
+
type PersistentEventDatabaseFactory = (dbPath: string) => Promise<PersistentEventDatabase> | PersistentEventDatabase;
|
|
11
23
|
/**
|
|
12
24
|
* Configuration for ModelManager
|
|
13
25
|
*/
|
|
@@ -22,13 +34,24 @@ interface ModelManagerConfig {
|
|
|
22
34
|
cacheTTL?: number;
|
|
23
35
|
/** Nostr pubkey for routstr review/model events (kind 38425/38423). Defaults to routstr's key. */
|
|
24
36
|
routstrPubkey?: string;
|
|
37
|
+
/** Nostr relay URLs for provider/model discovery.
|
|
38
|
+
* When set, these relays are used for all Nostr queries (kinds 38421, 38423, 38425).
|
|
39
|
+
* When unset, DEFAULT_NOSTR_RELAYS is used for all Nostr queries. */
|
|
40
|
+
nostrRelays?: string[];
|
|
25
41
|
/** Optional injectable logger */
|
|
26
42
|
logger?: SdkLogger;
|
|
27
|
-
/** Path to
|
|
43
|
+
/** Path to database for persistent Nostr event storage.
|
|
28
44
|
* If provided, events fetched by ModelManager from relays (kinds 38421,
|
|
29
45
|
* 38423, 38425) are persisted and survive process restarts. The underlying
|
|
30
|
-
* EventStore can also be accessed for advanced/manual event management.
|
|
46
|
+
* EventStore can also be accessed for advanced/manual event management.
|
|
47
|
+
*
|
|
48
|
+
* Runtime-specific SQLite implementations are intentionally not imported by
|
|
49
|
+
* the browser-safe default SDK entrypoint. Use @routstr/sdk/node or
|
|
50
|
+
* @routstr/sdk/bun to get a ModelManager preconfigured with a SQLite-backed
|
|
51
|
+
* persistentEventDatabaseFactory, or inject your own factory here. */
|
|
31
52
|
eventStoreDbPath?: string;
|
|
53
|
+
/** Factory used with eventStoreDbPath to create the persistent event DB. */
|
|
54
|
+
persistentEventDatabaseFactory?: PersistentEventDatabaseFactory;
|
|
32
55
|
}
|
|
33
56
|
/**
|
|
34
57
|
* ModelManager handles all model discovery and caching logic
|
|
@@ -41,6 +64,7 @@ declare class ModelManager {
|
|
|
41
64
|
private readonly includeProviderUrls;
|
|
42
65
|
private readonly excludeProviderUrls;
|
|
43
66
|
private readonly routstrPubkey;
|
|
67
|
+
private readonly nostrRelays;
|
|
44
68
|
private readonly logger;
|
|
45
69
|
private providerNodePubkeysByUrl;
|
|
46
70
|
/** Persistent event store for relay-fetched events (null if not configured/initialized) */
|
|
@@ -48,6 +72,7 @@ declare class ModelManager {
|
|
|
48
72
|
private eventStoreDb;
|
|
49
73
|
private eventStoreInitPromise;
|
|
50
74
|
private readonly eventStoreDbPath?;
|
|
75
|
+
private readonly persistentEventDatabaseFactory?;
|
|
51
76
|
constructor(adapter: DiscoveryAdapter, config?: ModelManagerConfig);
|
|
52
77
|
/**
|
|
53
78
|
* Get the list of bootstrapped provider base URLs
|
|
@@ -90,6 +115,11 @@ declare class ModelManager {
|
|
|
90
115
|
* @throws ProviderBootstrapError if all providers fail to fetch
|
|
91
116
|
*/
|
|
92
117
|
bootstrapProviders(torMode?: boolean, forceRefresh?: boolean): Promise<string[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Resolve Nostr relay URLs.
|
|
120
|
+
* Returns user-configured relays if set, otherwise the shared defaults.
|
|
121
|
+
*/
|
|
122
|
+
private getNostrRelays;
|
|
93
123
|
/**
|
|
94
124
|
* Bootstrap providers from Nostr network (kind 38421)
|
|
95
125
|
* @param kind The Nostr kind to fetch
|
package/dist/discovery/index.js
CHANGED
|
@@ -34,9 +34,11 @@ var NoProvidersAvailableError = class extends Error {
|
|
|
34
34
|
this.name = "NoProvidersAvailableError";
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
var DEFAULT_NOSTR_RELAYS = [
|
|
38
|
+
"wss://relay.damus.io",
|
|
39
|
+
"wss://nos.lol",
|
|
40
|
+
"wss://relay.routstr.com"
|
|
41
|
+
];
|
|
40
42
|
var ModelManager = class _ModelManager {
|
|
41
43
|
constructor(adapter, config = {}) {
|
|
42
44
|
this.adapter = adapter;
|
|
@@ -45,8 +47,10 @@ var ModelManager = class _ModelManager {
|
|
|
45
47
|
this.includeProviderUrls = config.includeProviderUrls || [];
|
|
46
48
|
this.excludeProviderUrls = config.excludeProviderUrls || [];
|
|
47
49
|
this.routstrPubkey = config.routstrPubkey || "4ad6fa2d16e2a9b576c863b4cf7404a70d4dc320c0c447d10ad6ff58993eacc8";
|
|
50
|
+
this.nostrRelays = config.nostrRelays;
|
|
48
51
|
this.logger = (config.logger ?? consoleLogger).child("ModelManager");
|
|
49
52
|
this.eventStoreDbPath = config.eventStoreDbPath;
|
|
53
|
+
this.persistentEventDatabaseFactory = config.persistentEventDatabaseFactory;
|
|
50
54
|
}
|
|
51
55
|
adapter;
|
|
52
56
|
cacheTTL;
|
|
@@ -54,6 +58,7 @@ var ModelManager = class _ModelManager {
|
|
|
54
58
|
includeProviderUrls;
|
|
55
59
|
excludeProviderUrls;
|
|
56
60
|
routstrPubkey;
|
|
61
|
+
nostrRelays;
|
|
57
62
|
logger;
|
|
58
63
|
providerNodePubkeysByUrl = /* @__PURE__ */ new Map();
|
|
59
64
|
/** Persistent event store for relay-fetched events (null if not configured/initialized) */
|
|
@@ -61,6 +66,7 @@ var ModelManager = class _ModelManager {
|
|
|
61
66
|
eventStoreDb = null;
|
|
62
67
|
eventStoreInitPromise = null;
|
|
63
68
|
eventStoreDbPath;
|
|
69
|
+
persistentEventDatabaseFactory;
|
|
64
70
|
/**
|
|
65
71
|
* Get the list of bootstrapped provider base URLs
|
|
66
72
|
* @returns Array of provider base URLs
|
|
@@ -89,7 +95,7 @@ var ModelManager = class _ModelManager {
|
|
|
89
95
|
} catch (error) {
|
|
90
96
|
this.eventStoreInitPromise = null;
|
|
91
97
|
throw new Error(
|
|
92
|
-
`
|
|
98
|
+
`Persistent Nostr event storage requires a runtime-specific database factory. Use @routstr/sdk/node, @routstr/sdk/bun, inject persistentEventDatabaseFactory, or omit eventStoreDbPath. (${error})`
|
|
93
99
|
);
|
|
94
100
|
}
|
|
95
101
|
})();
|
|
@@ -104,16 +110,15 @@ var ModelManager = class _ModelManager {
|
|
|
104
110
|
return this.ensureEventStore();
|
|
105
111
|
}
|
|
106
112
|
async createPersistentEventDatabase() {
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
if (!this.eventStoreDbPath) {
|
|
114
|
+
throw new Error("eventStoreDbPath is required");
|
|
115
|
+
}
|
|
116
|
+
if (!this.persistentEventDatabaseFactory) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"persistentEventDatabaseFactory is required. Import ModelManager from @routstr/sdk/node or @routstr/sdk/bun for SQLite-backed persistent event storage."
|
|
111
119
|
);
|
|
112
120
|
}
|
|
113
|
-
|
|
114
|
-
return new BetterSqlite3EventDatabase(
|
|
115
|
-
this.eventStoreDbPath
|
|
116
|
-
);
|
|
121
|
+
return this.persistentEventDatabaseFactory(this.eventStoreDbPath);
|
|
117
122
|
}
|
|
118
123
|
/** Close the persistent event store database handle, if configured. */
|
|
119
124
|
closeEventStore() {
|
|
@@ -226,6 +231,13 @@ var ModelManager = class _ModelManager {
|
|
|
226
231
|
}
|
|
227
232
|
return this.bootstrapFromHttp(torMode, forceRefresh);
|
|
228
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Resolve Nostr relay URLs.
|
|
236
|
+
* Returns user-configured relays if set, otherwise the shared defaults.
|
|
237
|
+
*/
|
|
238
|
+
getNostrRelays() {
|
|
239
|
+
return this.nostrRelays && this.nostrRelays.length > 0 ? this.nostrRelays : DEFAULT_NOSTR_RELAYS;
|
|
240
|
+
}
|
|
229
241
|
/**
|
|
230
242
|
* Bootstrap providers from Nostr network (kind 38421)
|
|
231
243
|
* @param kind The Nostr kind to fetch
|
|
@@ -233,11 +245,7 @@ var ModelManager = class _ModelManager {
|
|
|
233
245
|
* @returns Array of provider base URLs
|
|
234
246
|
*/
|
|
235
247
|
async bootstrapFromNostr(kind, torMode, forceRefresh = false) {
|
|
236
|
-
const
|
|
237
|
-
"wss://relay.primal.net",
|
|
238
|
-
"wss://nos.lol",
|
|
239
|
-
"wss://relay.damus.io"
|
|
240
|
-
];
|
|
248
|
+
const relays = this.getNostrRelays();
|
|
241
249
|
const cached = await this.getCachedNostrEvents(
|
|
242
250
|
{ kinds: [kind] },
|
|
243
251
|
this.cacheTTL,
|
|
@@ -248,7 +256,7 @@ var ModelManager = class _ModelManager {
|
|
|
248
256
|
const pool = new applesauceRelay.RelayPool();
|
|
249
257
|
const timeoutMs = 5e3;
|
|
250
258
|
await new Promise((resolve) => {
|
|
251
|
-
pool.req(
|
|
259
|
+
pool.req(relays, {
|
|
252
260
|
kinds: [kind],
|
|
253
261
|
limit: 100
|
|
254
262
|
}).pipe(
|
|
@@ -420,16 +428,11 @@ var ModelManager = class _ModelManager {
|
|
|
420
428
|
);
|
|
421
429
|
let sessionEvents = cached;
|
|
422
430
|
if (cached.length === 0) {
|
|
423
|
-
const
|
|
424
|
-
"wss://relay.primal.net",
|
|
425
|
-
"wss://nos.lol",
|
|
426
|
-
"wss://relay.damus.io",
|
|
427
|
-
"wss://relay.routstr.com"
|
|
428
|
-
];
|
|
431
|
+
const lgtmRelays = this.getNostrRelays();
|
|
429
432
|
const pool = new applesauceRelay.RelayPool();
|
|
430
433
|
const timeoutMs = 5e3;
|
|
431
434
|
await new Promise((resolve) => {
|
|
432
|
-
pool.req(
|
|
435
|
+
pool.req(lgtmRelays, {
|
|
433
436
|
kinds: [38425],
|
|
434
437
|
"#t": ["lgtm"],
|
|
435
438
|
limit: 500,
|
|
@@ -671,11 +674,7 @@ var ModelManager = class _ModelManager {
|
|
|
671
674
|
return cachedModels;
|
|
672
675
|
}
|
|
673
676
|
}
|
|
674
|
-
const
|
|
675
|
-
"wss://relay.damus.io",
|
|
676
|
-
"wss://nos.lol",
|
|
677
|
-
"wss://relay.routstr.com"
|
|
678
|
-
];
|
|
677
|
+
const relays = this.getNostrRelays();
|
|
679
678
|
const cached = await this.getCachedNostrEvents(
|
|
680
679
|
{ kinds: [38423], "#d": ["routstr-21-models"], authors: [this.routstrPubkey] },
|
|
681
680
|
this.cacheTTL,
|
|
@@ -686,7 +685,7 @@ var ModelManager = class _ModelManager {
|
|
|
686
685
|
const pool = new applesauceRelay.RelayPool();
|
|
687
686
|
const timeoutMs = 5e3;
|
|
688
687
|
await new Promise((resolve) => {
|
|
689
|
-
pool.req(
|
|
688
|
+
pool.req(relays, {
|
|
690
689
|
kinds: [38423],
|
|
691
690
|
"#d": ["routstr-21-models"],
|
|
692
691
|
limit: 1,
|