@oh-my-pi/pi-agent-core 11.0.3 → 11.2.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 +5 -5
  2. package/src/proxy.ts +10 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-agent-core",
3
- "version": "11.0.3",
3
+ "version": "11.2.0",
4
4
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -24,9 +24,9 @@
24
24
  "test": "bun test"
25
25
  },
26
26
  "dependencies": {
27
- "@oh-my-pi/pi-ai": "11.0.3",
28
- "@oh-my-pi/pi-tui": "11.0.3",
29
- "@oh-my-pi/pi-utils": "11.0.3"
27
+ "@oh-my-pi/pi-ai": "11.2.0",
28
+ "@oh-my-pi/pi-tui": "11.2.0",
29
+ "@oh-my-pi/pi-utils": "11.2.0"
30
30
  },
31
31
  "keywords": [
32
32
  "ai",
@@ -47,6 +47,6 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@sinclair/typebox": "^0.34.48",
50
- "@types/node": "^25.2.0"
50
+ "@types/bun": "^1.3.8"
51
51
  }
52
52
  }
package/src/proxy.ts CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  type ToolCall,
14
14
  } from "@oh-my-pi/pi-ai";
15
15
  import { parseStreamingJson } from "@oh-my-pi/pi-ai/utils/json-parse";
16
- import { readSseEvents } from "@oh-my-pi/pi-utils";
16
+ import { readSseJson } from "@oh-my-pi/pi-utils";
17
17
 
18
18
  // Create stream class matching ProxyMessageEventStream
19
19
  class ProxyMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
@@ -147,22 +147,20 @@ export function streamProxy(model: Model, context: Context, options: ProxyStream
147
147
  throw new Error(errorMessage);
148
148
  }
149
149
 
150
- for await (const event of readSseEvents(response.body!)) {
151
- if (options.signal?.aborted) {
152
- throw new Error("Request aborted by user");
153
- }
154
-
155
- const data = event.data?.trim();
156
- if (!data || data === "[DONE]") continue;
157
- const proxyEvent = JSON.parse(data) as ProxyAssistantMessageEvent;
158
- const parsedEvent = processProxyEvent(proxyEvent, partial);
150
+ let sawTerminalEvent = false;
151
+ for await (const event of readSseJson<ProxyAssistantMessageEvent>(response.body!, options.signal)) {
152
+ const parsedEvent = processProxyEvent(event, partial);
159
153
  if (parsedEvent) {
154
+ if (parsedEvent.type === "done" || parsedEvent.type === "error") {
155
+ sawTerminalEvent = true;
156
+ }
160
157
  stream.push(parsedEvent);
161
158
  }
162
159
  }
163
160
 
164
- if (options.signal?.aborted) {
165
- throw new Error("Request aborted by user");
161
+ if (options.signal?.aborted && !sawTerminalEvent) {
162
+ const reason = options.signal.reason;
163
+ throw reason instanceof Error ? reason : new Error(String(reason ?? "Request aborted"));
166
164
  }
167
165
 
168
166
  stream.end();