`message_agent` no longer takes an `interrupt` flag, and always steers. If the child is busy, it gets the message before its next model call and keeps working. To correct or redirect a busy child, the parent just calls `message_agent`, and `interrupt_agent` only stops it, which is the same split the API has after #31174. The tool result also drops `interrupted`, as it was just whether the child was running before the send. That was the last caller of the interrupt busy behaviour, so chatd and chatstate drop it too. `SendMessage` never interrupts now. On a busy chat it only ever adds the message to a lane, so the sends that moved a running chat to interrupting, or a `requires_action` chat back to running, are gone, along with the send's inline interruption finish for chats with no worker. Most of the diff is deleted tests. A steer send to a paused chat, or to an errored chat whose next message is being edited, no longer fails with a 429 at the queue limit when it's delivered straight away, which is whenever the message being edited is a queue message. Part of CODAGT-1140
56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package chatd
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"github.com/sqlc-dev/pqtype"
|
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/coderd/x/chatd/chatprompt"
|
|
"github.com/coder/coder/v2/coderd/x/chatd/chatstate"
|
|
)
|
|
|
|
// newChatMachine constructs a chat-scoped state machine handle bound to
|
|
// the server's database and pubsub.
|
|
func (p *Server) newChatMachine(chatID uuid.UUID) *chatstate.ChatMachine {
|
|
return chatstate.NewChatMachine(p.db, p.pubsub, chatID)
|
|
}
|
|
|
|
// systemMessage builds a chatstate.Message representing a system
|
|
// prompt entry for the initial-history slice of CreateChat.
|
|
func systemMessage(rawContent pqtype.NullRawMessage, modelConfigID uuid.UUID) chatstate.Message {
|
|
return chatstate.Message{
|
|
Role: database.ChatMessageRoleSystem,
|
|
Content: rawContent,
|
|
Visibility: database.ChatMessageVisibilityModel,
|
|
ModelConfigID: uuid.NullUUID{UUID: modelConfigID, Valid: modelConfigID != uuid.Nil},
|
|
ContentVersion: chatprompt.CurrentContentVersion,
|
|
}
|
|
}
|
|
|
|
func userMessage(rawContent pqtype.NullRawMessage, modelConfigID, createdBy uuid.UUID, reasoningEffort *string) chatstate.Message {
|
|
var effort database.NullChatReasoningEffort
|
|
if reasoningEffort != nil && *reasoningEffort != "" {
|
|
effort = database.NullChatReasoningEffort{ChatReasoningEffort: database.ChatReasoningEffort(*reasoningEffort), Valid: true}
|
|
}
|
|
return chatstate.Message{
|
|
Role: database.ChatMessageRoleUser,
|
|
Content: rawContent,
|
|
Visibility: database.ChatMessageVisibilityBoth,
|
|
ModelConfigID: uuid.NullUUID{UUID: modelConfigID, Valid: modelConfigID != uuid.Nil},
|
|
ReasoningEffort: effort,
|
|
CreatedBy: uuid.NullUUID{UUID: createdBy, Valid: createdBy != uuid.Nil},
|
|
ContentVersion: chatprompt.CurrentContentVersion,
|
|
}
|
|
}
|
|
|
|
// busyBehaviorToChatState converts the public busy-behavior enum used
|
|
// by the server API to the chatstate variant.
|
|
func busyBehaviorToChatState(b SendMessageBusyBehavior) chatstate.BusyBehavior {
|
|
switch b {
|
|
case SendMessageBusyBehaviorSteer:
|
|
return chatstate.BusyBehaviorSteer
|
|
default:
|
|
return chatstate.BusyBehaviorQueue
|
|
}
|
|
}
|