File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -191,6 +191,31 @@ describe("opencode glance plugin", () => {
191191 )
192192 } )
193193
194+ it ( "parses image events split across SSE chunks" , async ( ) => {
195+ const expiresAt = Date . now ( ) + 60_000
196+
197+ vi . stubGlobal (
198+ "fetch" ,
199+ routedFetch ( {
200+ session : { id : "sess-chunked" , url : "/s/sess-chunked" } ,
201+ sseEvents : [
202+ 'event: image\ndata: {"url":"https://glance.sh/chunked.png",' ,
203+ `"expiresAt":${ expiresAt } }\n\n` ,
204+ ] ,
205+ } ) ,
206+ )
207+
208+ const GlancePlugin = await loadPlugin ( )
209+ const plugin = await GlancePlugin ( mockClient ( ) )
210+
211+ await plugin . tool . glance . execute ( { } )
212+
213+ const ctx = mockContext ( )
214+ const result = await plugin . tool . glance_wait . execute ( { } , ctx )
215+
216+ expect ( result ) . toContain ( "https://glance.sh/chunked.png" )
217+ } )
218+
194219 it ( "returns timeout message when aborted" , async ( ) => {
195220 vi . stubGlobal (
196221 "fetch" ,
Original file line number Diff line number Diff line change @@ -120,6 +120,8 @@ async function listenForImages(
120120 const reader = res . body . getReader ( )
121121 const decoder = new TextDecoder ( )
122122 let buffer = ""
123+ let eventType = ""
124+ let dataLines : string [ ] = [ ]
123125
124126 const timeout = setTimeout ( ( ) => {
125127 reader . cancel ( )
@@ -140,9 +142,6 @@ async function listenForImages(
140142 const lines = buffer . split ( "\n" )
141143 buffer = lines . pop ( ) ?? ""
142144
143- let eventType = ""
144- let dataLines : string [ ] = [ ]
145-
146145 for ( const line of lines ) {
147146 if ( line . startsWith ( "event: " ) ) {
148147 eventType = line . slice ( 7 ) . trim ( )
You can’t perform that action at this time.
0 commit comments