Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/opencode/src/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import { ProviderError } from "./error"

const OPENAI_HEADER_TIMEOUT_DEFAULT = 300_000

function wrapSSE(res: Response, ms: number, ctl: AbortController) {
function wrapStream(res: Response, ms: number, ctl: AbortController) {
if (typeof ms !== "number" || ms <= 0) return res
if (!res.body) return res
if (!res.headers.get("content-type")?.includes("text/event-stream")) return res

const reader = res.body.getReader()
const body = new ReadableStream<Uint8Array>({
Expand Down Expand Up @@ -1821,7 +1820,7 @@ const layer = Layer.effect(
}).finally(() => headerTimeoutCtl?.clear())

if (!chunkAbortCtl) return res
return wrapSSE(res, chunkTimeout, chunkAbortCtl)
return wrapStream(res, chunkTimeout, chunkAbortCtl)
}

const bundledLoader = BUNDLED_PROVIDERS[model.api.npm]
Expand Down
8 changes: 7 additions & 1 deletion packages/opencode/test/lib/llm-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Sse = {
type: "sse"
head: unknown[]
tail: unknown[]
contentType?: string | false
wait?: PromiseLike<unknown>
hang?: boolean
error?: unknown
Expand Down Expand Up @@ -427,7 +428,10 @@ function send(item: Sse) {
if (item.error) end = Stream.concat(empty, Stream.fail(item.error))
else if (item.hang) end = Stream.concat(empty, Stream.never)

return HttpServerResponse.stream(Stream.concat(body, end), { contentType: "text/event-stream" })
return HttpServerResponse.stream(
Stream.concat(body, end),
item.contentType === false ? undefined : { contentType: item.contentType ?? "text/event-stream" },
)
}

const reset = Effect.fn("TestLLMServer.reset")(function* (item: Sse) {
Expand Down Expand Up @@ -577,6 +581,7 @@ export function raw(input: {
chunks?: unknown[]
head?: unknown[]
tail?: unknown[]
contentType?: string | false
wait?: PromiseLike<unknown>
hang?: boolean
error?: unknown
Expand All @@ -586,6 +591,7 @@ export function raw(input: {
type: "sse",
head: input.head ?? input.chunks ?? [],
tail: input.tail ?? [],
contentType: input.contentType,
wait: input.wait,
hang: input.hang,
error: input.error,
Expand Down
Loading
Loading