Skip to content

Commit 747d6c5

Browse files
authored
Merge pull request #2539 from dgageot/extract-stream-processor
refactor(runtime): drop unused receiver from handleStream
2 parents 64b2bd1 + d624cbd commit 747d6c5

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

pkg/runtime/fallback.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (r *LocalRuntime) tryModelWithFallback(
285285
}
286286
}
287287

288-
res, err := r.handleStream(ctx, stream, a, agentTools, sess, m, events)
288+
res, err := handleStream(ctx, stream, a, agentTools, sess, m, events)
289289
if err != nil {
290290
lastErr = err
291291

pkg/runtime/streaming.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ type streamResult struct {
3434
// events (content deltas, partial tool calls, reasoning tokens) and returning
3535
// the aggregated streamResult. The caller is responsible for adding the
3636
// resulting assistant message to the session.
37-
func (r *LocalRuntime) handleStream(ctx context.Context, stream chat.MessageStream, a *agent.Agent, agentTools []tools.Tool, sess *session.Session, m *modelsdev.Model, events chan Event) (streamResult, error) {
37+
//
38+
// handleStream is a pure stream-aggregation routine: it does not touch
39+
// runtime state and can be unit-tested by feeding a mock chat.MessageStream.
40+
// It is intentionally a free function rather than a method on *LocalRuntime
41+
// so the dependency direction is explicit (the loop calls into the chunker,
42+
// never the reverse).
43+
func handleStream(ctx context.Context, stream chat.MessageStream, a *agent.Agent, agentTools []tools.Tool, sess *session.Session, m *modelsdev.Model, events chan<- Event) (streamResult, error) {
3844
defer stream.Close()
3945

4046
var fullContent strings.Builder

0 commit comments

Comments
 (0)