@wengine-ai/llms 2.3.2399 → 2.3.2400

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.
@@ -25,3 +25,46 @@ export declare function parseJsonText(text: string, status?: number): any;
25
25
  * on the upstream response rather than the request body.
26
26
  */
27
27
  export declare function isEventStreamResponse(response: Response): boolean;
28
+ /**
29
+ * Check whether accumulated text looks like an SSE stream (vs JSON).
30
+ * Match only at line start so a JSON body containing an "event":"..." field
31
+ * is not falsely treated as a stream (JSON starts with "{" or "[").
32
+ */
33
+ export declare function looksLikeSSE(text: string): boolean;
34
+ /**
35
+ * Peek the first meaningful content of a response body without consuming it.
36
+ *
37
+ * The body is `tee()`d; we drain one tee'd branch with a short read loop and
38
+ * cancel it, leaving the other branch untouched so the caller can still read
39
+ * the full body. A single `read()` is not enough: upstream relays (e.g. the
40
+ * Codex relay) can split the first event across multiple chunks, send an empty
41
+ * leading buffer, or emit an SSE comment heartbeat (": ping") before the real
42
+ * `event:`/`data:` line. We accumulate across a bounded number of reads until
43
+ * we can classify the body as SSE or JSON, so a fragmented first event is
44
+ * still detected as a stream instead of failing JSON parse downstream.
45
+ *
46
+ * Returns `{ body, isSSE }` where `body` is the unread tee'd branch (the
47
+ * original full body, including the bytes we peeked) suitable for passing to a
48
+ * fresh `Response`, or `null` when the body cannot be peeked (locked/absent).
49
+ */
50
+ export declare function peekBodyForSSE(response: Response): Promise<{
51
+ body: ReadableStream<Uint8Array>;
52
+ isSSE: boolean;
53
+ } | null>;
54
+ /**
55
+ * Last-resort SSE detection that consumes the entire body as text.
56
+ *
57
+ * Used when `peekBodyForSSE` cannot run (body absent or locked by an earlier
58
+ * reader): instead of failing, drain the body to text and classify it. If the
59
+ * full text is an SSE stream, return it wrapped as a fresh `text/event-stream`
60
+ * `Response` so the caller can stream it through; otherwise return a `Response`
61
+ * over the same text so JSON parsing can proceed (and fail with a descriptive
62
+ * preview if it is neither).
63
+ *
64
+ * Returns the (possibly rebuilt) Response, or the original response when the
65
+ * body cannot be consumed at all.
66
+ */
67
+ export declare function readBodyForSSE(response: Response): Promise<{
68
+ response: Response;
69
+ isSSE: boolean;
70
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wengine-ai/llms",
3
- "version": "2.3.2399",
3
+ "version": "2.3.2400",
4
4
  "description": "A universal LLM API transformation server",
5
5
  "main": "dist/cjs/server.cjs",
6
6
  "module": "dist/esm/server.mjs",
@@ -52,7 +52,7 @@
52
52
  "uuid": "^11.1.0",
53
53
  "@fastify/multipart": "^9.0.0",
54
54
  "@fastify/static": "^8.2.0",
55
- "@wengine-ai/claude-code-router-shared": "^2.3.2399",
55
+ "@wengine-ai/claude-code-router-shared": "^2.3.2400",
56
56
  "adm-zip": "^0.5.16",
57
57
  "better-sqlite3": "^12.10.0",
58
58
  "rotating-file-stream": "^3.2.7"