feat(session): persist last request state for UI restoration

Sessions now record the input-bar state used for the most recent QA
request (agent, model, KB scope, web search). The chat UI hydrates
those settings on session reopen so users see the same configuration
they used last time, instead of the global default.

The state is stored in the existing sessions.agent_config JSONB column
to avoid a new migration. Frontend snapshots the user's global defaults
on session enter and restores them on session leave, so opening an old
session does not pollute new-chat defaults.
This commit is contained in:
wizardchen
2026-05-18 22:24:39 +08:00
committed by lyingbug
parent 8dd9b67df9
commit 7bb38f81b6
8 changed files with 282 additions and 20 deletions
@@ -239,6 +239,33 @@ func (r *sessionRepository) Update(ctx context.Context, session *types.Session,
return res.RowsAffected, res.Error
}
// UpdateLastRequestState writes only the agent_config column (used here to
// store SessionLastRequestState) and bumps updated_at. We deliberately bypass
// the regular Update path so the call doesn't perturb title/description and
// stays cheap (single-row UPDATE by PK).
func (r *sessionRepository) UpdateLastRequestState(
ctx context.Context, tenantID uint64, userID string, sessionID string,
state *types.SessionLastRequestState,
) (int64, error) {
now := time.Now()
var stateValue interface{}
if state != nil {
v, err := state.Value()
if err != nil {
return 0, err
}
stateValue = v
}
res := applySessionUserScope(r.db.WithContext(ctx).
Model(&types.Session{}).
Where("tenant_id = ? AND id = ?", tenantID, sessionID), userID).
Updates(map[string]interface{}{
"agent_config": stateValue,
"updated_at": now,
})
return res.RowsAffected, res.Error
}
// Delete deletes a session
func (r *sessionRepository) Delete(ctx context.Context, tenantID uint64, userID string, id string) (int64, error) {
res := applySessionUserScope(