From 776b0ceb6739b5f48f1e3d43f60877e07c0a0c7e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 22:51:49 +0000 Subject: [PATCH] Refactor Copilot session event dispatch Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- agent/provider/copilotagent/copilot.go | 46 ++++++++++++-------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/agent/provider/copilotagent/copilot.go b/agent/provider/copilotagent/copilot.go index 962c9f12..855492d4 100644 --- a/agent/provider/copilotagent/copilot.go +++ b/agent/provider/copilotagent/copilot.go @@ -121,30 +121,7 @@ func (p *provider) run(ctx context.Context, messages []*message.Message, options yield(nil, err) return } - var update *agent.ResponseUpdate - var done bool - var eventErr error - switch data := event.Data.(type) { - case *copilot.AssistantMessageDeltaData: - update = p.assistantMessageDeltaUpdate(event, data) - case *copilot.AssistantMessageData: - update = p.assistantMessageUpdate(event, data, isStreaming) - case *copilot.ToolExecutionStartData: - update = p.toolExecutionStartUpdate(event, data) - case *copilot.ToolExecutionCompleteData: - update = p.toolExecutionCompleteUpdate(event, data) - case *copilot.AssistantUsageData: - update = p.assistantUsageUpdate(event, data) - case *copilot.SessionIdleData: - update = rawEventUpdate(event) - done = true - case *copilot.SessionErrorData: - update = rawEventUpdate(event) - done = true - eventErr = fmt.Errorf("session error: %s", sessionErrorMessage(data)) - default: - update = rawEventUpdate(event) - } + update, done, eventErr := p.responseUpdateForSessionEvent(event, isStreaming) if update != nil { if !yield(update, nil) { return @@ -161,6 +138,27 @@ func (p *provider) run(ctx context.Context, messages []*message.Message, options } } +func (p *provider) responseUpdateForSessionEvent(event copilot.SessionEvent, isStreaming bool) (*agent.ResponseUpdate, bool, error) { + switch data := event.Data.(type) { + case *copilot.AssistantMessageDeltaData: + return p.assistantMessageDeltaUpdate(event, data), false, nil + case *copilot.AssistantMessageData: + return p.assistantMessageUpdate(event, data, isStreaming), false, nil + case *copilot.ToolExecutionStartData: + return p.toolExecutionStartUpdate(event, data), false, nil + case *copilot.ToolExecutionCompleteData: + return p.toolExecutionCompleteUpdate(event, data), false, nil + case *copilot.AssistantUsageData: + return p.assistantUsageUpdate(event, data), false, nil + case *copilot.SessionIdleData: + return rawEventUpdate(event), true, nil + case *copilot.SessionErrorData: + return rawEventUpdate(event), true, fmt.Errorf("session error: %s", sessionErrorMessage(data)) + default: + return rawEventUpdate(event), false, nil + } +} + type sessionEventQueue struct { mu sync.Mutex items []copilot.SessionEvent