MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / start

Function start

web/src/llm-api/canopywave.ts:265–348  ·  view source on GitHub ↗
(controller)

Source from the content-addressed store, hash-verified

263
264 const stream = new ReadableStream({
265 async start(controller) {
266 const decoder = new TextDecoder()
267 let buffer = ''
268
269 controller.enqueue(
270 new TextEncoder().encode(`: connected ${new Date().toISOString()}\n`),
271 )
272
273 heartbeatInterval = setInterval(() => {
274 if (!clientDisconnected) {
275 try {
276 controller.enqueue(
277 new TextEncoder().encode(
278 `: heartbeat ${new Date().toISOString()}\n\n`,
279 ),
280 )
281 } catch {
282 // client disconnected
283 }
284 }
285 }, 30000)
286
287 try {
288 let done = false
289 while (!done) {
290 const result = await reader.read()
291 done = result.done
292 const value = result.value
293
294 if (done) break
295
296 buffer += decoder.decode(value, { stream: true })
297 let lineEnd = buffer.indexOf('\n')
298
299 while (lineEnd !== -1) {
300 const line = buffer.slice(0, lineEnd + 1)
301 buffer = buffer.slice(lineEnd + 1)
302
303 const lineResult = await handleLine({
304 userId,
305 stripeCustomerId,
306 agentId,
307 clientId,
308 clientRequestId,
309 costMode,
310 startTime,
311 request: auditRequest,
312 originalModel,
313 line,
314 state,
315 logger,
316 insertMessage: insertMessageBigquery,
317 })
318 state = lineResult.state
319
320 if (!clientDisconnected) {
321 try {
322 controller.enqueue(new TextEncoder().encode(lineResult.patchedLine))

Callers

nothing calls this directly

Calls 4

getErrorObjectFunction · 0.90
enqueueMethod · 0.80
closeMethod · 0.80
handleLineFunction · 0.70

Tested by

no test coverage detected