@oh-my-pi/pi-utils 14.8.0 → 14.9.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/stream.ts +17 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-utils",
4
- "version": "14.8.0",
4
+ "version": "14.9.0",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://github.com/can1357/oh-my-pi",
7
7
  "author": "Can Boluk",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bun": "^1.3.13",
41
- "@oh-my-pi/pi-natives": "14.8.0"
41
+ "@oh-my-pi/pi-natives": "14.9.0"
42
42
  },
43
43
  "engines": {
44
44
  "bun": ">=1.3.7"
package/src/stream.ts CHANGED
@@ -199,8 +199,24 @@ class ConcatSink {
199
199
  * }
200
200
  * ```
201
201
  */
202
- export async function* readSseJson<T>(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<T> {
202
+ export type SseEventObserver = (event: ServerSentEvent) => void;
203
+
204
+ function notifySseEventObserver(observer: SseEventObserver | undefined, event: ServerSentEvent): void {
205
+ if (!observer) return;
206
+ try {
207
+ observer(event);
208
+ } catch {
209
+ // Diagnostic observers must never perturb provider stream consumption.
210
+ }
211
+ }
212
+
213
+ export async function* readSseJson<T>(
214
+ stream: ReadableStream<Uint8Array>,
215
+ signal?: AbortSignal,
216
+ onEvent?: SseEventObserver,
217
+ ): AsyncGenerator<T> {
203
218
  for await (const sse of readSseEvents(stream, signal)) {
219
+ notifySseEventObserver(onEvent, sse);
204
220
  const data = sse.data;
205
221
  if (data === "" || data === "[DONE]") {
206
222
  if (data === "[DONE]") return;