MCPcopy Index your code
hub / github.com/anomalyco/opencode / attach

Function attach

packages/opencode/src/plugin/openai/ws.ts:298–316  ·  view source on GitHub ↗
(next: WebSocket)

Source from the content-addressed store, hash-verified

296 }
297
298 function attach(next: WebSocket) {
299 cleanupSocket()
300 socket = next
301 socket.on("message", onMessage)
302 socket.once("error", onError)
303 socket.once("close", onClose)
304 cleanupSocket = () => {
305 socket.off("message", onMessage)
306 socket.off("error", onError)
307 socket.off("close", onClose)
308 }
309 const { stream: _stream, background: _background, ...payload } = options.body
310 resetIdleTimeout("idle timeout sending websocket request")
311 socket.send(JSON.stringify({ type: "response.create", ...payload }), (error) => {
312 if (completed) return
313 resetIdleTimeout("idle timeout waiting for websocket")
314 if (error) invalidate(new ProviderError.ResponseStreamError(error.message, { cause: error }))
315 })
316 }
317
318 return new Response(
319 new ReadableStream<Uint8Array>({

Callers 2

onMessageFunction · 0.70
startFunction · 0.70

Calls 6

cleanupSocketFunction · 0.85
resetIdleTimeoutFunction · 0.85
onMethod · 0.80
offMethod · 0.80
invalidateFunction · 0.70
sendMethod · 0.45

Tested by

no test coverage detected