@routstr/sdk 0.2.12 → 0.3.1
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 +29 -15
- package/dist/client/index.d.ts +29 -15
- package/dist/client/index.js +267 -166
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +268 -146
- package/dist/client/index.mjs.map +1 -1
- package/dist/discovery/index.js +2 -0
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +2 -0
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/index.d.mts +3 -10
- package/dist/index.d.ts +3 -10
- package/dist/index.js +273 -192
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +274 -171
- 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';
|
|
@@ -191,9 +190,6 @@ interface RouteRequestParams {
|
|
|
191
190
|
modelId?: string;
|
|
192
191
|
clientApiKey?: string;
|
|
193
192
|
}
|
|
194
|
-
interface RouteRequestToNodeResponseParams extends RouteRequestParams {
|
|
195
|
-
res: ServerResponse;
|
|
196
|
-
}
|
|
197
193
|
interface RoutstrClientConfig {
|
|
198
194
|
usageTrackingDriver?: UsageTrackingDriver;
|
|
199
195
|
sdkStore?: SdkStore;
|
|
@@ -246,7 +242,6 @@ declare class RoutstrClient {
|
|
|
246
242
|
* requests and get responses back.
|
|
247
243
|
*/
|
|
248
244
|
routeRequest(params: RouteRequestParams): Promise<Response>;
|
|
249
|
-
routeRequestToNodeResponse(params: RouteRequestToNodeResponseParams): Promise<void>;
|
|
250
245
|
private _prepareRoutedRequest;
|
|
251
246
|
/**
|
|
252
247
|
* Extract clientApiKey from Authorization Bearer token if present
|
|
@@ -374,20 +369,39 @@ interface UsageTrackingData {
|
|
|
374
369
|
}
|
|
375
370
|
|
|
376
371
|
/**
|
|
377
|
-
*
|
|
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.
|
|
378
380
|
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
|
|
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.
|
|
382
399
|
* - Multi-line events (multiple `data:` lines, plus `event:`/`id:`/`retry:`
|
|
383
|
-
* fields) are
|
|
384
|
-
* - Comments / keepalives (lines beginning with `:`) are preserved.
|
|
400
|
+
* fields) are still parsed correctly for inspection.
|
|
385
401
|
* - Chunks that contain multiple events, or events split across chunks, are
|
|
386
402
|
* handled correctly without merging or losing packets.
|
|
387
|
-
*
|
|
388
|
-
* As a side-effect, it inspects `data:` payloads for usage/responseId and
|
|
389
|
-
* invokes the provided callbacks the first time each is seen.
|
|
403
|
+
* - UTF-8 split across chunk boundaries is decoded safely.
|
|
390
404
|
*/
|
|
391
405
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
392
406
|
|
|
393
|
-
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';
|
|
@@ -191,9 +190,6 @@ interface RouteRequestParams {
|
|
|
191
190
|
modelId?: string;
|
|
192
191
|
clientApiKey?: string;
|
|
193
192
|
}
|
|
194
|
-
interface RouteRequestToNodeResponseParams extends RouteRequestParams {
|
|
195
|
-
res: ServerResponse;
|
|
196
|
-
}
|
|
197
193
|
interface RoutstrClientConfig {
|
|
198
194
|
usageTrackingDriver?: UsageTrackingDriver;
|
|
199
195
|
sdkStore?: SdkStore;
|
|
@@ -246,7 +242,6 @@ declare class RoutstrClient {
|
|
|
246
242
|
* requests and get responses back.
|
|
247
243
|
*/
|
|
248
244
|
routeRequest(params: RouteRequestParams): Promise<Response>;
|
|
249
|
-
routeRequestToNodeResponse(params: RouteRequestToNodeResponseParams): Promise<void>;
|
|
250
245
|
private _prepareRoutedRequest;
|
|
251
246
|
/**
|
|
252
247
|
* Extract clientApiKey from Authorization Bearer token if present
|
|
@@ -374,20 +369,39 @@ interface UsageTrackingData {
|
|
|
374
369
|
}
|
|
375
370
|
|
|
376
371
|
/**
|
|
377
|
-
*
|
|
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.
|
|
378
380
|
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
|
|
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.
|
|
382
399
|
* - Multi-line events (multiple `data:` lines, plus `event:`/`id:`/`retry:`
|
|
383
|
-
* fields) are
|
|
384
|
-
* - Comments / keepalives (lines beginning with `:`) are preserved.
|
|
400
|
+
* fields) are still parsed correctly for inspection.
|
|
385
401
|
* - Chunks that contain multiple events, or events split across chunks, are
|
|
386
402
|
* handled correctly without merging or losing packets.
|
|
387
|
-
*
|
|
388
|
-
* As a side-effect, it inspects `data:` payloads for usage/responseId and
|
|
389
|
-
* invokes the provided callbacks the first time each is seen.
|
|
403
|
+
* - UTF-8 split across chunk boundaries is decoded safely.
|
|
390
404
|
*/
|
|
391
405
|
declare function createSSEParserTransform(onUsage: (usage: UsageTrackingData) => void, onResponseId?: (responseId: string) => void): Transform;
|
|
392
406
|
|
|
393
|
-
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 };
|