MCPcopy Create free account
hub / github.com/anomalyco/opencode / socket

Function socket

packages/opencode/src/plugin/openai/ws-pool.ts:216–241  ·  view source on GitHub ↗
(
  entry: PoolEntry,
  url: string,
  headers: Record<string, string>,
  connectTimeout: number,
  maxConnectionAge: number,
  signal?: AbortSignal | null,
)

Source from the content-addressed store, hash-verified

214}
215
216async function socket(
217 entry: PoolEntry,
218 url: string,
219 headers: Record<string, string>,
220 connectTimeout: number,
221 maxConnectionAge: number,
222 signal?: AbortSignal | null,
223) {
224 if (
225 entry.socket?.readyState === WebSocket.OPEN &&
226 entry.connectedAt &&
227 Date.now() - entry.connectedAt < maxConnectionAge
228 ) {
229 return entry.socket
230 }
231
232 invalidate(entry)
233 const next = await OpenAIWebSocket.connectResponsesWebSocket({
234 url: OpenAIWebSocket.toWebSocketUrl(url),
235 headers,
236 timeout: connectTimeout,
237 signal: signal ?? undefined,
238 })
239 entry.connectedAt = Date.now()
240 return next
241}
242
243function invalidate(entry: PoolEntry) {
244 if (entry.socket) {

Callers 1

websocketFetchFunction · 0.70

Calls 1

invalidateFunction · 0.70

Tested by

no test coverage detected