diff --git a/internal/conversation/conversation.go b/internal/conversation/conversation.go index a9e0b55..3ce4171 100644 --- a/internal/conversation/conversation.go +++ b/internal/conversation/conversation.go @@ -190,9 +190,9 @@ type AssistantUpdate struct { func (AssistantUpdate) Type() EventType { return EventAssistantUpdate } // Done reports that the Inference the subscriber joined has returned. -// Err is nil on success. +// Error is empty on success. type Done struct { - Err error `json:"err"` + Error string `json:"error,omitempty"` } func (Done) Type() EventType { return EventDone } @@ -297,7 +297,11 @@ func (inf *Inference) follow( } } if done { - return send(ctx, ch, Done{Err: err}) + var errStr string + if err != nil { + errStr = err.Error() + } + return send(ctx, ch, Done{Error: errStr}) } // Wait for the call to close wait (when it appends new // events or finishes), or for the subscriber to cancel ctx. diff --git a/internal/conversation/conversation_test.go b/internal/conversation/conversation_test.go index 3527ced..d166fe9 100644 --- a/internal/conversation/conversation_test.go +++ b/internal/conversation/conversation_test.go @@ -1500,8 +1500,8 @@ func TestSubscribeInference(t *testing.T) { } asst = &e case Done: - if e.Err != nil { - t.Errorf("Done.Err = %v, want nil", e.Err) + if e.Error != "" { + t.Errorf("Done.Error = %q, want empty", e.Error) } default: t.Fatalf("unexpected event %v", e) @@ -1593,8 +1593,8 @@ func TestSubscribeInferenceError(t *testing.T) { if !ok { t.Fatalf("last event = %v, want Done", got[len(got)-1]) } - if done.Err == nil { - t.Fatal("Done.Err = nil, want the stream error") + if done.Error == "" { + t.Fatal("Done.Error = empty, want the stream error") } rows, err := db.New(c.db.Reader). SelectMessagesConversationId(ctx, c.id) @@ -1710,8 +1710,8 @@ func TestSubscribeToolResult(t *testing.T) { } } case Done: - if e.Err != nil { - t.Errorf("Done.Err = %v, want nil", e.Err) + if e.Error != "" { + t.Errorf("Done.Error = %q, want empty", e.Error) } default: t.Errorf("event %d = %v, want MessageSaved or Done", i, e) @@ -1902,8 +1902,8 @@ func TestSubscribeStartupError(t *testing.T) { } sawTool = true case Done: - if e.Err == nil { - t.Error("Done.Err = nil, want the startup failure") + if e.Error == "" { + t.Error("Done.Error = empty, want the startup failure") } } } @@ -2582,8 +2582,8 @@ func TestInferenceEventsFastFailure(t *testing.T) { if !ok { t.Fatalf("event = %v, want Done", got[0]) } - if done.Err == nil || done.Err.Error() != runErr.Error() { - t.Fatalf("Done.Err = %v, want %v", done.Err, runErr) + if done.Error != runErr.Error() { + t.Fatalf("Done.Error = %q, want %q", done.Error, runErr.Error()) } }