함수: toHttpStream()
function toHttpStream(
stream,
abortController?,
getId?): ReadableStream<Uint8Array<ArrayBufferLike>>;
정의 위치: packages/ai/src/stream-to-response.ts:1053
StreamChunk async iterable을 HTTP 스트림 형식(줄바꿈으로 구분된 JSON)의 ReadableStream으로 변환합니다.
이것은 새라인으로 구분된 JSON 으로 청크를 방출하는 ReadableStream 을 생성합니다:
- 각 청크는 JSON.stringify'd 되고 "\n" 로 이어집니다
- SSE 포맷팅 없음 ("data: " 접두어 없음)
이 형식은 fetchHttpStream 연결 어댑터와 호환됩니다.
getId 가 제공될 때 (전송 내구성), 각 청크는 {"id":"<offset>","chunk":{…}} 엔벨로프로 방출되며, 맨손 청크가 아닙니다. NDJSON 은 SSE 의 id: 줄과 같은 네이티브 이벤트 ID 필드가 없으므로, 재개 가능한 오프셋은 페이로드 내부에 탑니다. 태그 없는 청크 (id 없음) 는 맨손으로 남으므로, 내구성이 없는 스트림은 이전과 바이트 동일하며, 클라이언트는 자동으로 두 형식을 감지합니다.
매개변수
stream
AsyncIterable<AGUIEvent>
chat()에서 반환된 StreamChunk의 AsyncIterable입니다.
abortController?
AbortController
스트림이 취소될 때 중단할 선택적 AbortController입니다.
getId?
(chunk, index) => string | undefined
청크별 선택적 영속성 오프셋입니다. 제공되면 청크가 envelope 형식으로 인코딩됩니다.
반환값
ReadableStream<Uint8Array<ArrayBufferLike>>
HTTP 스트림 형식(줄바꿈으로 구분된 JSON)의 ReadableStream입니다.
예제
const stream = chat({ adapter: openaiText('gpt-5.5'), messages: [...] });
const readableStream = toHttpStream(stream);
// Use with Response for HTTP streaming (not SSE)
return new Response(readableStream, {
headers: { 'Content-Type': 'application/x-ndjson' }
});