Match pending sends by a send id the server echoes
This commit is contained in:
+11
-7
@@ -88,7 +88,7 @@ func (m *Manager) activeLead(ctx context.Context, owner string) (api.AgentSessio
|
||||
return api.AgentSession{}, false, nil
|
||||
}
|
||||
|
||||
func (m *Manager) createLead(ctx context.Context, owner api.User, prompt, model, actor string, images []string) (api.AgentSession, error) {
|
||||
func (m *Manager) createLead(ctx context.Context, owner api.User, prompt, model, actor, sendID string, images []string) (api.AgentSession, error) {
|
||||
_, found, err := m.activeLead(ctx, owner.Login)
|
||||
if err != nil {
|
||||
return api.AgentSession{}, err
|
||||
@@ -114,10 +114,10 @@ func (m *Manager) createLead(ctx context.Context, owner api.User, prompt, model,
|
||||
if err != nil {
|
||||
return api.AgentSession{}, err
|
||||
}
|
||||
return m.turn(ctx, sess, api.Task{}, actor, prompt, images)
|
||||
return m.turn(ctx, sess, api.Task{}, actor, prompt, sendID, images)
|
||||
}
|
||||
|
||||
func (m *Manager) MessageLead(ctx context.Context, user api.User, text, model string, images []string) (api.AgentSession, error) {
|
||||
func (m *Manager) MessageLead(ctx context.Context, user api.User, text, model, sendID string, images []string) (api.AgentSession, error) {
|
||||
m.setStartedTodo(user.Login, false)
|
||||
|
||||
m.leadMu.Lock()
|
||||
@@ -128,11 +128,11 @@ func (m *Manager) MessageLead(ctx context.Context, user api.User, text, model st
|
||||
return api.AgentSession{}, err
|
||||
}
|
||||
if !found {
|
||||
return m.createLead(ctx, user, text, model, user.Login, images)
|
||||
return m.createLead(ctx, user, text, model, user.Login, sendID, images)
|
||||
}
|
||||
|
||||
if sess.State == api.AgentSessionStateIdle {
|
||||
s, err := m.Send(ctx, sess.Id, user.Login, text, model, images...)
|
||||
s, err := m.Send(ctx, sess.Id, user.Login, text, model, sendID, images...)
|
||||
if !errors.Is(err, ErrConflict) {
|
||||
return s, err
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func (m *Manager) MessageLead(ctx context.Context, user api.User, text, model st
|
||||
}
|
||||
sess.Model = model
|
||||
}
|
||||
err = m.store.AddLeadInput(ctx, store.LeadInput{Owner: user.Login, Kind: store.LeadMessage, Actor: user.Login, Text: text, Images: images})
|
||||
err = m.store.AddLeadInput(ctx, store.LeadInput{Owner: user.Login, Kind: store.LeadMessage, Actor: user.Login, Text: text, Images: images, SendID: sendID})
|
||||
if err != nil {
|
||||
return api.AgentSession{}, err
|
||||
}
|
||||
@@ -171,6 +171,10 @@ func (m *Manager) DeliverLead(ctx context.Context, owner string) error {
|
||||
}
|
||||
|
||||
batch, actor, text, images := nextLeadTurn(inputs)
|
||||
sendID := ""
|
||||
if batch[0].Kind == store.LeadMessage {
|
||||
sendID = batch[0].SendID
|
||||
}
|
||||
if batch[0].Kind == store.LeadSignal && m.interrupted(sess.Id) {
|
||||
return nil
|
||||
}
|
||||
@@ -182,7 +186,7 @@ func (m *Manager) DeliverLead(ctx context.Context, owner string) error {
|
||||
}
|
||||
text += "\n\n" + state
|
||||
}
|
||||
_, err = m.Send(ctx, sess.Id, actor, text, "", images...)
|
||||
_, err = m.Send(ctx, sess.Id, actor, text, "", sendID, images...)
|
||||
if errors.Is(err, ErrConflict) {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user