@@ -5,8 +5,6 @@ import { findDoubleNewlineIndex, LineDecoder } from '../internal/decoders/line';
5
5
import { ReadableStreamToAsyncIterable } from '../internal/shims' ;
6
6
import { isAbortError } from '../internal/errors' ;
7
7
import { encodeUTF8 } from '../internal/utils/bytes' ;
8
- import { loggerFor } from '../internal/utils/log' ;
9
- import type { Opencode } from '../client' ;
10
8
11
9
type Bytes = string | ArrayBuffer | Uint8Array | null | undefined ;
12
10
@@ -18,24 +16,16 @@ export type ServerSentEvent = {
18
16
19
17
export class Stream < Item > implements AsyncIterable < Item > {
20
18
controller : AbortController ;
21
- #client: Opencode | undefined ;
22
19
23
20
constructor (
24
21
private iterator : ( ) => AsyncIterator < Item > ,
25
22
controller : AbortController ,
26
- client ?: Opencode ,
27
23
) {
28
24
this . controller = controller ;
29
- this . #client = client ;
30
25
}
31
26
32
- static fromSSEResponse < Item > (
33
- response : Response ,
34
- controller : AbortController ,
35
- client ?: Opencode ,
36
- ) : Stream < Item > {
27
+ static fromSSEResponse < Item > ( response : Response , controller : AbortController ) : Stream < Item > {
37
28
let consumed = false ;
38
- const logger = client ? loggerFor ( client ) : console ;
39
29
40
30
async function * iterator ( ) : AsyncIterator < Item , any , undefined > {
41
31
if ( consumed ) {
@@ -48,8 +38,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
48
38
try {
49
39
yield JSON . parse ( sse . data ) ;
50
40
} catch ( e ) {
51
- logger . error ( `Could not parse message into JSON:` , sse . data ) ;
52
- logger . error ( `From chunk:` , sse . raw ) ;
41
+ console . error ( `Could not parse message into JSON:` , sse . data ) ;
42
+ console . error ( `From chunk:` , sse . raw ) ;
53
43
throw e ;
54
44
}
55
45
}
@@ -64,18 +54,14 @@ export class Stream<Item> implements AsyncIterable<Item> {
64
54
}
65
55
}
66
56
67
- return new Stream ( iterator , controller , client ) ;
57
+ return new Stream ( iterator , controller ) ;
68
58
}
69
59
70
60
/**
71
61
* Generates a Stream from a newline-separated ReadableStream
72
62
* where each item is a JSON value.
73
63
*/
74
- static fromReadableStream < Item > (
75
- readableStream : ReadableStream ,
76
- controller : AbortController ,
77
- client ?: Opencode ,
78
- ) : Stream < Item > {
64
+ static fromReadableStream < Item > ( readableStream : ReadableStream , controller : AbortController ) : Stream < Item > {
79
65
let consumed = false ;
80
66
81
67
async function * iterLines ( ) : AsyncGenerator < string , void , unknown > {
@@ -115,7 +101,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
115
101
}
116
102
}
117
103
118
- return new Stream ( iterator , controller , client ) ;
104
+ return new Stream ( iterator , controller ) ;
119
105
}
120
106
121
107
[ Symbol . asyncIterator ] ( ) : AsyncIterator < Item > {
@@ -145,8 +131,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
145
131
} ;
146
132
147
133
return [
148
- new Stream ( ( ) => teeIterator ( left ) , this . controller , this . #client ) ,
149
- new Stream ( ( ) => teeIterator ( right ) , this . controller , this . #client ) ,
134
+ new Stream ( ( ) => teeIterator ( left ) , this . controller ) ,
135
+ new Stream ( ( ) => teeIterator ( right ) , this . controller ) ,
150
136
] ;
151
137
}
152
138
0 commit comments