@routstr/sdk 0.2.5 → 0.2.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.
- package/README.md +1 -2
- package/dist/client/index.d.mts +34 -6
- package/dist/client/index.d.ts +34 -6
- package/dist/client/index.js +773 -479
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +773 -479
- package/dist/client/index.mjs.map +1 -1
- package/dist/discovery/index.js +1 -1
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +1 -1
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/index.d.mts +21 -9
- package/dist/index.d.ts +21 -9
- package/dist/index.js +897 -558
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +895 -559
- package/dist/index.mjs.map +1 -1
- package/dist/{interfaces-CluftN4z.d.ts → interfaces-B62Rw-dd.d.ts} +19 -14
- package/dist/{interfaces-C6Dr6hKy.d.mts → interfaces-C5fLD3jB.d.mts} +19 -14
- package/dist/storage/index.d.mts +39 -162
- package/dist/storage/index.d.ts +39 -162
- package/dist/storage/index.js +529 -193
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +527 -194
- package/dist/storage/index.mjs.map +1 -1
- package/dist/store-DGeLPv9E.d.mts +172 -0
- package/dist/store-h7m23ffq.d.ts +172 -0
- package/dist/wallet/index.d.mts +26 -26
- package/dist/wallet/index.d.ts +26 -26
- package/dist/wallet/index.js +143 -271
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +143 -271
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,10 +70,9 @@ await client.fetchAIResponse(fetchOptions, streamingCallbacks);
|
|
|
70
70
|
|
|
71
71
|
## Client Modes
|
|
72
72
|
|
|
73
|
-
The `RoutstrClient` supports
|
|
73
|
+
The `RoutstrClient` supports two modes via the constructor `mode` parameter (defaults to `"xcashu"` if unspecified):
|
|
74
74
|
|
|
75
75
|
- `"xcashu"` — Default mode. Uses standard Cashu token spending with refunds.
|
|
76
|
-
- `"lazyrefund"` — Defers refund processing to reduce mint load; may retain tokens longer before refunding.
|
|
77
76
|
- `"apikeys"` — Uses API key authentication instead of Cashu tokens; no token spending or refund flow.
|
|
78
77
|
|
|
79
78
|
```ts
|
package/dist/client/index.d.mts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { M as Model, a as Message, T as TransactionHistory, l as StreamingResult } from '../types-BYj_8c5c.mjs';
|
|
2
|
-
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-
|
|
2
|
+
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-C5fLD3jB.mjs';
|
|
3
|
+
import { S as SdkStore, U as UsageTrackingDriver } from '../store-DGeLPv9E.mjs';
|
|
3
4
|
import { ServerResponse } from 'http';
|
|
4
5
|
import { CashuSpender, BalanceManager } from '../wallet/index.mjs';
|
|
5
6
|
import { Transform } from 'stream';
|
|
7
|
+
import 'zustand/vanilla';
|
|
8
|
+
import '../interfaces-BWJJTCXO.mjs';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* ProviderManager - Handles provider selection and failover logic
|
|
@@ -32,7 +35,19 @@ declare class ProviderManager {
|
|
|
32
35
|
private providersOnCoolDown;
|
|
33
36
|
/** Cooldown duration in milliseconds (5 minutes) */
|
|
34
37
|
private static readonly COOLDOWN_DURATION_MS;
|
|
35
|
-
|
|
38
|
+
/** Optional persistent store for failure tracking */
|
|
39
|
+
private store;
|
|
40
|
+
/** Instance ID for debugging */
|
|
41
|
+
private readonly instanceId;
|
|
42
|
+
constructor(providerRegistry: ProviderRegistry, store?: SdkStore);
|
|
43
|
+
/**
|
|
44
|
+
* Hydrate in-memory state from persistent store
|
|
45
|
+
*/
|
|
46
|
+
private hydrateFromStore;
|
|
47
|
+
/**
|
|
48
|
+
* Get instance ID for debugging
|
|
49
|
+
*/
|
|
50
|
+
getInstanceId(): string;
|
|
36
51
|
/**
|
|
37
52
|
* Clean up expired cooldown entries
|
|
38
53
|
*/
|
|
@@ -163,7 +178,7 @@ interface FetchOptions {
|
|
|
163
178
|
* RoutstrClient is the main SDK entry point
|
|
164
179
|
*/
|
|
165
180
|
type AlertLevel = "max" | "min";
|
|
166
|
-
type RoutstrClientMode = "xcashu" | "
|
|
181
|
+
type RoutstrClientMode = "xcashu" | "apikeys";
|
|
167
182
|
type DebugLevel = "DEBUG" | "WARN" | "ERROR";
|
|
168
183
|
interface RouteRequestParams {
|
|
169
184
|
path: string;
|
|
@@ -173,10 +188,17 @@ interface RouteRequestParams {
|
|
|
173
188
|
baseUrl: string;
|
|
174
189
|
mintUrl: string;
|
|
175
190
|
modelId?: string;
|
|
191
|
+
clientApiKey?: string;
|
|
176
192
|
}
|
|
177
193
|
interface RouteRequestToNodeResponseParams extends RouteRequestParams {
|
|
178
194
|
res: ServerResponse;
|
|
179
195
|
}
|
|
196
|
+
interface RoutstrClientConfig {
|
|
197
|
+
usageTrackingDriver?: UsageTrackingDriver;
|
|
198
|
+
sdkStore?: SdkStore;
|
|
199
|
+
/** Optional: shared ProviderManager instance for consistent failure tracking across requests */
|
|
200
|
+
providerManager?: ProviderManager;
|
|
201
|
+
}
|
|
180
202
|
declare class RoutstrClient {
|
|
181
203
|
private walletAdapter;
|
|
182
204
|
private storageAdapter;
|
|
@@ -188,7 +210,9 @@ declare class RoutstrClient {
|
|
|
188
210
|
private alertLevel;
|
|
189
211
|
private mode;
|
|
190
212
|
private debugLevel;
|
|
191
|
-
|
|
213
|
+
private usageTrackingDriver?;
|
|
214
|
+
private sdkStore?;
|
|
215
|
+
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, providerRegistry: ProviderRegistry, alertLevel: AlertLevel, mode?: RoutstrClientMode, options?: RoutstrClientConfig);
|
|
192
216
|
/**
|
|
193
217
|
* Get the current client mode
|
|
194
218
|
*/
|
|
@@ -223,6 +247,10 @@ declare class RoutstrClient {
|
|
|
223
247
|
routeRequest(params: RouteRequestParams): Promise<Response>;
|
|
224
248
|
routeRequestToNodeResponse(params: RouteRequestToNodeResponseParams): Promise<void>;
|
|
225
249
|
private _prepareRoutedRequest;
|
|
250
|
+
/**
|
|
251
|
+
* Extract clientApiKey from Authorization Bearer token if present
|
|
252
|
+
*/
|
|
253
|
+
private _extractClientApiKey;
|
|
226
254
|
/**
|
|
227
255
|
* Fetch AI response with streaming
|
|
228
256
|
*/
|
|
@@ -253,7 +281,7 @@ declare class RoutstrClient {
|
|
|
253
281
|
*/
|
|
254
282
|
private _getEstimatedCosts;
|
|
255
283
|
/**
|
|
256
|
-
* Get pending
|
|
284
|
+
* Get pending API key amount
|
|
257
285
|
*/
|
|
258
286
|
private _getPendingCashuTokenAmount;
|
|
259
287
|
/**
|
|
@@ -346,4 +374,4 @@ interface UsageTrackingData {
|
|
|
346
374
|
|
|
347
375
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
348
376
|
|
|
349
|
-
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, type RouteRequestToNodeResponseParams, RoutstrClient, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform };
|
|
377
|
+
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, type RouteRequestToNodeResponseParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { M as Model, a as Message, T as TransactionHistory, l as StreamingResult } from '../types-BYj_8c5c.js';
|
|
2
|
-
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-
|
|
2
|
+
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-B62Rw-dd.js';
|
|
3
|
+
import { S as SdkStore, U as UsageTrackingDriver } from '../store-h7m23ffq.js';
|
|
3
4
|
import { ServerResponse } from 'http';
|
|
4
5
|
import { CashuSpender, BalanceManager } from '../wallet/index.js';
|
|
5
6
|
import { Transform } from 'stream';
|
|
7
|
+
import 'zustand/vanilla';
|
|
8
|
+
import '../interfaces-BxDEka72.js';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* ProviderManager - Handles provider selection and failover logic
|
|
@@ -32,7 +35,19 @@ declare class ProviderManager {
|
|
|
32
35
|
private providersOnCoolDown;
|
|
33
36
|
/** Cooldown duration in milliseconds (5 minutes) */
|
|
34
37
|
private static readonly COOLDOWN_DURATION_MS;
|
|
35
|
-
|
|
38
|
+
/** Optional persistent store for failure tracking */
|
|
39
|
+
private store;
|
|
40
|
+
/** Instance ID for debugging */
|
|
41
|
+
private readonly instanceId;
|
|
42
|
+
constructor(providerRegistry: ProviderRegistry, store?: SdkStore);
|
|
43
|
+
/**
|
|
44
|
+
* Hydrate in-memory state from persistent store
|
|
45
|
+
*/
|
|
46
|
+
private hydrateFromStore;
|
|
47
|
+
/**
|
|
48
|
+
* Get instance ID for debugging
|
|
49
|
+
*/
|
|
50
|
+
getInstanceId(): string;
|
|
36
51
|
/**
|
|
37
52
|
* Clean up expired cooldown entries
|
|
38
53
|
*/
|
|
@@ -163,7 +178,7 @@ interface FetchOptions {
|
|
|
163
178
|
* RoutstrClient is the main SDK entry point
|
|
164
179
|
*/
|
|
165
180
|
type AlertLevel = "max" | "min";
|
|
166
|
-
type RoutstrClientMode = "xcashu" | "
|
|
181
|
+
type RoutstrClientMode = "xcashu" | "apikeys";
|
|
167
182
|
type DebugLevel = "DEBUG" | "WARN" | "ERROR";
|
|
168
183
|
interface RouteRequestParams {
|
|
169
184
|
path: string;
|
|
@@ -173,10 +188,17 @@ interface RouteRequestParams {
|
|
|
173
188
|
baseUrl: string;
|
|
174
189
|
mintUrl: string;
|
|
175
190
|
modelId?: string;
|
|
191
|
+
clientApiKey?: string;
|
|
176
192
|
}
|
|
177
193
|
interface RouteRequestToNodeResponseParams extends RouteRequestParams {
|
|
178
194
|
res: ServerResponse;
|
|
179
195
|
}
|
|
196
|
+
interface RoutstrClientConfig {
|
|
197
|
+
usageTrackingDriver?: UsageTrackingDriver;
|
|
198
|
+
sdkStore?: SdkStore;
|
|
199
|
+
/** Optional: shared ProviderManager instance for consistent failure tracking across requests */
|
|
200
|
+
providerManager?: ProviderManager;
|
|
201
|
+
}
|
|
180
202
|
declare class RoutstrClient {
|
|
181
203
|
private walletAdapter;
|
|
182
204
|
private storageAdapter;
|
|
@@ -188,7 +210,9 @@ declare class RoutstrClient {
|
|
|
188
210
|
private alertLevel;
|
|
189
211
|
private mode;
|
|
190
212
|
private debugLevel;
|
|
191
|
-
|
|
213
|
+
private usageTrackingDriver?;
|
|
214
|
+
private sdkStore?;
|
|
215
|
+
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, providerRegistry: ProviderRegistry, alertLevel: AlertLevel, mode?: RoutstrClientMode, options?: RoutstrClientConfig);
|
|
192
216
|
/**
|
|
193
217
|
* Get the current client mode
|
|
194
218
|
*/
|
|
@@ -223,6 +247,10 @@ declare class RoutstrClient {
|
|
|
223
247
|
routeRequest(params: RouteRequestParams): Promise<Response>;
|
|
224
248
|
routeRequestToNodeResponse(params: RouteRequestToNodeResponseParams): Promise<void>;
|
|
225
249
|
private _prepareRoutedRequest;
|
|
250
|
+
/**
|
|
251
|
+
* Extract clientApiKey from Authorization Bearer token if present
|
|
252
|
+
*/
|
|
253
|
+
private _extractClientApiKey;
|
|
226
254
|
/**
|
|
227
255
|
* Fetch AI response with streaming
|
|
228
256
|
*/
|
|
@@ -253,7 +281,7 @@ declare class RoutstrClient {
|
|
|
253
281
|
*/
|
|
254
282
|
private _getEstimatedCosts;
|
|
255
283
|
/**
|
|
256
|
-
* Get pending
|
|
284
|
+
* Get pending API key amount
|
|
257
285
|
*/
|
|
258
286
|
private _getPendingCashuTokenAmount;
|
|
259
287
|
/**
|
|
@@ -346,4 +374,4 @@ interface UsageTrackingData {
|
|
|
346
374
|
|
|
347
375
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
348
376
|
|
|
349
|
-
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, type RouteRequestToNodeResponseParams, RoutstrClient, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform };
|
|
377
|
+
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, type RouteRequestToNodeResponseParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform };
|