Skip to content

Commit e3bd936

Browse files
committed
chore(lib): extract Conversation interface
1 parent b8d6e9b commit e3bd936

6 files changed

Lines changed: 554 additions & 548 deletions

File tree

lib/httpapi/server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Server struct {
4040
srv *http.Server
4141
mu sync.RWMutex
4242
logger *slog.Logger
43-
conversation *st.Conversation
43+
conversation *st.PTYConversation
4444
agentio *termexec.Process
4545
agentType mf.AgentType
4646
emitter *EventEmitter
@@ -237,7 +237,7 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
237237
return mf.FormatToolCall(config.AgentType, message)
238238
}
239239

240-
conversation := st.NewConversation(ctx, st.ConversationConfig{
240+
conversation := st.NewPTY(ctx, st.PTYConversationConfig{
241241
AgentType: config.AgentType,
242242
AgentIO: config.Process,
243243
GetTime: func() time.Time {
@@ -331,15 +331,15 @@ func sseMiddleware(ctx huma.Context, next func(huma.Context)) {
331331
}
332332

333333
func (s *Server) StartSnapshotLoop(ctx context.Context) {
334-
s.conversation.StartSnapshotLoop(ctx)
334+
s.conversation.Start(ctx)
335335
go func() {
336336
for {
337337
currentStatus := s.conversation.Status()
338338

339339
// Send initial prompt when agent becomes stable for the first time
340340
if !s.conversation.InitialPromptSent && convertStatus(currentStatus) == AgentStatusStable {
341341

342-
if err := s.conversation.SendMessage(FormatMessage(s.agentType, s.conversation.InitialPrompt)...); err != nil {
342+
if err := s.conversation.Send(FormatMessage(s.agentType, s.conversation.InitialPrompt)...); err != nil {
343343
s.logger.Error("Failed to send initial prompt", "error", err)
344344
} else {
345345
s.conversation.InitialPromptSent = true
@@ -350,7 +350,7 @@ func (s *Server) StartSnapshotLoop(ctx context.Context) {
350350
}
351351
s.emitter.UpdateStatusAndEmitChanges(currentStatus, s.agentType)
352352
s.emitter.UpdateMessagesAndEmitChanges(s.conversation.Messages())
353-
s.emitter.UpdateScreenAndEmitChanges(s.conversation.Screen())
353+
s.emitter.UpdateScreenAndEmitChanges(s.conversation.String())
354354
time.Sleep(snapshotInterval)
355355
}
356356
}()
@@ -449,7 +449,7 @@ func (s *Server) createMessage(ctx context.Context, input *MessageRequest) (*Mes
449449

450450
switch input.Body.Type {
451451
case MessageTypeUser:
452-
if err := s.conversation.SendMessage(FormatMessage(s.agentType, input.Body.Content)...); err != nil {
452+
if err := s.conversation.Send(FormatMessage(s.agentType, input.Body.Content)...); err != nil {
453453
return nil, xerrors.Errorf("failed to send message: %w", err)
454454
}
455455
case MessageTypeRaw:

0 commit comments

Comments
 (0)