MCPcopy Create free account
hub / github.com/astercloud/aster / handleStream

Method handleStream

pkg/agent/actor.go:315–344  ·  view source on GitHub ↗

handleStream 处理流式对话

(_ *actor.Context, msg *StreamMsg)

Source from the content-addressed store, hash-verified

313
314// handleStream 处理流式对话
315func (a *AgentActor) handleStream(_ *actor.Context, msg *StreamMsg) {
316 execCtx, cancel := a.withCancellation(msg.Ctx)
317 defer cancel()
318
319 go func() {
320 reader := a.agent.Stream(execCtx, msg.Text)
321
322 for {
323 event, err := reader.Recv()
324 if err != nil {
325 // EOF 或错误
326 if msg.EventCh != nil {
327 msg.EventCh <- &StreamEventMsg{
328 Type: "done",
329 Error: err,
330 }
331 close(msg.EventCh)
332 }
333 return
334 }
335
336 if event != nil && msg.EventCh != nil {
337 msg.EventCh <- &StreamEventMsg{
338 Type: "event",
339 Content: event,
340 }
341 }
342 }
343 }()
344}
345
346// handleToolCall 处理工具调用
347func (a *AgentActor) handleToolCall(ctx *actor.Context, msg *ToolCallMsg) {

Callers 1

ReceiveMethod · 0.95

Calls 4

withCancellationMethod · 0.95
cancelFunction · 0.85
RecvMethod · 0.80
StreamMethod · 0.65

Tested by

no test coverage detected