Show prompts delivered into the running reply distinctly
This commit is contained in:
@@ -63,6 +63,10 @@ const (
|
||||
chatAdmitRefused
|
||||
)
|
||||
|
||||
type chatRecentOp struct {
|
||||
steered bool
|
||||
}
|
||||
|
||||
type chatStoredFile struct {
|
||||
URI string `json:"uri"`
|
||||
Name string `json:"name"`
|
||||
@@ -405,21 +409,21 @@ func (r *chatRoom) holdsOp(operationID string) bool {
|
||||
// duplicateOp reports whether operationID is a prompt this session already
|
||||
// accepted (queued reports it is still waiting in the queue), so a client retry
|
||||
// is acknowledged again instead of delivered twice.
|
||||
func (h *chatHub) duplicateOp(sessionID, operationID string) (duplicate, queued bool) {
|
||||
func (h *chatHub) duplicateOp(sessionID, operationID string) (duplicate, queued, steered bool) {
|
||||
if operationID == "" {
|
||||
return false, false
|
||||
return false, false, false
|
||||
}
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
if room := h.rooms[sessionID]; room != nil {
|
||||
for _, p := range room.queue {
|
||||
if p.operationID == operationID {
|
||||
return true, p.acked
|
||||
return true, p.acked, false
|
||||
}
|
||||
}
|
||||
}
|
||||
_, seen := h.recentOps[sessionID+"\x00"+operationID]
|
||||
return seen, false
|
||||
recent, seen := h.recentOps[sessionID+"\x00"+operationID]
|
||||
return seen, false, recent.steered
|
||||
}
|
||||
|
||||
func (h *chatHub) rememberOp(sessionID, operationID string) {
|
||||
@@ -434,12 +438,12 @@ func (h *chatHub) rememberOpLocked(sessionID, operationID string) {
|
||||
}
|
||||
key := sessionID + "\x00" + operationID
|
||||
if h.recentOps == nil {
|
||||
h.recentOps = map[string]struct{}{}
|
||||
h.recentOps = map[string]chatRecentOp{}
|
||||
}
|
||||
if _, ok := h.recentOps[key]; ok {
|
||||
return
|
||||
}
|
||||
h.recentOps[key] = struct{}{}
|
||||
h.recentOps[key] = chatRecentOp{}
|
||||
h.recentOpOrder = append(h.recentOpOrder, key)
|
||||
for len(h.recentOpOrder) > chatRecentOpsLimit {
|
||||
delete(h.recentOps, h.recentOpOrder[0])
|
||||
@@ -447,6 +451,16 @@ func (h *chatHub) rememberOpLocked(sessionID, operationID string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *chatHub) markOpSteered(sessionID, operationID string) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
key := sessionID + "\x00" + operationID
|
||||
if recent, ok := h.recentOps[key]; ok {
|
||||
recent.steered = true
|
||||
h.recentOps[key] = recent
|
||||
}
|
||||
}
|
||||
|
||||
// forgetOp lets a prompt that never reached the harness be retried.
|
||||
func (h *chatHub) forgetOp(sessionID, operationID string) {
|
||||
h.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user