MCPcopy
hub / github.com/anomalyco/opencode / pull

Function pull

packages/core/src/aisdk.ts:33–60  ·  view source on GitHub ↗
(ctrl)

Source from the content-addressed store, hash-verified

31 const reader = res.body.getReader()
32 const body = new ReadableStream<Uint8Array>({
33 async pull(ctrl) {
34 const part = await new Promise<Awaited<ReturnType<typeof reader.read>>>((resolve, reject) => {
35 const id = setTimeout(() => {
36 const err = new Error("SSE read timed out")
37 ctl.abort(err)
38 void reader.cancel(err)
39 reject(err)
40 }, ms)
41
42 reader.read().then(
43 (part) => {
44 clearTimeout(id)
45 resolve(part)
46 },
47 (err) => {
48 clearTimeout(id)
49 reject(err)
50 },
51 )
52 })
53
54 if (part.done) {
55 ctrl.close()
56 return
57 }
58
59 ctrl.enqueue(part.value)
60 },
61 async cancel(reason) {
62 ctl.abort(reason)
63 await reader.cancel(reason)

Callers

nothing calls this directly

Calls 6

resolveFunction · 0.70
cancelMethod · 0.65
readMethod · 0.65
rejectFunction · 0.50
abortMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected