diff --git a/components/actionhistory.html b/components/actionhistory.html
index c914b59..8a3d6f9 100644
--- a/components/actionhistory.html
+++ b/components/actionhistory.html
@@ -18,7 +18,7 @@
if (!window.actionHistoryScrollSet) {
htmx.onLoad(function(target) {
if (target.id === 'actionHistoryContainer') {
- target.scrollTop = target.scrollHeight;
+ target.scrollToBottom();
}
});
window.actionHistoryScrollSet = true;
diff --git a/components/room.html b/components/room.html
index 47497b6..1caabbd 100644
--- a/components/room.html
+++ b/components/room.html
@@ -74,7 +74,7 @@
{{end}}
- {{if and (eq .State.Username .Room.CreatorName) (.Room.IsRunning)}}
+ {{if and (eq .State.Username .Room.CreatorName) (.Room.BotFailed)}}
{{end}}
diff --git a/llmapi/main.go b/llmapi/main.go
index 8d18853..8e6db0b 100644
--- a/llmapi/main.go
+++ b/llmapi/main.go
@@ -188,6 +188,11 @@ func (b *Bot) BotMove() {
b.log.Error("bot loop", "error", err)
return
}
+ if room.BotFailed {
+ if err := repo.RoomUnSetBotFailed(context.Background(), room.ID); err != nil {
+ b.log.Error("failed to unset bot failed bool", "error", err)
+ }
+ }
// eventName := models.NotifyBacklogPrefix + room.ID
eventName := models.NotifyRoomUpdatePrefix + room.ID
eventPayload := ""
@@ -231,6 +236,9 @@ func (b *Bot) BotMove() {
b.log.Warn("failed to write to journal", "entry", lj)
}
b.log.Error("bot loop", "error", err)
+ if err := repo.RoomSetBotFailed(context.Background(), room.ID); err != nil {
+ b.log.Error("failed to set bot failed bool", "error", err)
+ }
return
}
tempMap, err := b.LLMParser.ParseBytes(llmResp)
@@ -666,16 +674,5 @@ func (b *Bot) CallLLM(prompt string) ([]byte, error) {
b.log.Debug("llm resp", "body", string(body), "url", b.cfg.LLMConfig.URL, "attempt", attempt)
return body, nil
}
- entry := fmt.Sprintf("bot '%s' exceeded attempts to call llm;", b.BotName)
- lj := models.Journal{
- Entry: entry,
- Username: b.BotName,
- RoomID: b.RoomID,
- }
- if err := repo.JournalCreate(context.Background(), &lj); err != nil {
- b.log.Warn("failed to write to journal", "entry", lj)
- }
- // notify room
- // This line should not be reached because each error path returns in the loop.
return nil, errors.New("unknown error in retry loop")
}
diff --git a/migrations/001_initial_schema.up.sql b/migrations/001_initial_schema.up.sql
index bae52bd..d5c696a 100644
--- a/migrations/001_initial_schema.up.sql
+++ b/migrations/001_initial_schema.up.sql
@@ -13,6 +13,7 @@ CREATE TABLE rooms (
mime_done BOOLEAN NOT NULL DEFAULT FALSE,
is_running BOOLEAN NOT NULL DEFAULT FALSE,
is_over BOOLEAN NOT NULL DEFAULT FALSE,
+ bot_failed BOOLEAN NOT NULL DEFAULT FALSE,
team_won TEXT NOT NULL DEFAULT '',
room_link TEXT NOT NULL DEFAULT ''
);
diff --git a/models/main.go b/models/main.go
index 8bab780..e53d395 100644
--- a/models/main.go
+++ b/models/main.go
@@ -178,6 +178,8 @@ type Room struct {
BotMap map[string]BotPlayer `db:"-"`
LogJournal []Journal `db:"-"`
Settings GameSettings `db:"-"`
+ //
+ BotFailed bool `db:"bot_failed"`
}
func (r *Room) FindColor(word string) (WordColor, bool) {
diff --git a/repos/rooms.go b/repos/rooms.go
index 87b901a..343f984 100644
--- a/repos/rooms.go
+++ b/repos/rooms.go
@@ -15,6 +15,20 @@ type RoomsRepo interface {
RoomCreate(ctx context.Context, room *models.Room) error
RoomDeleteByID(ctx context.Context, id string) error
RoomUpdate(ctx context.Context, room *models.Room) error
+ RoomSetBotFailed(ctx context.Context, roomID string) error
+ RoomUnSetBotFailed(ctx context.Context, roomID string) error
+}
+
+func (p *RepoProvider) RoomSetBotFailed(ctx context.Context, roomID string) error {
+ db := getDB(ctx, p.DB)
+ _, err := db.ExecContext(ctx, "UPDATE rooms SET bot_failed = true WHERE id = ?", roomID)
+ return err
+}
+
+func (p *RepoProvider) RoomUnSetBotFailed(ctx context.Context, roomID string) error {
+ db := getDB(ctx, p.DB)
+ _, err := db.ExecContext(ctx, "UPDATE rooms SET bot_failed = false WHERE id = ?", roomID)
+ return err
}
func (p *RepoProvider) RoomList(ctx context.Context) ([]*models.Room, error) {