Skip to content
Merged
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
25 changes: 25 additions & 0 deletions opencode/glance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ describe("opencode glance plugin", () => {
)
})

it("parses image events split across SSE chunks", async () => {
const expiresAt = Date.now() + 60_000

vi.stubGlobal(
"fetch",
routedFetch({
session: { id: "sess-chunked", url: "/s/sess-chunked" },
sseEvents: [
'event: image\ndata: {"url":"https://glance.sh/chunked.png",',
`"expiresAt":${expiresAt}}\n\n`,
],
}),
)

const GlancePlugin = await loadPlugin()
const plugin = await GlancePlugin(mockClient())

await plugin.tool.glance.execute({})

const ctx = mockContext()
const result = await plugin.tool.glance_wait.execute({}, ctx)

expect(result).toContain("https://glance.sh/chunked.png")
})

it("returns timeout message when aborted", async () => {
vi.stubGlobal(
"fetch",
Expand Down
5 changes: 2 additions & 3 deletions opencode/glance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ async function listenForImages(
const reader = res.body.getReader()
const decoder = new TextDecoder()
let buffer = ""
let eventType = ""
let dataLines: string[] = []

const timeout = setTimeout(() => {
reader.cancel()
Expand All @@ -140,9 +142,6 @@ async function listenForImages(
const lines = buffer.split("\n")
buffer = lines.pop() ?? ""

let eventType = ""
let dataLines: string[] = []

for (const line of lines) {
if (line.startsWith("event: ")) {
eventType = line.slice(7).trim()
Expand Down