Refactor conversation pkg done
This commit is contained in:
@@ -190,9 +190,9 @@ type AssistantUpdate struct {
|
|||||||
func (AssistantUpdate) Type() EventType { return EventAssistantUpdate }
|
func (AssistantUpdate) Type() EventType { return EventAssistantUpdate }
|
||||||
|
|
||||||
// Done reports that the Inference the subscriber joined has returned.
|
// Done reports that the Inference the subscriber joined has returned.
|
||||||
// Err is nil on success.
|
// Error is empty on success.
|
||||||
type Done struct {
|
type Done struct {
|
||||||
Err error `json:"err"`
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Done) Type() EventType { return EventDone }
|
func (Done) Type() EventType { return EventDone }
|
||||||
@@ -297,7 +297,11 @@ func (inf *Inference) follow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if done {
|
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
|
// Wait for the call to close wait (when it appends new
|
||||||
// events or finishes), or for the subscriber to cancel ctx.
|
// events or finishes), or for the subscriber to cancel ctx.
|
||||||
|
|||||||
@@ -1500,8 +1500,8 @@ func TestSubscribeInference(t *testing.T) {
|
|||||||
}
|
}
|
||||||
asst = &e
|
asst = &e
|
||||||
case Done:
|
case Done:
|
||||||
if e.Err != nil {
|
if e.Error != "" {
|
||||||
t.Errorf("Done.Err = %v, want nil", e.Err)
|
t.Errorf("Done.Error = %q, want empty", e.Error)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected event %v", e)
|
t.Fatalf("unexpected event %v", e)
|
||||||
@@ -1593,8 +1593,8 @@ func TestSubscribeInferenceError(t *testing.T) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("last event = %v, want Done", got[len(got)-1])
|
t.Fatalf("last event = %v, want Done", got[len(got)-1])
|
||||||
}
|
}
|
||||||
if done.Err == nil {
|
if done.Error == "" {
|
||||||
t.Fatal("Done.Err = nil, want the stream error")
|
t.Fatal("Done.Error = empty, want the stream error")
|
||||||
}
|
}
|
||||||
rows, err := db.New(c.db.Reader).
|
rows, err := db.New(c.db.Reader).
|
||||||
SelectMessagesConversationId(ctx, c.id)
|
SelectMessagesConversationId(ctx, c.id)
|
||||||
@@ -1710,8 +1710,8 @@ func TestSubscribeToolResult(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Done:
|
case Done:
|
||||||
if e.Err != nil {
|
if e.Error != "" {
|
||||||
t.Errorf("Done.Err = %v, want nil", e.Err)
|
t.Errorf("Done.Error = %q, want empty", e.Error)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
t.Errorf("event %d = %v, want MessageSaved or Done", i, e)
|
t.Errorf("event %d = %v, want MessageSaved or Done", i, e)
|
||||||
@@ -1902,8 +1902,8 @@ func TestSubscribeStartupError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
sawTool = true
|
sawTool = true
|
||||||
case Done:
|
case Done:
|
||||||
if e.Err == nil {
|
if e.Error == "" {
|
||||||
t.Error("Done.Err = nil, want the startup failure")
|
t.Error("Done.Error = empty, want the startup failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2582,8 +2582,8 @@ func TestInferenceEventsFastFailure(t *testing.T) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("event = %v, want Done", got[0])
|
t.Fatalf("event = %v, want Done", got[0])
|
||||||
}
|
}
|
||||||
if done.Err == nil || done.Err.Error() != runErr.Error() {
|
if done.Error != runErr.Error() {
|
||||||
t.Fatalf("Done.Err = %v, want %v", done.Err, runErr)
|
t.Fatalf("Done.Error = %q, want %q", done.Error, runErr.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user