-
Notifications
You must be signed in to change notification settings - Fork 106
refactor(lib): extract Conversation interface #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ type Server struct { | |
| srv *http.Server | ||
| mu sync.RWMutex | ||
| logger *slog.Logger | ||
| conversation *st.Conversation | ||
| conversation *st.PTYConversation | ||
| agentio *termexec.Process | ||
| agentType mf.AgentType | ||
| emitter *EventEmitter | ||
|
|
@@ -237,7 +237,7 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) { | |
| return mf.FormatToolCall(config.AgentType, message) | ||
| } | ||
|
|
||
| conversation := st.NewConversation(ctx, st.ConversationConfig{ | ||
| conversation := st.NewPTY(ctx, st.PTYConversationConfig{ | ||
| AgentType: config.AgentType, | ||
| AgentIO: config.Process, | ||
| GetTime: func() time.Time { | ||
|
|
@@ -331,15 +331,15 @@ func sseMiddleware(ctx huma.Context, next func(huma.Context)) { | |
| } | ||
|
|
||
| func (s *Server) StartSnapshotLoop(ctx context.Context) { | ||
| s.conversation.StartSnapshotLoop(ctx) | ||
| s.conversation.Start(ctx) | ||
| go func() { | ||
| for { | ||
| currentStatus := s.conversation.Status() | ||
|
|
||
| // Send initial prompt when agent becomes stable for the first time | ||
| if !s.conversation.InitialPromptSent && convertStatus(currentStatus) == AgentStatusStable { | ||
|
|
||
| if err := s.conversation.SendMessage(FormatMessage(s.agentType, s.conversation.InitialPrompt)...); err != nil { | ||
| if err := s.conversation.Send(FormatMessage(s.agentType, s.conversation.InitialPrompt)...); err != nil { | ||
| s.logger.Error("Failed to send initial prompt", "error", err) | ||
| } else { | ||
| s.conversation.InitialPromptSent = true | ||
|
|
@@ -350,7 +350,7 @@ func (s *Server) StartSnapshotLoop(ctx context.Context) { | |
| } | ||
| s.emitter.UpdateStatusAndEmitChanges(currentStatus, s.agentType) | ||
| s.emitter.UpdateMessagesAndEmitChanges(s.conversation.Messages()) | ||
| s.emitter.UpdateScreenAndEmitChanges(s.conversation.Screen()) | ||
| s.emitter.UpdateScreenAndEmitChanges(s.conversation.String()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Are there repercussions to implementing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. I'd prefer for the method name to be applicable to be all protocols, so |
||
| time.Sleep(snapshotInterval) | ||
| } | ||
| }() | ||
|
|
@@ -449,7 +449,7 @@ func (s *Server) createMessage(ctx context.Context, input *MessageRequest) (*Mes | |
|
|
||
| switch input.Body.Type { | ||
| case MessageTypeUser: | ||
| if err := s.conversation.SendMessage(FormatMessage(s.agentType, input.Body.Content)...); err != nil { | ||
| if err := s.conversation.Send(FormatMessage(s.agentType, input.Body.Content)...); err != nil { | ||
| return nil, xerrors.Errorf("failed to send message: %w", err) | ||
| } | ||
| case MessageTypeRaw: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnstcn Shouldn't this be *st.Conversation ? (It's possible that I'm lacking the context/motive behind this refactor, If we have extracted an interface, shouldn't we be using it rather than coupling this to the concrete implementation ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should, but there's some more coupling to be disentangled here before we can do that.