refactor: consolidated json parsing and stream utilities

- Centralized JSON parsing and stream processing logic by moving utilities from `packages/ai` to the shared `@oh-my-pi/pi-utils` package.
- Standardized import paths for JSON parsing and streaming across the agent, ai, and coding-agent packages.
- Refactored SSE stream handling to use consolidated `parseStreamingJson` logic and introduced robust error recovery for malformed container-shaped tail events.
- Cleaned up legacy bundled registry references and updated related module exports and tests to reflect the new utility structure.
This commit is contained in:
can1357
2026-06-27 00:11:42 +02:00
parent eec44769cc
commit eb4a02433c
28 changed files with 92 additions and 391 deletions
@@ -107,7 +107,6 @@ export const BUNDLED_PI_REGISTRY_KEYS: ReadonlySet<string> = new Set([
"@oh-my-pi/pi-ai/utils/google-validation",
"@oh-my-pi/pi-ai/utils/http-inspector",
"@oh-my-pi/pi-ai/utils/idle-iterator",
"@oh-my-pi/pi-ai/utils/json-parse",
"@oh-my-pi/pi-ai/utils/openai-http",
"@oh-my-pi/pi-ai/utils/openrouter-headers",
"@oh-my-pi/pi-ai/utils/overflow",
@@ -131,7 +131,6 @@ import * as bundledPiAiUtilsGoogleValidation from "@oh-my-pi/pi-ai/utils/google-
import * as bundledPiAiUtilsHarmonyLeak from "@oh-my-pi/pi-ai/utils/harmony-leak";
import * as bundledPiAiUtilsHttpInspector from "@oh-my-pi/pi-ai/utils/http-inspector";
import * as bundledPiAiUtilsIdleIterator from "@oh-my-pi/pi-ai/utils/idle-iterator";
import * as bundledPiAiUtilsJsonParse from "@oh-my-pi/pi-ai/utils/json-parse";
import * as bundledPiAiUtilsOpenaiHttp from "@oh-my-pi/pi-ai/utils/openai-http";
import * as bundledPiAiUtilsOpenrouterHeaders from "@oh-my-pi/pi-ai/utils/openrouter-headers";
import * as bundledPiAiUtilsOverflow from "@oh-my-pi/pi-ai/utils/overflow";
@@ -1207,7 +1206,6 @@ export const BUNDLED_PI_REGISTRY: Readonly<Record<string, Readonly<Record<string
Record<string, unknown>
>,
"@oh-my-pi/pi-ai/utils/idle-iterator": bundledPiAiUtilsIdleIterator as unknown as Readonly<Record<string, unknown>>,
"@oh-my-pi/pi-ai/utils/json-parse": bundledPiAiUtilsJsonParse as unknown as Readonly<Record<string, unknown>>,
"@oh-my-pi/pi-ai/utils/openai-http": bundledPiAiUtilsOpenaiHttp as unknown as Readonly<Record<string, unknown>>,
"@oh-my-pi/pi-ai/utils/openrouter-headers": bundledPiAiUtilsOpenrouterHeaders as unknown as Readonly<
Record<string, unknown>
@@ -1690,7 +1690,8 @@ export class InputController {
// that state — inform the user instead of silently flipping the
// persisted value. When thinking is on, the toggle works normally
// even if blocks are already hidden (user may want to show them).
const thinkingOff = ((this.ctx.viewSession ?? this.ctx.session)?.thinkingLevel ?? ThinkingLevel.Off) === ThinkingLevel.Off;
const thinkingOff =
((this.ctx.viewSession ?? this.ctx.session)?.thinkingLevel ?? ThinkingLevel.Off) === ThinkingLevel.Off;
if (thinkingOff) {
this.ctx.showStatus("Thinking is off — enable thinking to show blocks");
return;
@@ -1,4 +1,4 @@
import { parseStreamingJson } from "@oh-my-pi/pi-ai/utils/json-parse";
import { parseStreamingJson } from "@oh-my-pi/pi-utils";
import { nextStep, STREAMING_REVEAL_FRAME_MS } from "./streaming-reveal";
/** Minimal component surface the reveal pushes frames into. */