pendra 0.13.0 → 0.14.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/README.md CHANGED
@@ -154,6 +154,11 @@ Image generation is non-streaming — the response is returned as a single JSON
154
154
  | `baseURL` | — | `https://api.pendra.ai` |
155
155
  | `timeout` | — | `120000` (ms) |
156
156
 
157
+ For a streaming request, `timeout` covers waiting for the response to start and
158
+ then any gap between chunks, not the length of the whole stream, so long
159
+ generations are not cut off. Breaking out of a stream's `for await` loop early
160
+ cancels the request.
161
+
157
162
  ## Migrating from OpenAI
158
163
 
159
164
  ```diff
package/dist/index.d.mts CHANGED
@@ -376,6 +376,14 @@ interface ChatCompletionCreateParams {
376
376
  * chunk. The error frames used to be yielded *as* chunks (`JSON.parse` succeeds
377
377
  * on them), so a worker crash surfaced as a `TypeError` on `chunk.choices[0]`
378
378
  * rather than as something a caller could catch and read (issue #2252).
379
+ *
380
+ * `idleTimeoutMs` bounds the gap between reads, not the whole stream: the API
381
+ * sends a keep-alive comment every 15 s, so a healthy stream never goes quiet
382
+ * for long however long it runs, while a stalled one fails with an
383
+ * `APIConnectionError` rather than hanging (#2185). Leaving the loop before the
384
+ * stream ends — a `break`, or a frame that throws — aborts the request, so the
385
+ * connection is released and the worker stops generating tokens nobody will
386
+ * read (#2216).
379
387
  */
380
388
  declare class Stream implements AsyncIterable<ChatCompletionChunk> {
381
389
  private reader;
@@ -383,7 +391,8 @@ declare class Stream implements AsyncIterable<ChatCompletionChunk> {
383
391
  private sse;
384
392
  private done;
385
393
  private controller;
386
- constructor(response: Response, controller: AbortController);
394
+ private idleTimeoutMs;
395
+ constructor(response: Response, controller: AbortController, idleTimeoutMs?: number);
387
396
  [Symbol.asyncIterator](): AsyncIterator<ChatCompletionChunk>;
388
397
  abort(): void;
389
398
  }
@@ -546,22 +555,25 @@ declare class Rerank {
546
555
 
547
556
  interface ResponseInner {
548
557
  v?: number;
558
+ /** Legacy v1 encapsulated key. A v2 client refuses any frame carrying it. */
549
559
  enc?: string;
560
+ kid?: string;
550
561
  seq: number;
551
562
  ciphertext: string;
552
563
  }
553
564
  /**
554
- * Decrypts a worker's sealed response. Derives the response DEK once from the
555
- * first frame's `enc` (HPKE Export to the client's ephemeral key) and enforces a
556
- * monotonic `seq` across streaming chunks.
565
+ * Decrypts a worker's sealed response. The first frame names the `kid` the
566
+ * worker opened; its response key (from {@link sealRequest}) decrypts every
567
+ * frame. Refuses any frame not in v2 form and enforces a monotonic `seq` across
568
+ * streaming chunks.
557
569
  */
558
570
  declare class ResponseDecryptor {
559
- private respPriv;
571
+ private keys;
560
572
  private dek;
561
573
  private nextSeq;
562
- constructor(responsePrivateKey: Uint8Array);
574
+ constructor(responseKeys: Map<string, Uint8Array>);
563
575
  private ensureDek;
564
- /** Decrypt a non-streaming result envelope `{v, enc, seq, ciphertext}`. */
576
+ /** Decrypt a non-streaming result envelope `{v, kid, seq, ciphertext}`. */
565
577
  openResult(inner: ResponseInner): Uint8Array;
566
578
  /** Decrypt one streaming chunk envelope, enforcing monotonic `seq`. */
567
579
  openChunk(inner: ResponseInner): Uint8Array;
@@ -699,7 +711,6 @@ declare class Pendra {
699
711
  _fetch(path: string, options: {
700
712
  method: string;
701
713
  body?: Record<string, unknown>;
702
- stream?: boolean;
703
714
  headers?: Record<string, string>;
704
715
  }): Promise<{
705
716
  response: Response;
package/dist/index.d.ts CHANGED
@@ -376,6 +376,14 @@ interface ChatCompletionCreateParams {
376
376
  * chunk. The error frames used to be yielded *as* chunks (`JSON.parse` succeeds
377
377
  * on them), so a worker crash surfaced as a `TypeError` on `chunk.choices[0]`
378
378
  * rather than as something a caller could catch and read (issue #2252).
379
+ *
380
+ * `idleTimeoutMs` bounds the gap between reads, not the whole stream: the API
381
+ * sends a keep-alive comment every 15 s, so a healthy stream never goes quiet
382
+ * for long however long it runs, while a stalled one fails with an
383
+ * `APIConnectionError` rather than hanging (#2185). Leaving the loop before the
384
+ * stream ends — a `break`, or a frame that throws — aborts the request, so the
385
+ * connection is released and the worker stops generating tokens nobody will
386
+ * read (#2216).
379
387
  */
380
388
  declare class Stream implements AsyncIterable<ChatCompletionChunk> {
381
389
  private reader;
@@ -383,7 +391,8 @@ declare class Stream implements AsyncIterable<ChatCompletionChunk> {
383
391
  private sse;
384
392
  private done;
385
393
  private controller;
386
- constructor(response: Response, controller: AbortController);
394
+ private idleTimeoutMs;
395
+ constructor(response: Response, controller: AbortController, idleTimeoutMs?: number);
387
396
  [Symbol.asyncIterator](): AsyncIterator<ChatCompletionChunk>;
388
397
  abort(): void;
389
398
  }
@@ -546,22 +555,25 @@ declare class Rerank {
546
555
 
547
556
  interface ResponseInner {
548
557
  v?: number;
558
+ /** Legacy v1 encapsulated key. A v2 client refuses any frame carrying it. */
549
559
  enc?: string;
560
+ kid?: string;
550
561
  seq: number;
551
562
  ciphertext: string;
552
563
  }
553
564
  /**
554
- * Decrypts a worker's sealed response. Derives the response DEK once from the
555
- * first frame's `enc` (HPKE Export to the client's ephemeral key) and enforces a
556
- * monotonic `seq` across streaming chunks.
565
+ * Decrypts a worker's sealed response. The first frame names the `kid` the
566
+ * worker opened; its response key (from {@link sealRequest}) decrypts every
567
+ * frame. Refuses any frame not in v2 form and enforces a monotonic `seq` across
568
+ * streaming chunks.
557
569
  */
558
570
  declare class ResponseDecryptor {
559
- private respPriv;
571
+ private keys;
560
572
  private dek;
561
573
  private nextSeq;
562
- constructor(responsePrivateKey: Uint8Array);
574
+ constructor(responseKeys: Map<string, Uint8Array>);
563
575
  private ensureDek;
564
- /** Decrypt a non-streaming result envelope `{v, enc, seq, ciphertext}`. */
576
+ /** Decrypt a non-streaming result envelope `{v, kid, seq, ciphertext}`. */
565
577
  openResult(inner: ResponseInner): Uint8Array;
566
578
  /** Decrypt one streaming chunk envelope, enforcing monotonic `seq`. */
567
579
  openChunk(inner: ResponseInner): Uint8Array;
@@ -699,7 +711,6 @@ declare class Pendra {
699
711
  _fetch(path: string, options: {
700
712
  method: string;
701
713
  body?: Record<string, unknown>;
702
- stream?: boolean;
703
714
  headers?: Record<string, string>;
704
715
  }): Promise<{
705
716
  response: Response;