@@ -52,6 +52,10 @@ func (s *Server) GetOpenAPI() string {
52
52
return string (prettyJSON )
53
53
}
54
54
55
+ // That's about 40 frames per second. It's slightly less
56
+ // because the action of taking a snapshot takes time too.
57
+ const snapshotInterval = 25 * time .Millisecond
58
+
55
59
// NewServer creates a new server instance
56
60
func NewServer (ctx context.Context , agentType mf.AgentType , process * termexec.Process , port int ) * Server {
57
61
router := chi .NewMux ()
@@ -72,9 +76,6 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
72
76
formatMessage := func (message string , userInput string ) string {
73
77
return mf .FormatAgentMessage (agentType , message , userInput )
74
78
}
75
- // That's about 40 frames per second. It's slightly less
76
- // because the action of taking a snapshot takes time too.
77
- snapshotInterval := 25 * time .Millisecond
78
79
conversation := st .NewConversation (ctx , st.ConversationConfig {
79
80
AgentIO : process ,
80
81
GetTime : func () time.Time {
@@ -84,17 +85,7 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
84
85
ScreenStabilityLength : 2 * time .Second ,
85
86
FormatMessage : formatMessage ,
86
87
})
87
- conversation .StartSnapshotLoop (ctx )
88
88
emitter := NewEventEmitter (1024 )
89
- go func () {
90
- for {
91
- emitter .UpdateStatusAndEmitChanges (conversation .Status ())
92
- emitter .UpdateMessagesAndEmitChanges (conversation .Messages ())
93
- emitter .UpdateScreenAndEmitChanges (conversation .Screen ())
94
- time .Sleep (snapshotInterval )
95
- }
96
- }()
97
-
98
89
s := & Server {
99
90
router : router ,
100
91
api : api ,
@@ -112,6 +103,18 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
112
103
return s
113
104
}
114
105
106
+ func (s * Server ) StartSnapshotLoop (ctx context.Context ) {
107
+ s .conversation .StartSnapshotLoop (ctx )
108
+ go func () {
109
+ for {
110
+ s .emitter .UpdateStatusAndEmitChanges (s .conversation .Status ())
111
+ s .emitter .UpdateMessagesAndEmitChanges (s .conversation .Messages ())
112
+ s .emitter .UpdateScreenAndEmitChanges (s .conversation .Screen ())
113
+ time .Sleep (snapshotInterval )
114
+ }
115
+ }()
116
+ }
117
+
115
118
// registerRoutes sets up all API endpoints
116
119
func (s * Server ) registerRoutes () {
117
120
// GET /status endpoint
0 commit comments