@routstr/sdk 0.3.9 → 0.3.10
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 +6278 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.mjs +6230 -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 +6586 -0
- package/dist/bun.js.map +1 -0
- package/dist/bun.mjs +6532 -0
- package/dist/bun.mjs.map +1 -0
- package/dist/bunSqlite-BMTseLIz.d.ts +18 -0
- package/dist/bunSqlite-D6AreVE2.d.mts +18 -0
- package/dist/client/index.d.mts +63 -41
- package/dist/client/index.d.ts +63 -41
- package/dist/client/index.js +801 -1291
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +801 -1292
- 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 +28 -21
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +28 -21
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1045 -1564
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1045 -1561
- 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 +6651 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +6599 -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 +1801 -0
- package/dist/storage/bun.js.map +1 -0
- package/dist/storage/bun.mjs +1777 -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 +139 -650
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +140 -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 +1864 -0
- package/dist/storage/node.js.map +1 -0
- package/dist/storage/node.mjs +1842 -0
- package/dist/storage/node.mjs.map +1 -0
- package/dist/{store-C6dfj1cc.d.mts → store-BiuM2V9N.d.mts} +14 -0
- package/dist/{store-58VcEUoA.d.ts → store-C8MZlfuz.d.ts} +14 -0
- package/package.json +26 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { a as StorageDriver, U as UsageTrackingDriver } from './store-C8MZlfuz.js';
|
|
2
|
+
import { S as SdkLogger } from './types-_21yYFZG.js';
|
|
3
|
+
|
|
4
|
+
declare function createBunSqliteDriver(dbPath: string, options?: {
|
|
5
|
+
logger?: SdkLogger;
|
|
6
|
+
}): Promise<StorageDriver>;
|
|
7
|
+
|
|
8
|
+
interface BunSqliteUsageTrackingDriverOptions {
|
|
9
|
+
dbPath?: string;
|
|
10
|
+
tableName?: string;
|
|
11
|
+
legacyStorageDriver?: StorageDriver;
|
|
12
|
+
sqlite?: {
|
|
13
|
+
Database: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare const createBunSqliteUsageTrackingDriver: (options?: BunSqliteUsageTrackingDriverOptions) => UsageTrackingDriver;
|
|
17
|
+
|
|
18
|
+
export { type BunSqliteUsageTrackingDriverOptions as B, createBunSqliteUsageTrackingDriver as a, createBunSqliteDriver as c };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { a as StorageDriver, U as UsageTrackingDriver } from './store-BiuM2V9N.mjs';
|
|
2
|
+
import { S as SdkLogger } from './types-_21yYFZG.mjs';
|
|
3
|
+
|
|
4
|
+
declare function createBunSqliteDriver(dbPath: string, options?: {
|
|
5
|
+
logger?: SdkLogger;
|
|
6
|
+
}): Promise<StorageDriver>;
|
|
7
|
+
|
|
8
|
+
interface BunSqliteUsageTrackingDriverOptions {
|
|
9
|
+
dbPath?: string;
|
|
10
|
+
tableName?: string;
|
|
11
|
+
legacyStorageDriver?: StorageDriver;
|
|
12
|
+
sqlite?: {
|
|
13
|
+
Database: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare const createBunSqliteUsageTrackingDriver: (options?: BunSqliteUsageTrackingDriverOptions) => UsageTrackingDriver;
|
|
17
|
+
|
|
18
|
+
export { type BunSqliteUsageTrackingDriverOptions as B, createBunSqliteUsageTrackingDriver as a, createBunSqliteDriver as c };
|
package/dist/client/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { e as Model, S as SdkLogger,
|
|
1
|
+
import { e as Model, S as SdkLogger, m as StreamingResult, M as Message, n as TransactionHistory } from '../types-_21yYFZG.mjs';
|
|
2
2
|
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-Csn8Uq04.mjs';
|
|
3
|
-
import { S as SdkStore, U as UsageTrackingDriver } from '../store-
|
|
3
|
+
import { S as SdkStore, U as UsageTrackingDriver } from '../store-BiuM2V9N.mjs';
|
|
4
4
|
import { CashuSpender, BalanceManager } from '../wallet/index.mjs';
|
|
5
5
|
import { Transform } from 'stream';
|
|
6
6
|
import 'zustand/vanilla';
|
|
@@ -25,6 +25,9 @@ interface ModelProviderPrice {
|
|
|
25
25
|
completionPerMillion: number;
|
|
26
26
|
totalPerMillion: number;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* ProviderManager handles provider selection and failover
|
|
30
|
+
*/
|
|
28
31
|
declare class ProviderManager {
|
|
29
32
|
private providerRegistry;
|
|
30
33
|
private failedProviders;
|
|
@@ -162,19 +165,6 @@ declare class ProviderManager {
|
|
|
162
165
|
* Extracted from utils/apiUtils.ts
|
|
163
166
|
*/
|
|
164
167
|
|
|
165
|
-
/**
|
|
166
|
-
* Options for fetching AI response
|
|
167
|
-
*/
|
|
168
|
-
interface FetchOptions {
|
|
169
|
-
messageHistory: Message[];
|
|
170
|
-
selectedModel: Model;
|
|
171
|
-
baseUrl: string;
|
|
172
|
-
mintUrl: string;
|
|
173
|
-
balance: number;
|
|
174
|
-
transactionHistory: TransactionHistory[];
|
|
175
|
-
maxTokens?: number;
|
|
176
|
-
headers?: Record<string, string>;
|
|
177
|
-
}
|
|
178
168
|
/**
|
|
179
169
|
* RoutstrClient is the main SDK entry point
|
|
180
170
|
*/
|
|
@@ -205,7 +195,6 @@ declare class RoutstrClient {
|
|
|
205
195
|
private providerRegistry;
|
|
206
196
|
private cashuSpender;
|
|
207
197
|
private balanceManager;
|
|
208
|
-
private streamProcessor;
|
|
209
198
|
private providerManager;
|
|
210
199
|
private alertLevel;
|
|
211
200
|
private mode;
|
|
@@ -251,10 +240,6 @@ declare class RoutstrClient {
|
|
|
251
240
|
* Extract clientApiKey from Authorization Bearer token if present
|
|
252
241
|
*/
|
|
253
242
|
private _extractClientApiKey;
|
|
254
|
-
/**
|
|
255
|
-
* Fetch AI response with streaming
|
|
256
|
-
*/
|
|
257
|
-
fetchAIResponse(options: FetchOptions, callbacks: StreamingCallbacks): Promise<void>;
|
|
258
243
|
/**
|
|
259
244
|
* Make the API request with failover support
|
|
260
245
|
*/
|
|
@@ -268,26 +253,6 @@ declare class RoutstrClient {
|
|
|
268
253
|
*/
|
|
269
254
|
private _handlePostResponseBalanceUpdate;
|
|
270
255
|
private _trackResponseUsage;
|
|
271
|
-
/**
|
|
272
|
-
* Convert messages for API format
|
|
273
|
-
*/
|
|
274
|
-
private _convertMessages;
|
|
275
|
-
/**
|
|
276
|
-
* Create assistant message from streaming result
|
|
277
|
-
*/
|
|
278
|
-
private _createAssistantMessage;
|
|
279
|
-
/**
|
|
280
|
-
* Calculate estimated costs from usage
|
|
281
|
-
*/
|
|
282
|
-
private _getEstimatedCosts;
|
|
283
|
-
/**
|
|
284
|
-
* Get pending API key amount
|
|
285
|
-
*/
|
|
286
|
-
private _getPendingCashuTokenAmount;
|
|
287
|
-
/**
|
|
288
|
-
* Handle errors and notify callbacks
|
|
289
|
-
*/
|
|
290
|
-
private _handleError;
|
|
291
256
|
/**
|
|
292
257
|
* Check wallet balance and throw if insufficient
|
|
293
258
|
*/
|
|
@@ -370,6 +335,19 @@ interface UsageTrackingData {
|
|
|
370
335
|
totalTokens: number;
|
|
371
336
|
cost: number;
|
|
372
337
|
satsCost: number;
|
|
338
|
+
/** Upstream provider/route that handled the request (e.g. "openrouter:openrouter:Anthropic"). */
|
|
339
|
+
provider?: string;
|
|
340
|
+
/** Full cost breakdown emitted by the upstream `cost` object. */
|
|
341
|
+
baseMsats?: number;
|
|
342
|
+
inputMsats?: number;
|
|
343
|
+
outputMsats?: number;
|
|
344
|
+
totalMsats?: number;
|
|
345
|
+
totalUsd?: number;
|
|
346
|
+
cacheReadInputTokens?: number;
|
|
347
|
+
cacheCreationInputTokens?: number;
|
|
348
|
+
cacheReadMsats?: number;
|
|
349
|
+
cacheCreationMsats?: number;
|
|
350
|
+
remainingBalanceMsats?: number;
|
|
373
351
|
}
|
|
374
352
|
|
|
375
353
|
/**
|
|
@@ -408,4 +386,48 @@ declare function inspectSSEWebStream(stream: ReadableStream<Uint8Array>, onUsage
|
|
|
408
386
|
*/
|
|
409
387
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
410
388
|
|
|
411
|
-
|
|
389
|
+
/**
|
|
390
|
+
* Options for fetching AI response
|
|
391
|
+
*/
|
|
392
|
+
interface FetchOptions {
|
|
393
|
+
messageHistory: Message[];
|
|
394
|
+
selectedModel: Model;
|
|
395
|
+
baseUrl: string;
|
|
396
|
+
mintUrl: string;
|
|
397
|
+
balance: number;
|
|
398
|
+
transactionHistory: TransactionHistory[];
|
|
399
|
+
maxTokens?: number;
|
|
400
|
+
headers?: Record<string, string>;
|
|
401
|
+
}
|
|
402
|
+
interface FetchAIResponseClient {
|
|
403
|
+
routeRequest(params: {
|
|
404
|
+
path: string;
|
|
405
|
+
method: string;
|
|
406
|
+
body?: unknown;
|
|
407
|
+
headers?: Record<string, string>;
|
|
408
|
+
baseUrl: string;
|
|
409
|
+
mintUrl: string;
|
|
410
|
+
modelId?: string;
|
|
411
|
+
}): Promise<Response>;
|
|
412
|
+
getProviderManager(): {
|
|
413
|
+
getModelForProvider(baseUrl: string, modelId: string): Promise<{
|
|
414
|
+
id: string;
|
|
415
|
+
} | null>;
|
|
416
|
+
};
|
|
417
|
+
getMode(): RoutstrClientMode;
|
|
418
|
+
}
|
|
419
|
+
interface FetchAIResponseDeps {
|
|
420
|
+
client: FetchAIResponseClient;
|
|
421
|
+
providerRegistry: ProviderRegistry;
|
|
422
|
+
alertLevel: AlertLevel;
|
|
423
|
+
logger: SdkLogger;
|
|
424
|
+
getPendingCashuTokenAmount?: () => number;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Fetch an AI chat/completions response using RoutstrClient.routeRequest for
|
|
428
|
+
* payment/auth/failover/accounting, then consume the returned SSE stream and
|
|
429
|
+
* drive the legacy streaming callbacks.
|
|
430
|
+
*/
|
|
431
|
+
declare function fetchAIResponse(options: FetchOptions, callbacks: StreamingCallbacks, deps: FetchAIResponseDeps): Promise<void>;
|
|
432
|
+
|
|
433
|
+
export { type AlertLevel, type DebugLevel, type FetchAIResponseDeps, type ModelProviderPrice, ProviderManager, type RouteRequestParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform, fetchAIResponse, inspectSSEWebStream };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { e as Model, S as SdkLogger,
|
|
1
|
+
import { e as Model, S as SdkLogger, m as StreamingResult, M as Message, n as TransactionHistory } from '../types-_21yYFZG.js';
|
|
2
2
|
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-C-DYd9Jy.js';
|
|
3
|
-
import { S as SdkStore, U as UsageTrackingDriver } from '../store-
|
|
3
|
+
import { S as SdkStore, U as UsageTrackingDriver } from '../store-C8MZlfuz.js';
|
|
4
4
|
import { CashuSpender, BalanceManager } from '../wallet/index.js';
|
|
5
5
|
import { Transform } from 'stream';
|
|
6
6
|
import 'zustand/vanilla';
|
|
@@ -25,6 +25,9 @@ interface ModelProviderPrice {
|
|
|
25
25
|
completionPerMillion: number;
|
|
26
26
|
totalPerMillion: number;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* ProviderManager handles provider selection and failover
|
|
30
|
+
*/
|
|
28
31
|
declare class ProviderManager {
|
|
29
32
|
private providerRegistry;
|
|
30
33
|
private failedProviders;
|
|
@@ -162,19 +165,6 @@ declare class ProviderManager {
|
|
|
162
165
|
* Extracted from utils/apiUtils.ts
|
|
163
166
|
*/
|
|
164
167
|
|
|
165
|
-
/**
|
|
166
|
-
* Options for fetching AI response
|
|
167
|
-
*/
|
|
168
|
-
interface FetchOptions {
|
|
169
|
-
messageHistory: Message[];
|
|
170
|
-
selectedModel: Model;
|
|
171
|
-
baseUrl: string;
|
|
172
|
-
mintUrl: string;
|
|
173
|
-
balance: number;
|
|
174
|
-
transactionHistory: TransactionHistory[];
|
|
175
|
-
maxTokens?: number;
|
|
176
|
-
headers?: Record<string, string>;
|
|
177
|
-
}
|
|
178
168
|
/**
|
|
179
169
|
* RoutstrClient is the main SDK entry point
|
|
180
170
|
*/
|
|
@@ -205,7 +195,6 @@ declare class RoutstrClient {
|
|
|
205
195
|
private providerRegistry;
|
|
206
196
|
private cashuSpender;
|
|
207
197
|
private balanceManager;
|
|
208
|
-
private streamProcessor;
|
|
209
198
|
private providerManager;
|
|
210
199
|
private alertLevel;
|
|
211
200
|
private mode;
|
|
@@ -251,10 +240,6 @@ declare class RoutstrClient {
|
|
|
251
240
|
* Extract clientApiKey from Authorization Bearer token if present
|
|
252
241
|
*/
|
|
253
242
|
private _extractClientApiKey;
|
|
254
|
-
/**
|
|
255
|
-
* Fetch AI response with streaming
|
|
256
|
-
*/
|
|
257
|
-
fetchAIResponse(options: FetchOptions, callbacks: StreamingCallbacks): Promise<void>;
|
|
258
243
|
/**
|
|
259
244
|
* Make the API request with failover support
|
|
260
245
|
*/
|
|
@@ -268,26 +253,6 @@ declare class RoutstrClient {
|
|
|
268
253
|
*/
|
|
269
254
|
private _handlePostResponseBalanceUpdate;
|
|
270
255
|
private _trackResponseUsage;
|
|
271
|
-
/**
|
|
272
|
-
* Convert messages for API format
|
|
273
|
-
*/
|
|
274
|
-
private _convertMessages;
|
|
275
|
-
/**
|
|
276
|
-
* Create assistant message from streaming result
|
|
277
|
-
*/
|
|
278
|
-
private _createAssistantMessage;
|
|
279
|
-
/**
|
|
280
|
-
* Calculate estimated costs from usage
|
|
281
|
-
*/
|
|
282
|
-
private _getEstimatedCosts;
|
|
283
|
-
/**
|
|
284
|
-
* Get pending API key amount
|
|
285
|
-
*/
|
|
286
|
-
private _getPendingCashuTokenAmount;
|
|
287
|
-
/**
|
|
288
|
-
* Handle errors and notify callbacks
|
|
289
|
-
*/
|
|
290
|
-
private _handleError;
|
|
291
256
|
/**
|
|
292
257
|
* Check wallet balance and throw if insufficient
|
|
293
258
|
*/
|
|
@@ -370,6 +335,19 @@ interface UsageTrackingData {
|
|
|
370
335
|
totalTokens: number;
|
|
371
336
|
cost: number;
|
|
372
337
|
satsCost: number;
|
|
338
|
+
/** Upstream provider/route that handled the request (e.g. "openrouter:openrouter:Anthropic"). */
|
|
339
|
+
provider?: string;
|
|
340
|
+
/** Full cost breakdown emitted by the upstream `cost` object. */
|
|
341
|
+
baseMsats?: number;
|
|
342
|
+
inputMsats?: number;
|
|
343
|
+
outputMsats?: number;
|
|
344
|
+
totalMsats?: number;
|
|
345
|
+
totalUsd?: number;
|
|
346
|
+
cacheReadInputTokens?: number;
|
|
347
|
+
cacheCreationInputTokens?: number;
|
|
348
|
+
cacheReadMsats?: number;
|
|
349
|
+
cacheCreationMsats?: number;
|
|
350
|
+
remainingBalanceMsats?: number;
|
|
373
351
|
}
|
|
374
352
|
|
|
375
353
|
/**
|
|
@@ -408,4 +386,48 @@ declare function inspectSSEWebStream(stream: ReadableStream<Uint8Array>, onUsage
|
|
|
408
386
|
*/
|
|
409
387
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
410
388
|
|
|
411
|
-
|
|
389
|
+
/**
|
|
390
|
+
* Options for fetching AI response
|
|
391
|
+
*/
|
|
392
|
+
interface FetchOptions {
|
|
393
|
+
messageHistory: Message[];
|
|
394
|
+
selectedModel: Model;
|
|
395
|
+
baseUrl: string;
|
|
396
|
+
mintUrl: string;
|
|
397
|
+
balance: number;
|
|
398
|
+
transactionHistory: TransactionHistory[];
|
|
399
|
+
maxTokens?: number;
|
|
400
|
+
headers?: Record<string, string>;
|
|
401
|
+
}
|
|
402
|
+
interface FetchAIResponseClient {
|
|
403
|
+
routeRequest(params: {
|
|
404
|
+
path: string;
|
|
405
|
+
method: string;
|
|
406
|
+
body?: unknown;
|
|
407
|
+
headers?: Record<string, string>;
|
|
408
|
+
baseUrl: string;
|
|
409
|
+
mintUrl: string;
|
|
410
|
+
modelId?: string;
|
|
411
|
+
}): Promise<Response>;
|
|
412
|
+
getProviderManager(): {
|
|
413
|
+
getModelForProvider(baseUrl: string, modelId: string): Promise<{
|
|
414
|
+
id: string;
|
|
415
|
+
} | null>;
|
|
416
|
+
};
|
|
417
|
+
getMode(): RoutstrClientMode;
|
|
418
|
+
}
|
|
419
|
+
interface FetchAIResponseDeps {
|
|
420
|
+
client: FetchAIResponseClient;
|
|
421
|
+
providerRegistry: ProviderRegistry;
|
|
422
|
+
alertLevel: AlertLevel;
|
|
423
|
+
logger: SdkLogger;
|
|
424
|
+
getPendingCashuTokenAmount?: () => number;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Fetch an AI chat/completions response using RoutstrClient.routeRequest for
|
|
428
|
+
* payment/auth/failover/accounting, then consume the returned SSE stream and
|
|
429
|
+
* drive the legacy streaming callbacks.
|
|
430
|
+
*/
|
|
431
|
+
declare function fetchAIResponse(options: FetchOptions, callbacks: StreamingCallbacks, deps: FetchAIResponseDeps): Promise<void>;
|
|
432
|
+
|
|
433
|
+
export { type AlertLevel, type DebugLevel, type FetchAIResponseDeps, type ModelProviderPrice, ProviderManager, type RouteRequestParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform, fetchAIResponse, inspectSSEWebStream };
|