Stream Translator (proxy/stream-translator.ts)

autobeat · src/translation/proxy/stream-translator.ts · typescript · MIT
ai, realtime, infra, ui

Orchestrates SSE line-by-line translation between OpenAI and Anthropic streaming formats, routing events through parser, middleware chain, and serializer. Reuse for building protocol-bridging LLM proxies.

// Source: https://github.com/dean0x/autobeat | License: MIT | Copyright 2024-2026 dean0x
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Stream translator — orchestrates OpenAI parser + middleware + Anthropic serializer.
 *
 * ARCHITECTURE: The stream translator sits between the raw SSE lines from the
 * target (OpenAI) and the SSE output to the source (Claude Code). It processes
 * one SSE line at a time, yielding zero or more Anthropic SSE strings.
 *
 * Line routing:
 * - `data: [DONE]` → end sentinel, no-op
 * - `data: <json>` → parse JSON, route through target parser + middleware + source serializer
 * - `event: <name>` → ignored (OpenAI doesn't use named events)
 * - `: <comment>` → ignored
 * - Empty line → ignored (SSE event separator)
 */
import type { Str

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

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

Get a free API key