@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.
@@ -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
- * 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.
378
380
  *
379
- * Unlike a naive line-splitter, this buffers until a full SSE event is
380
- * received (terminated by a blank line, per the SSE spec), then forwards the
381
- * 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.
382
399
  * - Multi-line events (multiple `data:` lines, plus `event:`/`id:`/`retry:`
383
- * fields) are preserved.
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, 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';
@@ -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
- * 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.
378
380
  *
379
- * Unlike a naive line-splitter, this buffers until a full SSE event is
380
- * received (terminated by a blank line, per the SSE spec), then forwards the
381
- * 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.
382
399
  * - Multi-line events (multiple `data:` lines, plus `event:`/`id:`/`retry:`
383
- * fields) are preserved.
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, 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 };