@routstr/sdk 0.2.11 → 0.3.0
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/client/index.d.mts +30 -15
- package/dist/client/index.d.ts +30 -15
- package/dist/client/index.js +289 -141
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +290 -143
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.d.mts +3 -10
- package/dist/index.d.ts +3 -10
- package/dist/index.js +289 -163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +290 -164
- package/dist/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +13 -0
- package/dist/wallet/index.d.ts +13 -0
- package/dist/wallet/index.js +71 -2
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +71 -2
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/client/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { M as Model, a as Message, T as TransactionHistory, l as StreamingResult } from '../types-BYj_8c5c.mjs';
|
|
2
2
|
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-C5fLD3jB.mjs';
|
|
3
3
|
import { S as SdkStore, U as UsageTrackingDriver } from '../store-DGeLPv9E.mjs';
|
|
4
|
-
import { ServerResponse } from 'http';
|
|
5
4
|
import { CashuSpender, BalanceManager } from '../wallet/index.mjs';
|
|
6
5
|
import { Transform } from 'stream';
|
|
7
6
|
import 'zustand/vanilla';
|
|
@@ -50,6 +49,7 @@ declare class ProviderManager {
|
|
|
50
49
|
getInstanceId(): string;
|
|
51
50
|
/**
|
|
52
51
|
* Clean up expired cooldown entries
|
|
52
|
+
* Also removes the provider from failedProviders so it can be retried
|
|
53
53
|
*/
|
|
54
54
|
private cleanupExpiredCooldowns;
|
|
55
55
|
/**
|
|
@@ -190,9 +190,6 @@ interface RouteRequestParams {
|
|
|
190
190
|
modelId?: string;
|
|
191
191
|
clientApiKey?: string;
|
|
192
192
|
}
|
|
193
|
-
interface RouteRequestToNodeResponseParams extends RouteRequestParams {
|
|
194
|
-
res: ServerResponse;
|
|
195
|
-
}
|
|
196
193
|
interface RoutstrClientConfig {
|
|
197
194
|
usageTrackingDriver?: UsageTrackingDriver;
|
|
198
195
|
sdkStore?: SdkStore;
|
|
@@ -245,7 +242,6 @@ declare class RoutstrClient {
|
|
|
245
242
|
* requests and get responses back.
|
|
246
243
|
*/
|
|
247
244
|
routeRequest(params: RouteRequestParams): Promise<Response>;
|
|
248
|
-
routeRequestToNodeResponse(params: RouteRequestToNodeResponseParams): Promise<void>;
|
|
249
245
|
private _prepareRoutedRequest;
|
|
250
246
|
/**
|
|
251
247
|
* Extract clientApiKey from Authorization Bearer token if present
|
|
@@ -373,20 +369,39 @@ interface UsageTrackingData {
|
|
|
373
369
|
}
|
|
374
370
|
|
|
375
371
|
/**
|
|
376
|
-
*
|
|
372
|
+
* Inspect a Web `ReadableStream<Uint8Array>` of SSE bytes for `usage` and
|
|
373
|
+
* response `id` fields without touching the bytes that are delivered to the
|
|
374
|
+
* real client. This is meant to be called on one branch of a `body.tee()`.
|
|
375
|
+
*
|
|
376
|
+
* The inspector reads the stream to completion (or errors out), decoding
|
|
377
|
+
* UTF-8 across chunk boundaries, splitting on SSE event terminators
|
|
378
|
+
* (`\r?\n\r?\n`), parsing each `data:` payload as JSON, and invoking the
|
|
379
|
+
* provided callbacks when usage / response id become known.
|
|
377
380
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
|
|
381
|
+
* The returned Promise resolves with the final captured values once the
|
|
382
|
+
* stream ends (or is cancelled / errors out).
|
|
383
|
+
*/
|
|
384
|
+
declare function inspectSSEWebStream(stream: ReadableStream<Uint8Array>, onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Promise<{
|
|
385
|
+
capturedUsage?: UsageTrackingData;
|
|
386
|
+
capturedResponseId?: string;
|
|
387
|
+
}>;
|
|
388
|
+
/**
|
|
389
|
+
* SSE parser transform that preserves the original byte stream.
|
|
390
|
+
*
|
|
391
|
+
* Incoming chunks are forwarded downstream unchanged so chunk boundaries and
|
|
392
|
+
* timing remain identical to the upstream source. In parallel, a streaming text
|
|
393
|
+
* decoder buffers just enough data to detect complete SSE event blocks for
|
|
394
|
+
* usage/responseId inspection.
|
|
395
|
+
*
|
|
396
|
+
* This means:
|
|
397
|
+
* - The client sees the original stream bytes without parser-induced
|
|
398
|
+
* re-chunking.
|
|
381
399
|
* - Multi-line events (multiple `data:` lines, plus `event:`/`id:`/`retry:`
|
|
382
|
-
* fields) are
|
|
383
|
-
* - Comments / keepalives (lines beginning with `:`) are preserved.
|
|
400
|
+
* fields) are still parsed correctly for inspection.
|
|
384
401
|
* - Chunks that contain multiple events, or events split across chunks, are
|
|
385
402
|
* handled correctly without merging or losing packets.
|
|
386
|
-
*
|
|
387
|
-
* As a side-effect, it inspects `data:` payloads for usage/responseId and
|
|
388
|
-
* invokes the provided callbacks the first time each is seen.
|
|
403
|
+
* - UTF-8 split across chunk boundaries is decoded safely.
|
|
389
404
|
*/
|
|
390
405
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
391
406
|
|
|
392
|
-
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams,
|
|
407
|
+
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform, inspectSSEWebStream };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { M as Model, a as Message, T as TransactionHistory, l as StreamingResult } from '../types-BYj_8c5c.js';
|
|
2
2
|
import { P as ProviderRegistry, W as WalletAdapter, S as StorageAdapter, a as StreamingCallbacks } from '../interfaces-B62Rw-dd.js';
|
|
3
3
|
import { S as SdkStore, U as UsageTrackingDriver } from '../store-h7m23ffq.js';
|
|
4
|
-
import { ServerResponse } from 'http';
|
|
5
4
|
import { CashuSpender, BalanceManager } from '../wallet/index.js';
|
|
6
5
|
import { Transform } from 'stream';
|
|
7
6
|
import 'zustand/vanilla';
|
|
@@ -50,6 +49,7 @@ declare class ProviderManager {
|
|
|
50
49
|
getInstanceId(): string;
|
|
51
50
|
/**
|
|
52
51
|
* Clean up expired cooldown entries
|
|
52
|
+
* Also removes the provider from failedProviders so it can be retried
|
|
53
53
|
*/
|
|
54
54
|
private cleanupExpiredCooldowns;
|
|
55
55
|
/**
|
|
@@ -190,9 +190,6 @@ interface RouteRequestParams {
|
|
|
190
190
|
modelId?: string;
|
|
191
191
|
clientApiKey?: string;
|
|
192
192
|
}
|
|
193
|
-
interface RouteRequestToNodeResponseParams extends RouteRequestParams {
|
|
194
|
-
res: ServerResponse;
|
|
195
|
-
}
|
|
196
193
|
interface RoutstrClientConfig {
|
|
197
194
|
usageTrackingDriver?: UsageTrackingDriver;
|
|
198
195
|
sdkStore?: SdkStore;
|
|
@@ -245,7 +242,6 @@ declare class RoutstrClient {
|
|
|
245
242
|
* requests and get responses back.
|
|
246
243
|
*/
|
|
247
244
|
routeRequest(params: RouteRequestParams): Promise<Response>;
|
|
248
|
-
routeRequestToNodeResponse(params: RouteRequestToNodeResponseParams): Promise<void>;
|
|
249
245
|
private _prepareRoutedRequest;
|
|
250
246
|
/**
|
|
251
247
|
* Extract clientApiKey from Authorization Bearer token if present
|
|
@@ -373,20 +369,39 @@ interface UsageTrackingData {
|
|
|
373
369
|
}
|
|
374
370
|
|
|
375
371
|
/**
|
|
376
|
-
*
|
|
372
|
+
* Inspect a Web `ReadableStream<Uint8Array>` of SSE bytes for `usage` and
|
|
373
|
+
* response `id` fields without touching the bytes that are delivered to the
|
|
374
|
+
* real client. This is meant to be called on one branch of a `body.tee()`.
|
|
375
|
+
*
|
|
376
|
+
* The inspector reads the stream to completion (or errors out), decoding
|
|
377
|
+
* UTF-8 across chunk boundaries, splitting on SSE event terminators
|
|
378
|
+
* (`\r?\n\r?\n`), parsing each `data:` payload as JSON, and invoking the
|
|
379
|
+
* provided callbacks when usage / response id become known.
|
|
377
380
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
|
|
381
|
+
* The returned Promise resolves with the final captured values once the
|
|
382
|
+
* stream ends (or is cancelled / errors out).
|
|
383
|
+
*/
|
|
384
|
+
declare function inspectSSEWebStream(stream: ReadableStream<Uint8Array>, onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Promise<{
|
|
385
|
+
capturedUsage?: UsageTrackingData;
|
|
386
|
+
capturedResponseId?: string;
|
|
387
|
+
}>;
|
|
388
|
+
/**
|
|
389
|
+
* SSE parser transform that preserves the original byte stream.
|
|
390
|
+
*
|
|
391
|
+
* Incoming chunks are forwarded downstream unchanged so chunk boundaries and
|
|
392
|
+
* timing remain identical to the upstream source. In parallel, a streaming text
|
|
393
|
+
* decoder buffers just enough data to detect complete SSE event blocks for
|
|
394
|
+
* usage/responseId inspection.
|
|
395
|
+
*
|
|
396
|
+
* This means:
|
|
397
|
+
* - The client sees the original stream bytes without parser-induced
|
|
398
|
+
* re-chunking.
|
|
381
399
|
* - Multi-line events (multiple `data:` lines, plus `event:`/`id:`/`retry:`
|
|
382
|
-
* fields) are
|
|
383
|
-
* - Comments / keepalives (lines beginning with `:`) are preserved.
|
|
400
|
+
* fields) are still parsed correctly for inspection.
|
|
384
401
|
* - Chunks that contain multiple events, or events split across chunks, are
|
|
385
402
|
* handled correctly without merging or losing packets.
|
|
386
|
-
*
|
|
387
|
-
* As a side-effect, it inspects `data:` payloads for usage/responseId and
|
|
388
|
-
* invokes the provided callbacks the first time each is seen.
|
|
403
|
+
* - UTF-8 split across chunk boundaries is decoded safely.
|
|
389
404
|
*/
|
|
390
405
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
391
406
|
|
|
392
|
-
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams,
|
|
407
|
+
export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform, inspectSSEWebStream };
|