MCPcopy Create free account
hub / github.com/experdot/pointer / sendMessageStreaming

Method sendMessageStreaming

src/main/aiHandler.ts:278–330  ·  view source on GitHub ↗
(
    event: Electron.IpcMainInvokeEvent,
    request: AIRequest,
    eventChannel: string
  )

Source from the content-addressed store, hash-verified

276 }
277
278 public async sendMessageStreaming(
279 event: Electron.IpcMainInvokeEvent,
280 request: AIRequest,
281 eventChannel: string
282 ): Promise<void> {
283 const abortController = new AbortController()
284 this.abortControllers.set(request.requestId, abortController)
285 this.initRequestState(request.requestId, event, eventChannel)
286
287 try {
288 const modelConfig = this.getModelConfig(request.modelConfig)
289 const apiMessages = await this.prepareApiMessages(request.messages, modelConfig)
290 const response = await this.fetchStreamingResponse(
291 request,
292 apiMessages,
293 modelConfig,
294 abortController
295 )
296
297 if (!response.ok) {
298 let errorDetail = ''
299 try {
300 const errorBody = await response.text()
301 const parsed = JSON.parse(errorBody)
302 errorDetail = parsed.error?.message || parsed.message || errorBody
303 } catch {
304 errorDetail = response.statusText
305 }
306
307 this.finalizeTerminalError(request.requestId, `HTTP ${response.status}: ${errorDetail}`)
308 return
309 }
310
311 const reader = response.body?.getReader()
312 if (!reader) {
313 this.finalizeTerminalError(request.requestId, 'No response body reader available')
314 return
315 }
316
317 const parser = this.createStreamParser(request.requestId)
318 await this.processStreamResponse(request.requestId, reader, parser)
319 } catch (error) {
320 if (error instanceof Error && error.name === 'AbortError') {
321 this.finalizeComplete(request.requestId)
322 return
323 }
324
325 this.finalizeTerminalError(
326 request.requestId,
327 error instanceof Error ? error.message : 'Unknown error'
328 )
329 }
330 }
331
332 public async stopStreaming(requestId: string): Promise<void> {
333 const abortController = this.abortControllers.get(requestId)

Callers 2

sendMessageMethod · 0.80
setupAIHandlersFunction · 0.80

Calls 9

initRequestStateMethod · 0.95
getModelConfigMethod · 0.95
prepareApiMessagesMethod · 0.95
finalizeTerminalErrorMethod · 0.95
createStreamParserMethod · 0.95
processStreamResponseMethod · 0.95
finalizeCompleteMethod · 0.95
parseMethod · 0.65

Tested by

no test coverage detected