sseFraming (route/framing.ts)

opencode · packages/ai/src/route/framing.ts · typescript · MIT
realtime, tag:knn-classified

SSE framing utilities that decode streaming HTTP responses into provider frames, handling events and errors.

// Source: https://github.com/anomalyco/opencode | License: MIT | Copyright 2025 opencode
// Provided via justclaw.it.com; keep this notice with the code.
import { Effect, Stream } from "effect"
import { makeParser } from "effect/encoding/Sse"
import { AIError, InvalidProviderOutputError } from "../schema/index.js"

/**
 * Decode a streaming HTTP response body into provider-protocol frames.
 *
 * `Framing` is the byte-stream-shaped seam between transport and protocol:
 *
 * - SSE (`Framing.sse`) — UTF-8 decode the body, run the SSE channel decoder,
 *   and emit the `data:` payload of each non-empty event. The default drops
 *   `[DONE]`; protocols that use it as a terminal select `sseWithDone`.
 * - AWS event stream — length-prefixed binary frames with CRC checksums.
 *   Each emitted fra

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key