50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package agents
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"g.fc.run/ai/byre/internal/api"
|
|
"g.fc.run/ai/byre/internal/store"
|
|
)
|
|
|
|
const awayText = "I'm away right now, so I can't answer this. Pick the answer you think most likely and carry on; when I'm back I can answer again, which forks the task from here with my answer. " +
|
|
"If you strongly believe two answers are both worth following to the end, use your fork tool, if you have one, to follow the other one in a fork. " +
|
|
"If this needs something only I can give, such as a test result, a password or a permission, don't guess: note it, and carry on with other work or end your turn. " +
|
|
"This grants no authorization I must give explicitly, such as to deploy, push or commit."
|
|
|
|
func (m *Manager) SetAway(ctx context.Context, login string, away bool) (api.User, error) {
|
|
u, err := m.store.UpdateAway(ctx, login, away)
|
|
if err != nil || !away {
|
|
return u, err
|
|
}
|
|
items, err := m.store.ListInbox(ctx, store.InboxFilter{State: api.Open})
|
|
if err != nil {
|
|
return u, err
|
|
}
|
|
for _, item := range items {
|
|
task, err := m.store.GetTask(ctx, item.TaskId)
|
|
if err != nil {
|
|
return u, err
|
|
}
|
|
if task.CreatedBy != login {
|
|
continue
|
|
}
|
|
err = m.answerAway(ctx, login, item.Id)
|
|
if err != nil {
|
|
slog.Error("answer question while away", "item", item.Id, "user", login, "err", err)
|
|
}
|
|
}
|
|
return u, nil
|
|
}
|
|
|
|
func (m *Manager) answerAway(ctx context.Context, login, itemID string) error {
|
|
text := awayText
|
|
_, err := m.Respond(ctx, login, []api.InboxResponseCreate{{ItemId: itemID, Type: api.Other, Text: &text}})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
slog.Info("question answered while away", "item", itemID, "user", login)
|
|
return nil
|
|
}
|