fix(chat): settle authoritative turns and make capabilities explicit
This commit is contained in:
@@ -45,11 +45,31 @@ func handleChatPrompt(ctx context.Context, request protocol.Message, broker chat
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat prompt exceeds 64 KiB"})
|
||||
return
|
||||
}
|
||||
if len(prompt.Attachments) > 0 {
|
||||
var err error
|
||||
if checker, ok := broker.(interface {
|
||||
CheckAttachments(context.Context, string) error
|
||||
}); ok {
|
||||
err = checker.CheckAttachments(ctx, prompt.SessionID)
|
||||
} else if _, ok := broker.(chatPromptWithFiles); !ok {
|
||||
err = errChatAttachmentsUnsupported
|
||||
}
|
||||
if err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
attachmentFiles, attachmentParts, err := prepareChatAttachments(prompt.SessionID, prompt.Attachments)
|
||||
if err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
accepted := false
|
||||
defer func() {
|
||||
if !accepted {
|
||||
releaseChatAttachments(attachmentFiles)
|
||||
}
|
||||
}()
|
||||
sessionID := prompt.SessionID
|
||||
sub := hub.attach(sessionID, clientID, sanitizeChatClientLabel(prompt.Client), broker, write)
|
||||
if sub == nil {
|
||||
@@ -85,6 +105,7 @@ func handleChatPrompt(ctx context.Context, request protocol.Message, broker chat
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + sessionID + " already has the maximum number of prompts queued"})
|
||||
return
|
||||
}
|
||||
accepted = true
|
||||
// Publish the user turn to every other client; the sender already has it.
|
||||
hub.broadcastUser(userFrame, clientID)
|
||||
if queued {
|
||||
|
||||
Reference in New Issue
Block a user