24 Commits

Author SHA1 Message Date
roboomp eaa5f46d32 fix(mcp): resumed interrupted HTTP response streams
Implemented 2025-11-25 Streamable HTTP polling semantics for POST SSE responses: retain event IDs and retry intervals, wait as instructed, and reconnect with GET plus Last-Event-ID until the originating JSON-RPC response arrives.

Extended the shared SSE parser to expose valid id/retry fields and control-only events so reconnecting consumers do not need to reparse raw lines.

Fixes #8264
2026-08-11 18:21:12 +00:00
roboomp 22fa8f6623 perf(stream): batched response decoding
- Batched complete SSE lines into one UTF-8 decode per source chunk.

- Parsed Ollama NDJSON bytes directly without TextDecoder buffering.

Fixes #5542
2026-07-15 02:55:02 +00:00
can1357 eb4a02433c 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.
2026-06-27 00:11:42 +02:00
usr_bin_roygbiv 5f22e58a61 fix(utils): require string closed in hasValidPredecessorForComma 2026-06-23 23:53:04 -05:00
usr_bin_roygbiv 2a31d063b2 fix(utils): handle string escapes and partial unicode escapes at EOF in getClosingSuffix 2026-06-23 23:43:46 -05:00
usr_bin_roygbiv 4528f5414a fix(utils): gate literal completion to non-inString state in getClosingSuffix 2026-06-23 23:39:56 -05:00
usr_bin_roygbiv 3a91053566 fix(utils): transition arrays back to expect_value on comma in scanJsonState 2026-06-23 23:36:28 -05:00
usr_bin_roygbiv a971f1aa9b fix(utils): validate comma predecessor using parser state instead of character rules 2026-06-23 23:32:42 -05:00
usr_bin_roygbiv fde4a33a59 fix(utils): handle invalid comma predecessors in isJsonTruncated 2026-06-23 23:29:36 -05:00
usr_bin_roygbiv 5032116702 fix(utils): handle truncated JSON gracefully in readSseJson 2026-06-23 23:23:55 -05:00
usr_bin_roygbiv 4d8a85e028 fix(utils): handle truncated JSON gracefully in readSseJson 2026-06-23 23:20:17 -05:00
can1357 80a0a1b8a8 feat(utils): replaced createAbortableStream with abortableSource
- Introduced `abortableSource` as a lighter, direct-reader async generator.
- Removed the `createAbortableStream` public API to eliminate unnecessary stream wrapper layers.
- Updated internal stream processing to use `abortableSource` for improved memory and performance.
2026-06-19 16:06:18 +02:00
can1357 b75c7dd5f2 fix(utils): added abort propagation to createAbortableStream
- Reworked createAbortableStream to forward abort signals to the source stream reader.
- Added cleanup logic so abort/cancel/error paths release locks and emit AbortError consistently.
- Updated related tests to verify source-stream cancellation and handoff escape-handler behavior.
2026-06-13 17:56:02 +02:00
can1357 9d457f73d9 test: migrated test imports to package subpath exports
- Replaced relative `../src` imports with `@oh-my-pi/pi-ai` and `@oh-my-pi/pi-agent-core` subpaths.
2026-06-08 19:03:55 +02:00
can1357 83b69ead9f test(ai): fixed SSE test structure and added keepalive parsing coverage
- Restructured the auth-broker `openSnapshotStream` tests to be top-level cases under the describe suite.
- Added a stream parser test asserting pure ": keepalive" lines are not included in subsequent SSE event raw output.
2026-05-25 20:29:30 +02:00
can1357 39f34ada70 feat: added pure-JS sanitizeText
- Migrated sanitizeText from pi-natives to pi-utils as a pure-JS implementation, removing the native dependency across all call sites.
2026-05-16 20:12:26 +02:00
can1357 9f386dd6e5 feat(ai,coding-agent): raw SSE diagnostics + steady-state idle watchdog
Adds an opt-in onSseEvent callback across HTTP-streaming providers (Anthropic, OpenAI Responses/Completions, Azure OpenAI Responses, OpenAI Codex SSE, Google Gemini CLI, GitLab Duo, Kimi, Synthetic) so callers can inspect raw SSE frames without altering parsed output. Provider fetch wrapping only tees response bodies when an observer is wired; standalone packages/ai consumers without onSseEvent are not penalized.

Adds streamIdleTimeoutMs (env: PI_STREAM_IDLE_TIMEOUT_MS, with PI_OPENAI_STREAM_IDLE_TIMEOUT_MS as a backward-compatible alias). Anthropic now enforces a steady-state idle watchdog (default 120s) in addition to the first-event watchdog. OpenAI Responses, Azure Responses, and Codex (SSE + WebSocket) gain a semantic-progress predicate so response.in_progress-style keepalives no longer keep stalled tool calls alive forever.

Adds a coding-agent debug-panel raw SSE viewer backed by a per-session bounded buffer (1000 records / 512KB) that AgentSession populates unconditionally so users can post-hoc inspect a stuck stream from the TUI.
2026-05-10 04:53:41 +02:00
can1357 9672139228 feat: added shared readSseEvents utility for Anthropic SSE parsing
- Added `readSseEvents` and `ServerSentEvent` exports in utils for reusable SSE stream parsing.
- Replaced Anthropic's local SSE parser with shared `readSseEvents(response.body, signal)` decoding.
- Updated abort handling in agent stream loop to race an `ABORTED` sentinel with `responseIterator.next()`.
- Expanded stream tests for `readSseEvents` parsing of CRLF, comments, split UTF-8 chunks, and trailing events.
2026-05-07 00:08:06 +02:00
can1357 2e33e436b4 feat: switched to native text sanitization, removed Bun.stripANSI
- Added `sanitizeText` function to pi-natives that strips ANSI escape sequences, removes control characters and lone surrogates, and normalizes line endings.
- Moved `sanitizeText` function from `@oh-my-pi/pi-utils` to `@oh-my-pi/pi-natives` for better code organization and native performance.
- Added line length clamping (4000 characters) to bash and Python execution output to prevent excessively long lines.
- Replaced internal `#normalizeOutput` methods with `sanitizeText` utility function in bash and Python execution components.
- Fixed bash interactive tool to gracefully handle malformed output chunks by normalizing them with `sanitizeText`.
- Simplified documentation by removing WASM terminology from package descriptions and comments.
2026-02-14 03:25:13 +01:00
can1357 aa2c75d727 refactor(utils): simplified abort handling and stream parsing with inlined Promise.withResolvers and Uint8Array lookup
- Removed createAbortablePromise function and inlined Promise.withResolvers usage in untilAborted for simpler abort handling.
- Replaced Bitmap class with simpler Uint8Array lookup table for whitespace detection in SSE parsing.
- Fixed subarray calculation in ConcatSink.pullJSONL to use correct read offset instead of computed remainder.
- Simplified copyWithin call in ConcatSink.pullJSONL to use read offset directly.
- Changed String.replace with regex to replaceAll for carriage return removal in sanitizeText.
- Removed unused test utilities and test cases for TextDecoderStream.
2026-02-06 00:13:29 +01:00
can1357 0171cd7b75 refactor(utils): restructured stream utilities for improved reusability and correctness
- Extracted stream abort handling into dedicated `createAbortableStream` utility function for reuse across stream operations.
- Refactored `sanitizeBinaryOutput` to handle surrogate pairs correctly and filter additional control characters (DEL and C1 control block) with lazy array allocation.
- Simplified JSONL parsing by replacing manual buffer management with new `pullJSONL` generator method in ConcatSink class.
- Removed unused `createSanitizerStream` and `createTextDecoderStream` helper functions that are no longer needed.
- Refactored `readSseJson` to use generator-based line processing with fast-path optimization for OpenAI-style done markers.
- Updated stdio transport to use new `readJsonl` utility instead of manual JSON parsing with TextDecoder.
2026-02-05 23:39:05 +01:00
can1357 b12a27830c refactor(stream): improved SSE parsing & added GPT-5.3, Claude 4.6 Opus
- Extracted stream parsing utilities into reusable functions in pi-utils package (readLines, readJsonl, parseJsonlLenient, readSseJson).
- Replaced manual buffer management with ConcatSink class for efficient stream handling across multiple modules.
- Simplified SSE stream parsing in google-gemini-cli provider by using readSseJson utility instead of manual reader setup.
- Refactored MCP stdio transport to use readLines utility for cleaner line-based stream processing.
- Updated RPC client and mode to use readJsonl utility, removing duplicate JSONL parsing logic.
- Optimized buffer allocations by using allocUnsafe where data is immediately populated and reusing empty buffer instances.
2026-02-05 21:06:58 +01:00
can1357 8255875525 refactor(utils): restructured stream handling and improved error semantics across utilities
- Refactored readSseJson abort handling to use pipeThrough with signal instead of manual event listeners, improving stream cancellation semantics.
- Replaced finally block with catch block to handle abort errors explicitly, preventing unnecessary cleanup operations.
- Reformatted test strings to use single quotes for consistency with project style guidelines.
- Removed unused isEnoent import and consolidated error code checking in dump-edit-history script.
2026-02-05 13:41:49 +01:00
can1357 1f7c4f6f90 refactor(stream-parsing): restructured stream utilities to use Web standard APIs and generic SSE parsing
- Refactored SSE stream parsing to use generic `readSseJson` utility instead of domain-specific handlers across multiple packages.
- Migrated from Node.js Buffer API to Web standard APIs (Uint8Array, TextDecoder, DataView) for cross-platform compatibility.
- Simplified stream transformation pipeline by consolidating multiple stream operations into unified `createTextLineSplitter` utility.
- Refactored `ptree.ts` to remove complex stream pumping infrastructure and simplify stderr handling with direct async iteration.
- Rewrote stream utilities to operate at binary level with byte-level parsing for improved efficiency and reduced string allocations.
- Updated TypeScript configuration to include DOM.AsyncIterable type definitions for async iterable DOM API support.
2026-02-05 10:59:47 +01:00