Download packages/llm/test/lib/sse.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 804 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/llm/test/lib/sse.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/llm/test/lib/sse.ts
-
curl -L -o sse.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/llm/test/lib/sse.ts
804 Bytes
| /** | |
| * Helpers for building deterministic SSE bodies in tests. | |
| * | |
| * Inline template-literal SSE strings are hard to write and review when chunks | |
| * contain JSON; this helper accepts plain values and serializes them, so test | |
| * authors only think about the chunk shapes, not the wire format. | |
| */ | |
| export const sseEvents = (...chunks: ReadonlyArray<unknown>): string => | |
| `${chunks.map(formatChunk).join("")}data: [DONE]\n\n` | |
| const formatChunk = (chunk: unknown) => `data: ${typeof chunk === "string" ? chunk : JSON.stringify(chunk)}\n\n` | |
| /** | |
| * Build an SSE body from already-serialized strings (used when the chunk shape | |
| * itself is part of what's being tested, e.g. malformed chunks). | |
| */ | |
| export const sseRaw = (...lines: ReadonlyArray<string>): string => lines.map((line) => `${line}\n\n`).join("") | |