@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.
@@ -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
- * SSE parser transform that preserves event boundaries verbatim.
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
- * Unlike a naive line-splitter, this buffers until a full SSE event is
379
- * received (terminated by a blank line, per the SSE spec), then forwards the
380
- * entire event unchanged downstream. This means:
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 preserved.
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, type RouteRequestToNodeResponseParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform };
407
+ export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform, inspectSSEWebStream };
@@ -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
- * SSE parser transform that preserves event boundaries verbatim.
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
- * Unlike a naive line-splitter, this buffers until a full SSE event is
379
- * received (terminated by a blank line, per the SSE spec), then forwards the
380
- * entire event unchanged downstream. This means:
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 preserved.
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, type RouteRequestToNodeResponseParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform };
407
+ export { type AlertLevel, type DebugLevel, type FetchOptions, type ModelProviderPrice, ProviderManager, type RouteRequestParams, RoutstrClient, type RoutstrClientConfig, type RoutstrClientMode, type StreamCallbacks, StreamProcessor, createSSEParserTransform, inspectSSEWebStream };