From 477ca045b0184efe30e85cf3193f3ae3094d2766 Mon Sep 17 00:00:00 2001 From: berniegreen Date: Wed, 31 Dec 2025 12:26:13 -0600 Subject: [PATCH] refactor: update Vendor interface and Chatter for structured streaming (Phase 2) --- internal/core/chatter.go | 20 ++++++++++++++------ internal/plugins/ai/vendor.go | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/internal/core/chatter.go b/internal/core/chatter.go index adbd581f..37178c75 100644 --- a/internal/core/chatter.go +++ b/internal/core/chatter.go @@ -64,7 +64,7 @@ func (o *Chatter) Send(request *domain.ChatRequest, opts *domain.ChatOptions) (s message := "" if o.Stream { - responseChan := make(chan string) + responseChan := make(chan domain.StreamUpdate) errChan := make(chan error, 1) done := make(chan struct{}) printedStream := false @@ -76,11 +76,19 @@ func (o *Chatter) Send(request *domain.ChatRequest, opts *domain.ChatOptions) (s } }() - for response := range responseChan { - message += response - if !opts.SuppressThink { - fmt.Print(response) - printedStream = true + for update := range responseChan { + switch update.Type { + case domain.StreamTypeContent: + message += update.Content + if !opts.SuppressThink { + fmt.Print(update.Content) + printedStream = true + } + case domain.StreamTypeUsage: + // Placeholder for metadata handling + // Future logic: Store usage in session or context + case domain.StreamTypeError: + errChan <- errors.New(update.Content) } } diff --git a/internal/plugins/ai/vendor.go b/internal/plugins/ai/vendor.go index a9c9b929..c3134618 100644 --- a/internal/plugins/ai/vendor.go +++ b/internal/plugins/ai/vendor.go @@ -12,7 +12,7 @@ import ( type Vendor interface { plugins.Plugin ListModels() ([]string, error) - SendStream([]*chat.ChatCompletionMessage, *domain.ChatOptions, chan string) error + SendStream([]*chat.ChatCompletionMessage, *domain.ChatOptions, chan domain.StreamUpdate) error Send(context.Context, []*chat.ChatCompletionMessage, *domain.ChatOptions) (string, error) NeedsRawMode(modelName string) bool }