@oh-my-pi/pi-agent-core 6.7.67 → 6.8.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 -3
  2. package/src/proxy.ts +8 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-agent-core",
3
- "version": "6.7.67",
3
+ "version": "6.8.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",
@@ -13,8 +13,9 @@
13
13
  "test": "vitest --run"
14
14
  },
15
15
  "dependencies": {
16
- "@oh-my-pi/pi-ai": "6.7.67",
17
- "@oh-my-pi/pi-tui": "6.7.67"
16
+ "@oh-my-pi/pi-ai": "6.8.0",
17
+ "@oh-my-pi/pi-tui": "6.8.0",
18
+ "@oh-my-pi/pi-utils": "6.8.0"
18
19
  },
19
20
  "keywords": [
20
21
  "ai",
@@ -34,6 +35,7 @@
34
35
  "bun": ">=1.0.0"
35
36
  },
36
37
  "devDependencies": {
38
+ "@sinclair/typebox": "^0.34.46",
37
39
  "@types/node": "^24.3.0",
38
40
  "vitest": "^3.2.4"
39
41
  }
package/src/proxy.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  type ToolCall,
15
15
  } from "@oh-my-pi/pi-ai";
16
16
  import { parseStreamingJson } from "@oh-my-pi/pi-ai/src/utils/json-parse";
17
+ import { readSseEvents } from "@oh-my-pi/pi-utils";
17
18
 
18
19
  // Create stream class matching ProxyMessageEventStream
19
20
  class ProxyMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
@@ -148,33 +149,17 @@ export function streamProxy(model: Model<any>, context: Context, options: ProxyS
148
149
  throw new Error(errorMessage);
149
150
  }
150
151
 
151
- reader = response.body!.getReader() as ReadableStreamDefaultReader<Uint8Array>;
152
- const decoder = new TextDecoder();
153
- let buffer = "";
154
-
155
- while (true) {
156
- const { done, value } = await reader!.read();
157
- if (done) break;
158
-
152
+ for await (const event of readSseEvents(response.body!)) {
159
153
  if (options.signal?.aborted) {
160
154
  throw new Error("Request aborted by user");
161
155
  }
162
156
 
163
- buffer += decoder.decode(value, { stream: true });
164
- const lines = buffer.split("\n");
165
- buffer = lines.pop() || "";
166
-
167
- for (const line of lines) {
168
- if (line.startsWith("data: ")) {
169
- const data = line.slice(6).trim();
170
- if (data) {
171
- const proxyEvent = JSON.parse(data) as ProxyAssistantMessageEvent;
172
- const event = processProxyEvent(proxyEvent, partial);
173
- if (event) {
174
- stream.push(event);
175
- }
176
- }
177
- }
157
+ const data = event.data?.trim();
158
+ if (!data || data === "[DONE]") continue;
159
+ const proxyEvent = JSON.parse(data) as ProxyAssistantMessageEvent;
160
+ const parsedEvent = processProxyEvent(proxyEvent, partial);
161
+ if (parsedEvent) {
162
+ stream.push(parsedEvent);
178
163
  }
179
164
  }
180
165