Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb51050a

Browse files
committed
Only report user messages
1 parent6cb03be commitb51050a

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

‎cli/exp_mcp.go‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ func (r *RootCmd) mcpServer() *serpent.Command {
493493
}
494494

495495
func (s*mcpServer)startReporter(ctx context.Context,inv*serpent.Invocation) {
496+
// lastMessageID is the ID of the last *user* message that we saw. A user
497+
// message only happens when interacting via the API (as opposed to
498+
// interacting with the terminal directly).
496499
varlastMessageIDint64
497500
shouldUpdate:=func(itemreportTask) codersdk.WorkspaceAppStatusState {
498501
// Always send self-reported updates.
@@ -505,18 +508,17 @@ func (s *mcpServer) startReporter(ctx context.Context, inv *serpent.Invocation)
505508
codersdk.WorkspaceAppStatusStateFailure:
506509
returnitem.state
507510
}
508-
// Always send "working" when there is a new message, since this means the
509-
// user submitted a message through the API and we know the LLM will begin
510-
// work soon if it has not already.
511+
// Always send "working" when there is a new user message, since we know the
512+
// LLM will begin work soon if it has not already.
511513
ifitem.messageID>lastMessageID {
512514
returncodersdk.WorkspaceAppStatusStateWorking
513515
}
514-
// Otherwise, if the state is "working" and there have been no newmessages,
515-
// it means either that the LLM is still working or it means the user has
516-
// interacted with the terminal directly. For now, we are ignoring these
517-
// updates. This risks missing cases where the user manually submits a new
518-
// prompt and the LLM becomes active and does not update itself, but it
519-
// avoids spamming useless status updates.
516+
// Otherwise, if the state is "working" and there have been no newuser
517+
//messages,it means either that the LLM is still working or it means the
518+
//user hasinteracted with the terminal directly. For now, we are ignoring
519+
//theseupdates. This risks missing cases where the user manually submits
520+
//a newprompt and the LLM becomes active and does not update itself, but
521+
//itavoids spamming useless status updates.
520522
return""
521523
}
522524
varlastPayload agentsdk.PatchAppStatus
@@ -599,12 +601,14 @@ func (s *mcpServer) startWatcher(ctx context.Context, inv *serpent.Invocation) {
599601
return
600602
}
601603
case agentapi.EventMessageUpdate:
602-
err:=s.queue.Push(reportTask{
603-
messageID:ev.Id,
604-
})
605-
iferr!=nil {
606-
cliui.Warnf(inv.Stderr,"Failed to queue update: %s",err)
607-
return
604+
ifev.Role==agentapi.RoleUser {
605+
err:=s.queue.Push(reportTask{
606+
messageID:ev.Id,
607+
})
608+
iferr!=nil {
609+
cliui.Warnf(inv.Stderr,"Failed to queue update: %s",err)
610+
return
611+
}
608612
}
609613
}
610614
caseerr:=<-errCh:

‎cli/exp_mcp_test.go‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,12 @@ func TestExpMcpReporter(t *testing.T) {
790790
}
791791
}
792792

793-
makeMessageEvent:=func(idint64)*codersdk.ServerSentEvent {
793+
makeMessageEvent:=func(idint64,role agentapi.ConversationRole)*codersdk.ServerSentEvent {
794794
return&codersdk.ServerSentEvent{
795795
Type:ServerSentEventTypeMessageUpdate,
796796
Data: agentapi.EventMessageUpdate{
797-
Id:id,
797+
Id:id,
798+
Role:role,
798799
},
799800
}
800801
}
@@ -813,7 +814,7 @@ func TestExpMcpReporter(t *testing.T) {
813814
return
814815
}
815816
// Send initial message.
816-
send(*makeMessageEvent(0))
817+
send(*makeMessageEvent(0,agentapi.RoleAgent))
817818
listening<-send
818819
<-closed
819820
}))
@@ -902,13 +903,17 @@ func TestExpMcpReporter(t *testing.T) {
902903
URI:"https://dev.coder.com",
903904
},
904905
},
905-
// Terminal becomes active again according to the screen watcher, but
906-
//message length is the same. This could be the LLM being active again,
907-
//but itcould also be the user messing around. We will prefer not
908-
//updating thestatus so the "working" update here should be skipped.
906+
// Terminal becomes active again according to the screen watcher, but no
907+
//new user message. This could be the LLM being active again, but it
908+
// could also be the user messing around. We will prefer not updating the
909+
// status so the "working" update here should be skipped.
909910
{
910911
event:makeStatusEvent(agentapi.StatusRunning),
911912
},
913+
// Agent messages are ignored.
914+
{
915+
event:makeMessageEvent(1,agentapi.RoleAgent),
916+
},
912917
// LLM reports that it failed and URI is blank.
913918
{
914919
state:codersdk.WorkspaceAppStatusStateFailure,
@@ -923,10 +928,10 @@ func TestExpMcpReporter(t *testing.T) {
923928
{
924929
event:makeStatusEvent(agentapi.StatusRunning),
925930
},
926-
// ... but this timethe message length has increasedso we know there is
927-
//LLMactivity. This time the "working" update will not be skipped.
931+
// ... but this timewe have a new user messageso we know there is LLM
932+
// activity. This time the "working" update will not be skipped.
928933
{
929-
event:makeMessageEvent(1),
934+
event:makeMessageEvent(2,agentapi.RoleUser),
930935
expected:&codersdk.WorkspaceAppStatus{
931936
State:codersdk.WorkspaceAppStatusStateWorking,
932937
Message:"oops",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp